十分钟教你部署一个属于自己的chatgpt网站-(源码)

时间:2024-09-30 20:17:27
  • from flask import Flask, request, jsonify
  • import openai
  • app = Flask(__name__)
  • # 设置GPT-3 API密钥
  • openai.api_key = "YOUR_API_KEY"
  • # 定义API接口
  • @('/chat', methods=['POST'])
  • def chat():
  • data =
  • message = data['message']
  • response = generate_response(message)
  • return jsonify({'message': response})
  • # 生成回复信息
  • def generate_response(message):
  • prompt = f"Conversation:\n\nUser: {message}\nAI:"
  • response = (
  • engine="text-davinci-002",
  • prompt=prompt,
  • max_tokens=1024,
  • n=1,
  • stop=None,
  • temperature=0.5,
  • )
  • message = [0].()
  • return message
  • if __name__ == '__main__':
  • app.run(debug=True, host='0.0.0.0', port=5000)