Shreyas094 commited on
Commit
e998c03
·
verified ·
1 Parent(s): 6d83b64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -497,7 +497,7 @@ If any part of the information cannot be verified from this source, clearly stat
497
  source_response = ""
498
  for message in client.chat_completion(
499
  messages=[{"role": "user", "content": prompt}],
500
- max_tokens=2000,
501
  temperature=temperature,
502
  stream=True,
503
  ):
@@ -510,6 +510,28 @@ If any part of the information cannot be verified from this source, clearly stat
510
  # Generate an overall summary after processing all sources
511
  overall_prompt = f"""Based on the summaries you've generated for each source: '{accumulated_response}', provide a concise overall summary that addresses the user's query: '{query}'
512
  Highlight any conflicting information or gaps in the available data."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
513
 
514
  def get_response_from_pdf(query, model, selected_docs, num_calls=3, temperature=0.2):
515
  logging.info(f"Entering get_response_from_pdf with query: {query}, model: {model}, selected_docs: {selected_docs}")
 
497
  source_response = ""
498
  for message in client.chat_completion(
499
  messages=[{"role": "user", "content": prompt}],
500
+ max_tokens=10000,
501
  temperature=temperature,
502
  stream=True,
503
  ):
 
510
  # Generate an overall summary after processing all sources
511
  overall_prompt = f"""Based on the summaries you've generated for each source: '{accumulated_response}', provide a concise overall summary that addresses the user's query: '{query}'
512
  Highlight any conflicting information or gaps in the available data."""
513
+
514
+ if model == "@cf/meta/llama-3.1-8b-instruct":
515
+ # Use Cloudflare API for overall summary
516
+ overall_response = ""
517
+ for response in get_response_from_cloudflare(prompt="", context="", query=overall_prompt, num_calls=1, temperature=temperature, search_type="web"):
518
+ overall_response += response
519
+ accumulated_response += f"Overall Summary:\n\n{overall_response}\n\n"
520
+ yield accumulated_response, ""
521
+ else:
522
+ # Use Hugging Face API for overall summary
523
+ overall_summary = ""
524
+ for message in client.chat_completion(
525
+ messages=[{"role": "user", "content": overall_prompt}],
526
+ max_tokens=10000,
527
+ temperature=temperature,
528
+ stream=True,
529
+ ):
530
+ if message.choices and message.choices[0].delta and message.choices[0].delta.content:
531
+ chunk = message.choices[0].delta.content
532
+ overall_summary += chunk
533
+ accumulated_response += f"Overall Summary:\n\n{overall_summary}\n\n"
534
+ yield accumulated_response, ""
535
 
536
  def get_response_from_pdf(query, model, selected_docs, num_calls=3, temperature=0.2):
537
  logging.info(f"Entering get_response_from_pdf with query: {query}, model: {model}, selected_docs: {selected_docs}")