joshuadunlop commited on
Commit
41866c2
·
1 Parent(s): 039bca9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -118,15 +118,15 @@ def generate_answer(question,openAI_key):
118
  prompt += c + '\n\n'
119
 
120
  prompt += "Instructions: Compose a comprehensive reply to the query using the search results given. "\
121
- "Cite each reference using [ Page Number] notation (every result has this number at the beginning). "\
122
  "Citation should be done at the end of each sentence. If the search results mention multiple subjects "\
123
  "with the same name, create separate answers for each. Only include information found in the results and "\
124
- "don't add any additional information. Make sure the answer is correct and don't output false content. "\
125
  "If the text does not relate to the query, simply state 'Found Nothing'. Ignore outlier "\
126
- "search results which has nothing to do with the question. Only answer what is asked. The "\
127
  "answer should be short and concise. \n\nQuery: {question}\nAnswer: "
128
 
129
- prompt += f"Query: {question}\nAnswer:"
130
  answer = generate_text(openAI_key, prompt,"text-davinci-003")
131
  return answer
132
 
@@ -264,9 +264,15 @@ if generate_all:
264
  for worker in workers:
265
  worker.join()
266
 
 
 
267
  while not results.empty():
268
  i, answer = results.get()
269
  if isinstance(answer, str) and 'Error' in answer:
270
  st.error(f"Error on row {i}: {answer}")
271
  else:
272
- st.session_state[f'session_answer{i}'] = answer
 
 
 
 
 
118
  prompt += c + '\n\n'
119
 
120
  prompt += "Instructions: Compose a comprehensive reply to the query using the search results given. "\
121
+ "Cite each reference using [Page Number] notation (every result has this number at the beginning). "\
122
  "Citation should be done at the end of each sentence. If the search results mention multiple subjects "\
123
  "with the same name, create separate answers for each. Only include information found in the results and "\
124
+ "don't add any additional information. Make sure the answer is correct, and don't output false content. "\
125
  "If the text does not relate to the query, simply state 'Found Nothing'. Ignore outlier "\
126
+ "search results that have nothing to do with the question. Only answer what is asked. The "\
127
  "answer should be short and concise. \n\nQuery: {question}\nAnswer: "
128
 
129
+ prompt += f"Query: {question}\nAnswer: "
130
  answer = generate_text(openAI_key, prompt,"text-davinci-003")
131
  return answer
132
 
 
264
  for worker in workers:
265
  worker.join()
266
 
267
+ # Collect all results first
268
+ answers = {}
269
  while not results.empty():
270
  i, answer = results.get()
271
  if isinstance(answer, str) and 'Error' in answer:
272
  st.error(f"Error on row {i}: {answer}")
273
  else:
274
+ answers[i] = answer
275
+
276
+ # Update session state in the main thread
277
+ for i, answer in answers.items():
278
+ st.session_state[f'session_answer{i}'] = answer