-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
54 lines (41 loc) · 1.48 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from flask import Flask, jsonify, render_template, request
import openai
from apikey import OPEN_AI_KEY
from dataset import dataset
# from Advanatge import services, mission, company_name
# with open(r"C:\Users\hrush\OneDrive\Desktop\chatmodel\fine_tuned_model_id.txt", "r") as f:
# fine_tune_model_id = f.read().strip()
default_response = "This information is not available at the moment.For more queries can contact our executive"
# intitalizing the flask app
app = Flask(__name__)
# api key from openai
openai.api_key = OPEN_AI_KEY
# function for model prompt and query
def ask_gpt3(prompt):
response = openai.ChatCompletion.create(
messages=[
{"role": "system", "content": "You're an AI assistant who answers user questions from the dataset."},
{"role": "user", "content": prompt}
],
model='gpt-3.5-turbo',
temperature=0.7,
max_tokens=100,
n=1,
stop=None,
frequency_penalty=0,
presence_penalty=0
)
answer = response['choices'][0]['message']['content']
return answer
# this renders a html template for the user
@app.route("/")
def index():
return render_template("index.html")
# post method to request the gpt model to answer the question asked by user
@app.route("/ask",methods=['POST'])
def ask():
user_input = request.form['user_input']
response = ask_gpt3(user_input)
return jsonify({"response": response})
if __name__ == "__main__":
app.run(debug=True)