bhaskartripathi commited on
Commit
9297d37
1 Parent(s): 074f838

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -14
app.py CHANGED
@@ -98,22 +98,18 @@ def load_recommender(path, start_page=1):
98
  recommender.fit(chunks)
99
  return 'Corpus Loaded.'
100
 
101
-
102
- def generate_text(openAI_key,prompt, engine="text-davinci-003"):
103
  openai.api_key = openAI_key
104
- completions = openai.Completion.create(
105
- engine=engine,
106
- prompt=prompt,
107
- max_tokens=512,
108
- n=1,
109
- stop=None,
110
- temperature=0.7,
111
  )
112
- message = completions.choices[0].text
113
- return message
114
-
115
 
116
- def generate_answer(question,openAI_key):
117
  topn_chunks = recommender(question)
118
  prompt = ""
119
  prompt += 'search results:\n\n'
@@ -130,10 +126,11 @@ def generate_answer(question,openAI_key):
130
  "answer should be short and concise. \n\nQuery: {question}\nAnswer: "
131
 
132
  prompt += f"Query: {question}\nAnswer:"
133
- answer = generate_text(openAI_key, prompt,"text-davinci-003")
134
  return answer
135
 
136
 
 
137
  def question_answer(url, file, question,openAI_key):
138
  if openAI_key.strip()=='':
139
  return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'
 
98
  recommender.fit(chunks)
99
  return 'Corpus Loaded.'
100
 
101
+ def generate_text(openAI_key, prompt, model="gpt-3.5-turbo"):
 
102
  openai.api_key = openAI_key
103
+ message = openai.ChatCompletion.create(
104
+ model=model,
105
+ messages=[
106
+ {"role": "system", "content": "You are a helpful assistant."},
107
+ {"role": "user", "content": prompt}
108
+ ]
 
109
  )
110
+ return message.choices[0].message['content']
 
 
111
 
112
+ def generate_answer(question, openAI_key):
113
  topn_chunks = recommender(question)
114
  prompt = ""
115
  prompt += 'search results:\n\n'
 
126
  "answer should be short and concise. \n\nQuery: {question}\nAnswer: "
127
 
128
  prompt += f"Query: {question}\nAnswer:"
129
+ answer = generate_text(openAI_key, prompt, "gpt-3.5-turbo")
130
  return answer
131
 
132
 
133
+
134
  def question_answer(url, file, question,openAI_key):
135
  if openAI_key.strip()=='':
136
  return '[ERROR]: Please enter you Open AI Key. Get your key here : https://platform.openai.com/account/api-keys'