-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
executable file
·35 lines (26 loc) · 891 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from flask import Flask, render_template, request, jsonify
import openai
app = Flask(__name__)
# Replace 'your-api-key' with your actual OpenAI API key
openai.api_key = '<Yout_API_KEY>'
@app.route("/")
def index():
return render_template('chat.html')
@app.route("/get", methods=["POST"])
def chat():
msg = request.form["msg"]
response = get_Chat_response(msg)
return jsonify({"response": response})
def get_Chat_response(text):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": text}],
max_tokens=150,
stop=None,
temperature=0.7,
)
# Access the content from the first message in the response's choices
return response['choices'][0]['message']['content'].strip()
#return response.choices[0].text.strip()
if __name__ == '__main__':
app.run(debug=True)