Shreyas094
commited on
Commit
•
9f83d50
1
Parent(s):
1dc5b0f
Update app.py
Browse files
app.py
CHANGED
@@ -215,6 +215,10 @@ def google_search(term, num_results=5, lang="en", timeout=5, safe="active", ssl_
|
|
215 |
print(" Text: None")
|
216 |
print("End of search results")
|
217 |
|
|
|
|
|
|
|
|
|
218 |
return all_results
|
219 |
|
220 |
def ask_question(question, temperature, top_p, repetition_penalty, web_search):
|
@@ -233,14 +237,11 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search):
|
|
233 |
context_str = "\n".join([result["text"] for result in search_results if result["text"]])
|
234 |
prompt_template = """
|
235 |
Answer the question based on the following web search results:
|
236 |
-
|
237 |
Web Search Results:
|
238 |
{context}
|
239 |
-
|
240 |
Current Question: {question}
|
241 |
-
|
242 |
If the web search results don't contain relevant information, state that the information is not available in the search results.
|
243 |
-
Provide a concise and direct answer to the question:
|
244 |
"""
|
245 |
prompt_val = ChatPromptTemplate.from_template(prompt_template)
|
246 |
formatted_prompt = prompt_val.format(context=context_str, question=question)
|
@@ -262,6 +263,10 @@ def ask_question(question, temperature, top_p, repetition_penalty, web_search):
|
|
262 |
answer = generate_chunked_response(model, formatted_prompt)
|
263 |
answer = re.split(r'Question:|Current Question:', answer)[-1].strip()
|
264 |
|
|
|
|
|
|
|
|
|
265 |
if not web_search:
|
266 |
memory_database[question] = answer
|
267 |
|
|
|
215 |
print(" Text: None")
|
216 |
print("End of search results")
|
217 |
|
218 |
+
if not all_results:
|
219 |
+
print("No search results found. Returning a default message.")
|
220 |
+
return [{"link": None, "text": "No information found in the web search results."}]
|
221 |
+
|
222 |
return all_results
|
223 |
|
224 |
def ask_question(question, temperature, top_p, repetition_penalty, web_search):
|
|
|
237 |
context_str = "\n".join([result["text"] for result in search_results if result["text"]])
|
238 |
prompt_template = """
|
239 |
Answer the question based on the following web search results:
|
|
|
240 |
Web Search Results:
|
241 |
{context}
|
|
|
242 |
Current Question: {question}
|
|
|
243 |
If the web search results don't contain relevant information, state that the information is not available in the search results.
|
244 |
+
Provide a concise and direct answer to the question without mentioning the web search or these instructions:
|
245 |
"""
|
246 |
prompt_val = ChatPromptTemplate.from_template(prompt_template)
|
247 |
formatted_prompt = prompt_val.format(context=context_str, question=question)
|
|
|
263 |
answer = generate_chunked_response(model, formatted_prompt)
|
264 |
answer = re.split(r'Question:|Current Question:', answer)[-1].strip()
|
265 |
|
266 |
+
# Remove any remaining prompt instructions from the answer
|
267 |
+
answer_lines = answer.split('\n')
|
268 |
+
answer = '\n'.join(line for line in answer_lines if not line.startswith('If') and not line.startswith('Provide'))
|
269 |
+
|
270 |
if not web_search:
|
271 |
memory_database[question] = answer
|
272 |
|