Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -419,11 +419,7 @@ After writing the document, please provide a list of sources used in your respon
|
|
419 |
if not full_response:
|
420 |
yield "I apologize, but I couldn't generate a response at this time. Please try again later."
|
421 |
|
422 |
-
|
423 |
-
web_search_database = None
|
424 |
-
|
425 |
-
def update_web_search_vectors(search_results):
|
426 |
-
global web_search_database
|
427 |
embed = get_embeddings()
|
428 |
|
429 |
documents = []
|
@@ -432,18 +428,13 @@ def update_web_search_vectors(search_results):
|
|
432 |
content = f"{result['title']}\n{result['body']}\nSource: {result['href']}"
|
433 |
documents.append(Document(page_content=content, metadata={"source": result['href']}))
|
434 |
|
435 |
-
|
436 |
-
web_search_database = FAISS.from_documents(documents, embed)
|
437 |
-
else:
|
438 |
-
web_search_database.add_documents(documents)
|
439 |
|
440 |
def get_response_with_search(query, model, num_calls=3, temperature=0.2):
|
441 |
-
global web_search_database
|
442 |
-
|
443 |
search_results = duckduckgo_search(query)
|
444 |
-
|
445 |
|
446 |
-
if web_search_database
|
447 |
yield "No web search results available. Please try again.", ""
|
448 |
return
|
449 |
|
@@ -478,7 +469,6 @@ After writing the document, please provide a list of sources used in your respon
|
|
478 |
main_content += chunk
|
479 |
yield main_content, "" # Yield partial main content without sources
|
480 |
|
481 |
-
|
482 |
def get_response_from_pdf(query, model, selected_docs, num_calls=3, temperature=0.2):
|
483 |
logging.info(f"Entering get_response_from_pdf with query: {query}, model: {model}, selected_docs: {selected_docs}")
|
484 |
|
|
|
419 |
if not full_response:
|
420 |
yield "I apologize, but I couldn't generate a response at this time. Please try again later."
|
421 |
|
422 |
+
def create_web_search_vectors(search_results):
|
|
|
|
|
|
|
|
|
423 |
embed = get_embeddings()
|
424 |
|
425 |
documents = []
|
|
|
428 |
content = f"{result['title']}\n{result['body']}\nSource: {result['href']}"
|
429 |
documents.append(Document(page_content=content, metadata={"source": result['href']}))
|
430 |
|
431 |
+
return FAISS.from_documents(documents, embed)
|
|
|
|
|
|
|
432 |
|
433 |
def get_response_with_search(query, model, num_calls=3, temperature=0.2):
|
|
|
|
|
434 |
search_results = duckduckgo_search(query)
|
435 |
+
web_search_database = create_web_search_vectors(search_results)
|
436 |
|
437 |
+
if not web_search_database:
|
438 |
yield "No web search results available. Please try again.", ""
|
439 |
return
|
440 |
|
|
|
469 |
main_content += chunk
|
470 |
yield main_content, "" # Yield partial main content without sources
|
471 |
|
|
|
472 |
def get_response_from_pdf(query, model, selected_docs, num_calls=3, temperature=0.2):
|
473 |
logging.info(f"Entering get_response_from_pdf with query: {query}, model: {model}, selected_docs: {selected_docs}")
|
474 |
|