joshuadunlop commited on
Commit
d9e7c36
·
1 Parent(s): 6999ac8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -120,9 +120,21 @@ def generate_answer(question,openAI_key):
120
  if not recommender.fitted:
121
  st.error('The recommender is not fitted yet.')
122
  return
123
-
124
- # Replace the hard-coded string with the variable instructions
125
- prompt = instructions + f"\n\nQuery: {question}\nAnswer: "
 
 
 
 
 
 
 
 
 
 
 
 
126
  answer = generate_text(openAI_key, prompt,"text-davinci-003")
127
 
128
  answer = answer.strip()
@@ -148,15 +160,6 @@ row_count = st.session_state.get("row_count", 1)
148
  num_concurrent_calls = st.sidebar.number_input("Concurrent Calls:", min_value=1, max_value=2000, value=10, step=1)
149
  generate_all = st.sidebar.button("Generate All")
150
 
151
- instructions = st.sidebar.text_area('Instructions', value="""Instructions: Compose a comprehensive reply to the query using the search results given.
152
- Cite each reference using [Page Number] notation (every result has this number at the beginning).
153
- Citation should be done at the end of each sentence. If the search results mention multiple subjects
154
- with the same name, create separate answers for each. Only include information found in the results and
155
- don't add any additional information. Make sure the answer is correct, and don't output false content.
156
- If the text does not relate to the query, simply state 'Found Nothing'. Ignore outlier
157
- search results that have nothing to do with the question. Only answer what is asked. The
158
- answer should be short and concise.""")
159
-
160
  if add_row:
161
  row_count += 1
162
  st.session_state.row_count = row_count
@@ -275,4 +278,4 @@ if generate_all:
275
  for i, answer in answers.items():
276
  st.session_state[f'session_answer{i}'] = answer
277
 
278
- logging.info("Session state updated with answers.")
 
120
  if not recommender.fitted:
121
  st.error('The recommender is not fitted yet.')
122
  return
123
+ prompt = ""
124
+ prompt += 'search results:\n\n'
125
+ for c in topn_chunks:
126
+ prompt += c + '\n\n'
127
+
128
+ prompt += "Instructions: Compose a comprehensive reply to the query using the search results given. "\
129
+ "Cite each reference using [Page Number] notation (every result has this number at the beginning). "\
130
+ "Citation should be done at the end of each sentence. If the search results mention multiple subjects "\
131
+ "with the same name, create separate answers for each. Only include information found in the results and "\
132
+ "don't add any additional information. Make sure the answer is correct, and don't output false content. "\
133
+ "If the text does not relate to the query, simply state 'Found Nothing'. Ignore outlier "\
134
+ "search results that have nothing to do with the question. Only answer what is asked. The "\
135
+ "answer should be short and concise. \n\nQuery: {question}\nAnswer: "
136
+
137
+ prompt += f"Query: {question}\nAnswer: "
138
  answer = generate_text(openAI_key, prompt,"text-davinci-003")
139
 
140
  answer = answer.strip()
 
160
  num_concurrent_calls = st.sidebar.number_input("Concurrent Calls:", min_value=1, max_value=2000, value=10, step=1)
161
  generate_all = st.sidebar.button("Generate All")
162
 
 
 
 
 
 
 
 
 
 
163
  if add_row:
164
  row_count += 1
165
  st.session_state.row_count = row_count
 
278
  for i, answer in answers.items():
279
  st.session_state[f'session_answer{i}'] = answer
280
 
281
+ logging.info("Session state updated with answers.")