Shreyas094 commited on
Commit
86ff084
·
verified ·
1 Parent(s): 351bac3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -495,30 +495,40 @@ def create_web_search_vectors(search_results):
495
 
496
  def get_response_with_search(query, model, num_calls=3, temperature=0.2):
497
  search_results = duckduckgo_search(query)
498
- ranked_results = rank_results(query, search_results)
499
- web_search_database = create_web_search_vectors(ranked_results)
500
 
501
- if not web_search_database:
502
  yield "No web search results available. Please try again.", ""
503
  return
504
 
505
- retriever = web_search_database.as_retriever(search_kwargs={"k": 3})
506
- relevant_docs = retriever.get_relevant_documents(query)
507
-
508
  accumulated_response = ""
509
 
510
- for i, doc in enumerate(relevant_docs, 1):
511
- context = doc.page_content
512
- source = doc.metadata.get('source', 'Unknown source')
513
- date = doc.metadata.get('date', 'Unknown date')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
514
 
515
  prompt = f"""Using the following context from a web search result:
516
  {context}
517
- This information is from {date}.
518
  You are an expert AI assistant. Write a detailed and complete research article that fulfills the following user request: '{query}'
519
  Base your summary strictly on the information from this source. Only include information that is directly supported by the given content.
520
  If any part of the information cannot be verified from this source, clearly state that it could not be confirmed."""
521
-
522
  if model == "@cf/meta/llama-3.1-8b-instruct":
523
  # Use Cloudflare API
524
  source_response = ""
 
495
 
496
  def get_response_with_search(query, model, num_calls=3, temperature=0.2):
497
  search_results = duckduckgo_search(query)
 
 
498
 
499
+ if not search_results:
500
  yield "No web search results available. Please try again.", ""
501
  return
502
 
 
 
 
503
  accumulated_response = ""
504
 
505
+ # Split the search results into separate documents
506
+ documents = search_results.split("------------------------------------------------------------")
507
+
508
+ for i, doc in enumerate(documents, 1):
509
+ if not doc.strip(): # Skip empty documents
510
+ continue
511
+
512
+ # Extract title, URL, and content from the document
513
+ title_start = doc.find("Website Title:") + len("Website Title:")
514
+ title_end = doc.find("===========", title_start)
515
+ title = doc[title_start:title_end].strip()
516
+
517
+ url_start = doc.find("Website URL:") + len("Website URL:")
518
+ url_end = doc.find("===========", url_start)
519
+ source = doc[url_start:url_end].strip()
520
+
521
+ content_start = doc.find("Website Content") + len("Website Content ===========")
522
+ content_end = doc.find("Website Content End")
523
+ context = doc[content_start:content_end].strip()
524
 
525
  prompt = f"""Using the following context from a web search result:
526
  {context}
527
+ This information is from the website titled: {title}
528
  You are an expert AI assistant. Write a detailed and complete research article that fulfills the following user request: '{query}'
529
  Base your summary strictly on the information from this source. Only include information that is directly supported by the given content.
530
  If any part of the information cannot be verified from this source, clearly state that it could not be confirmed."""
531
+
532
  if model == "@cf/meta/llama-3.1-8b-instruct":
533
  # Use Cloudflare API
534
  source_response = ""