Spaces:
Runtime error
Runtime error
bhaskartripathi
commited on
Commit
•
57c0c93
1
Parent(s):
ea4d797
Update app.py
Browse files
app.py
CHANGED
@@ -132,27 +132,22 @@ def generate_text(openAI_key, prompt, model="gpt-3.5-turbo"):
|
|
132 |
).choices[0].message['content']
|
133 |
return message
|
134 |
|
135 |
-
|
136 |
-
def generate_answer(question, openAI_key,model):
|
137 |
topn_chunks = recommender(question)
|
138 |
-
prompt =
|
139 |
-
prompt += 'search results:\n\n'
|
140 |
for c in topn_chunks:
|
141 |
prompt += c + '\n\n'
|
142 |
|
143 |
prompt += "Instructions: Compose a comprehensive reply to the query using the search results given. "\
|
144 |
-
"Cite each reference using [ Page Number] notation
|
145 |
-
"
|
146 |
-
"with the same name, create separate answers for each. Only include information found in the results and "\
|
147 |
-
"don't add any additional information. Make sure the answer is correct and don't output false content. "\
|
148 |
-
"If the text does not relate to the query, simply state 'Found Nothing.Please select text-davinci-003 model.'. Ignore outlier "\
|
149 |
-
"search results which has nothing to do with the question. Only answer what is asked. The "\
|
150 |
-
"answer should be short and concise. \n\nQuery: {question}\nAnswer: "
|
151 |
|
152 |
-
prompt += f"
|
153 |
answer = generate_text(openAI_key, prompt, model)
|
154 |
return answer
|
155 |
|
|
|
156 |
def question_answer(chat_history, url, file, question, openAI_key, model):
|
157 |
try:
|
158 |
if openAI_key.strip()=='':
|
@@ -175,7 +170,7 @@ def question_answer(chat_history, url, file, question, openAI_key, model):
|
|
175 |
load_recommender(file_name)
|
176 |
if question.strip() == '':
|
177 |
return '[ERROR]: Question field is empty'
|
178 |
-
if model == "text-davinci-003":
|
179 |
answer = generate_answer_text_davinci_003(question, openAI_key)
|
180 |
else:
|
181 |
answer = generate_answer(question, openAI_key, model)
|
|
|
132 |
).choices[0].message['content']
|
133 |
return message
|
134 |
|
135 |
+
|
136 |
+
def generate_answer(question, openAI_key, model):
|
137 |
topn_chunks = recommender(question)
|
138 |
+
prompt = 'search results:\n\n'
|
|
|
139 |
for c in topn_chunks:
|
140 |
prompt += c + '\n\n'
|
141 |
|
142 |
prompt += "Instructions: Compose a comprehensive reply to the query using the search results given. "\
|
143 |
+
"Cite each reference using [ Page Number] notation. "\
|
144 |
+
"Only answer what is asked. The answer should be short and concise. \n\nQuery: "
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
+
prompt += f"{question}\nAnswer:"
|
147 |
answer = generate_text(openAI_key, prompt, model)
|
148 |
return answer
|
149 |
|
150 |
+
|
151 |
def question_answer(chat_history, url, file, question, openAI_key, model):
|
152 |
try:
|
153 |
if openAI_key.strip()=='':
|
|
|
170 |
load_recommender(file_name)
|
171 |
if question.strip() == '':
|
172 |
return '[ERROR]: Question field is empty'
|
173 |
+
if model == "text-davinci-003" or model == "gpt-4" or model == "gpt-4-32k":
|
174 |
answer = generate_answer_text_davinci_003(question, openAI_key)
|
175 |
else:
|
176 |
answer = generate_answer(question, openAI_key, model)
|