Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -43,7 +43,7 @@ def call_llm_with_retry(groq_client, **payload):
|
|
43 |
"""
|
44 |
Wraps groq_client.chat.completions.create(**payload) in a retry loop
|
45 |
to catch 429 rate-limit errors. If we see “try again in XXs,” we parse
|
46 |
-
that wait time, sleep, then retry. We also do a short sleep (0.3s)
|
47 |
after each successful call to spread usage.
|
48 |
"""
|
49 |
max_retries = 3
|
@@ -127,8 +127,8 @@ def generate_script(
|
|
127 |
sponsor_provided=None
|
128 |
):
|
129 |
"""
|
130 |
-
If you do a single call to generate the entire script.
|
131 |
-
Uses DEEPSEEK_R1. Just ensure you parse the JSON.
|
132 |
"""
|
133 |
print("[LOG] Generating script with tone:", tone, "and length:", target_length)
|
134 |
|
@@ -590,7 +590,7 @@ include key data points and context:
|
|
590 |
merged_input = "\n\n".join(truncated_summaries)
|
591 |
|
592 |
final_prompt = f"""
|
593 |
-
IMPORTANT: Do NOT include chain-of-thought or hidden
|
594 |
Produce a long, academic-style research report with the following structure:
|
595 |
- Title Page (concise descriptive title)
|
596 |
- Table of Contents
|
@@ -612,7 +612,7 @@ Partial Summaries:
|
|
612 |
{merged_input}
|
613 |
References (URLs):
|
614 |
{references_text}
|
615 |
-
Now, merge these partial summaries into one thoroughly expanded research
|
616 |
"""
|
617 |
final_data = {
|
618 |
"model": MODEL_COMBINATION,
|
@@ -623,6 +623,12 @@ Now, merge these partial summaries into one thoroughly expanded research paper:
|
|
623 |
final_response = call_llm_with_retry(groq_client, **final_data)
|
624 |
final_text = final_response.choices[0].message.content.strip()
|
625 |
|
|
|
|
|
|
|
|
|
|
|
|
|
626 |
# Step 6: PDF generation
|
627 |
print("[LOG] Step 6: Generating final PDF from the merged text.")
|
628 |
final_report = generate_report(final_text)
|
|
|
43 |
"""
|
44 |
Wraps groq_client.chat.completions.create(**payload) in a retry loop
|
45 |
to catch 429 rate-limit errors. If we see “try again in XXs,” we parse
|
46 |
+
that wait time, sleep, then retry. We also do a short sleep (0.3s)
|
47 |
after each successful call to spread usage.
|
48 |
"""
|
49 |
max_retries = 3
|
|
|
127 |
sponsor_provided=None
|
128 |
):
|
129 |
"""
|
130 |
+
If you do a single call to generate the entire script.
|
131 |
+
Uses DEEPSEEK_R1. Just ensure you parse the JSON.
|
132 |
"""
|
133 |
print("[LOG] Generating script with tone:", tone, "and length:", target_length)
|
134 |
|
|
|
590 |
merged_input = "\n\n".join(truncated_summaries)
|
591 |
|
592 |
final_prompt = f"""
|
593 |
+
IMPORTANT: Do NOT include any chain-of-thought, internal planning, or hidden reasoning in the final output.
|
594 |
Produce a long, academic-style research report with the following structure:
|
595 |
- Title Page (concise descriptive title)
|
596 |
- Table of Contents
|
|
|
612 |
{merged_input}
|
613 |
References (URLs):
|
614 |
{references_text}
|
615 |
+
Now, merge these partial summaries into one thoroughly expanded research report:
|
616 |
"""
|
617 |
final_data = {
|
618 |
"model": MODEL_COMBINATION,
|
|
|
623 |
final_response = call_llm_with_retry(groq_client, **final_data)
|
624 |
final_text = final_response.choices[0].message.content.strip()
|
625 |
|
626 |
+
# --- NEW POST-PROCESSING STEP ---
|
627 |
+
# Remove any lingering chain-of-thought content (anything between <think> and </think> tags)
|
628 |
+
final_text = re.sub(r"<think>.*?</think>", "", final_text, flags=re.DOTALL)
|
629 |
+
final_text = final_text.strip()
|
630 |
+
# ------------------------------
|
631 |
+
|
632 |
# Step 6: PDF generation
|
633 |
print("[LOG] Step 6: Generating final PDF from the merged text.")
|
634 |
final_report = generate_report(final_text)
|