Spaces:
Paused
Paused
Shreyas094
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -419,12 +419,31 @@ 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 |
def get_response_with_search(query, model, num_calls=3, temperature=0.2):
|
423 |
search_results = duckduckgo_search(query)
|
424 |
-
|
425 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
426 |
|
427 |
-
prompt = f"""Using the following context:
|
428 |
{context}
|
429 |
You are an expert AI assistant, write a detailed and complete research document that fulfills the following user request: '{query}'
|
430 |
Base your entire response strictly on the information retrieved from trusted sources. Importantly, only include information that is directly supported by the retrieved content.
|
|
|
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 = []
|
426 |
+
for result in search_results:
|
427 |
+
if 'body' in result:
|
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 |
+
|
441 |
+
retriever = web_search_database.as_retriever(search_kwargs={"k": 5})
|
442 |
+
relevant_docs = retriever.get_relevant_documents(query)
|
443 |
+
|
444 |
+
context = "\n".join([doc.page_content for doc in relevant_docs])
|
445 |
|
446 |
+
prompt = f"""Using the following context from web search results:
|
447 |
{context}
|
448 |
You are an expert AI assistant, write a detailed and complete research document that fulfills the following user request: '{query}'
|
449 |
Base your entire response strictly on the information retrieved from trusted sources. Importantly, only include information that is directly supported by the retrieved content.
|