Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -455,14 +455,16 @@ If any part of the information cannot be verified from this source, clearly stat
|
|
455 |
|
456 |
if model == "@cf/meta/llama-3.1-8b-instruct":
|
457 |
# Use Cloudflare API
|
|
|
458 |
for response in get_response_from_cloudflare(prompt="", context=context, query=query, num_calls=1, temperature=temperature, search_type="web"):
|
459 |
-
|
460 |
-
|
|
|
461 |
else:
|
462 |
# Use Hugging Face API
|
463 |
client = InferenceClient(model, token=huggingface_token)
|
464 |
|
465 |
-
|
466 |
for message in client.chat_completion(
|
467 |
messages=[{"role": "user", "content": prompt}],
|
468 |
max_tokens=2000,
|
@@ -471,9 +473,9 @@ If any part of the information cannot be verified from this source, clearly stat
|
|
471 |
):
|
472 |
if message.choices and message.choices[0].delta and message.choices[0].delta.content:
|
473 |
chunk = message.choices[0].delta.content
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
|
478 |
# Generate an overall summary after processing all sources
|
479 |
overall_prompt = f"""Based on the summaries you've generated for each source, provide a concise overall summary that addresses the user's query: '{query}'
|
@@ -481,9 +483,11 @@ Highlight any conflicting information or gaps in the available data."""
|
|
481 |
|
482 |
if model == "@cf/meta/llama-3.1-8b-instruct":
|
483 |
# Use Cloudflare API for overall summary
|
|
|
484 |
for response in get_response_from_cloudflare(prompt="", context="", query=overall_prompt, num_calls=1, temperature=temperature, search_type="web"):
|
485 |
-
|
486 |
-
|
|
|
487 |
else:
|
488 |
# Use Hugging Face API for overall summary
|
489 |
overall_summary = ""
|
@@ -496,8 +500,8 @@ Highlight any conflicting information or gaps in the available data."""
|
|
496 |
if message.choices and message.choices[0].delta and message.choices[0].delta.content:
|
497 |
chunk = message.choices[0].delta.content
|
498 |
overall_summary += chunk
|
499 |
-
|
500 |
-
|
501 |
|
502 |
def get_response_from_pdf(query, model, selected_docs, num_calls=3, temperature=0.2):
|
503 |
logging.info(f"Entering get_response_from_pdf with query: {query}, model: {model}, selected_docs: {selected_docs}")
|
|
|
455 |
|
456 |
if model == "@cf/meta/llama-3.1-8b-instruct":
|
457 |
# Use Cloudflare API
|
458 |
+
source_response = ""
|
459 |
for response in get_response_from_cloudflare(prompt="", context=context, query=query, num_calls=1, temperature=temperature, search_type="web"):
|
460 |
+
source_response += response
|
461 |
+
accumulated_response += f"Source {i} ({source}):\n\n{source_response}\n\n"
|
462 |
+
yield accumulated_response, ""
|
463 |
else:
|
464 |
# Use Hugging Face API
|
465 |
client = InferenceClient(model, token=huggingface_token)
|
466 |
|
467 |
+
source_response = ""
|
468 |
for message in client.chat_completion(
|
469 |
messages=[{"role": "user", "content": prompt}],
|
470 |
max_tokens=2000,
|
|
|
473 |
):
|
474 |
if message.choices and message.choices[0].delta and message.choices[0].delta.content:
|
475 |
chunk = message.choices[0].delta.content
|
476 |
+
source_response += chunk
|
477 |
+
accumulated_response += f"Source {i} ({source}):\n\n{source_response}\n\n"
|
478 |
+
yield accumulated_response, ""
|
479 |
|
480 |
# Generate an overall summary after processing all sources
|
481 |
overall_prompt = f"""Based on the summaries you've generated for each source, provide a concise overall summary that addresses the user's query: '{query}'
|
|
|
483 |
|
484 |
if model == "@cf/meta/llama-3.1-8b-instruct":
|
485 |
# Use Cloudflare API for overall summary
|
486 |
+
overall_response = ""
|
487 |
for response in get_response_from_cloudflare(prompt="", context="", query=overall_prompt, num_calls=1, temperature=temperature, search_type="web"):
|
488 |
+
overall_response += response
|
489 |
+
accumulated_response += f"Overall Summary:\n\n{overall_response}\n\n"
|
490 |
+
yield accumulated_response, ""
|
491 |
else:
|
492 |
# Use Hugging Face API for overall summary
|
493 |
overall_summary = ""
|
|
|
500 |
if message.choices and message.choices[0].delta and message.choices[0].delta.content:
|
501 |
chunk = message.choices[0].delta.content
|
502 |
overall_summary += chunk
|
503 |
+
accumulated_response += f"Overall Summary:\n\n{overall_summary}\n\n"
|
504 |
+
yield accumulated_response, ""
|
505 |
|
506 |
def get_response_from_pdf(query, model, selected_docs, num_calls=3, temperature=0.2):
|
507 |
logging.info(f"Entering get_response_from_pdf with query: {query}, model: {model}, selected_docs: {selected_docs}")
|