Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -478,9 +478,9 @@ def get_response_with_search(query, model, num_calls=3, temperature=0.2):
|
|
478 |
context = retrieve_web_search_results(database, query)
|
479 |
|
480 |
prompt = f"""Using the following context from web search results:
|
481 |
-
{context}
|
482 |
-
Write a detailed and complete research document that fulfills the following user request: '{query}'
|
483 |
-
After writing the document, please provide a list of sources used in your response."""
|
484 |
|
485 |
try:
|
486 |
if model == "@cf/meta/llama-3.1-8b-instruct":
|
@@ -499,10 +499,13 @@ After writing the document, please provide a list of sources used in your respon
|
|
499 |
temperature=temperature,
|
500 |
stream=True,
|
501 |
):
|
502 |
-
if message.choices and message.choices[0].delta and message.choices[0].delta.content:
|
503 |
chunk = message.choices[0].delta.content
|
504 |
main_content += chunk
|
505 |
yield main_content, "" # Yield partial main content without sources
|
|
|
|
|
|
|
506 |
finally:
|
507 |
# Clean up the temporary database
|
508 |
cleanup_web_search_database(temp_dir)
|
|
|
478 |
context = retrieve_web_search_results(database, query)
|
479 |
|
480 |
prompt = f"""Using the following context from web search results:
|
481 |
+
{context}
|
482 |
+
Write a detailed and complete research document that fulfills the following user request: '{query}'
|
483 |
+
After writing the document, please provide a list of sources used in your response."""
|
484 |
|
485 |
try:
|
486 |
if model == "@cf/meta/llama-3.1-8b-instruct":
|
|
|
499 |
temperature=temperature,
|
500 |
stream=True,
|
501 |
):
|
502 |
+
if message.choices and len(message.choices) > 0 and message.choices[0].delta and message.choices[0].delta.content:
|
503 |
chunk = message.choices[0].delta.content
|
504 |
main_content += chunk
|
505 |
yield main_content, "" # Yield partial main content without sources
|
506 |
+
except Exception as e:
|
507 |
+
logging.error(f"Error in get_response_with_search: {str(e)}", exc_info=True)
|
508 |
+
yield f"An error occurred while processing the search results: {str(e)}", ""
|
509 |
finally:
|
510 |
# Clean up the temporary database
|
511 |
cleanup_web_search_database(temp_dir)
|