Update app.py
Browse files
app.py
CHANGED
@@ -388,15 +388,17 @@ QUESTION:
|
|
388 |
MATERIALS:
|
389 |
{search_block}
|
390 |
|
391 |
-
|
|
|
392 |
"""
|
393 |
try:
|
394 |
raw = self._call_llm(prompt, 300)
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
print("\
|
|
|
400 |
direct_prompt = f"""
|
401 |
Answer this question directly and concisely. Use the materials provided.
|
402 |
|
@@ -406,28 +408,33 @@ QUESTION:
|
|
406 |
MATERIALS:
|
407 |
{search_block}
|
408 |
|
409 |
-
|
410 |
-
|
411 |
"""
|
412 |
raw = self._call_llm(direct_prompt, 300)
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
Summarize the key information from these materials in one sentence
|
|
|
|
|
422 |
|
|
|
423 |
{search_block}
|
424 |
-
|
425 |
-
Write ANSWER: <answer> on its own line.
|
426 |
"""
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
|
|
|
|
|
|
|
|
431 |
|
432 |
state["final_answer"] = answer
|
433 |
state["current_step"] = "done"
|
@@ -508,7 +515,7 @@ Write ANSWER: <answer> on its own line.
|
|
508 |
}
|
509 |
|
510 |
final_state = self.workflow.invoke(state)
|
511 |
-
return final_state["final_answer"]
|
512 |
|
513 |
def _download_file(self, url: str) -> bytes:
|
514 |
"""Download a file from a URL."""
|
|
|
388 |
MATERIALS:
|
389 |
{search_block}
|
390 |
|
391 |
+
Return ONLY a JSON object in this format:
|
392 |
+
{{"ANSWER": "your answer here"}}
|
393 |
"""
|
394 |
try:
|
395 |
raw = self._call_llm(prompt, 300)
|
396 |
+
try:
|
397 |
+
result = json.loads(raw)
|
398 |
+
answer = result.get("ANSWER", "")
|
399 |
+
except json.JSONDecodeError:
|
400 |
+
print("\nJSON parse error, trying direct prompt...")
|
401 |
+
# If first attempt fails, try a more direct prompt
|
402 |
direct_prompt = f"""
|
403 |
Answer this question directly and concisely. Use the materials provided.
|
404 |
|
|
|
408 |
MATERIALS:
|
409 |
{search_block}
|
410 |
|
411 |
+
Return ONLY a JSON object in this format:
|
412 |
+
{{"ANSWER": "your answer here"}}
|
413 |
"""
|
414 |
raw = self._call_llm(direct_prompt, 300)
|
415 |
+
try:
|
416 |
+
result = json.loads(raw)
|
417 |
+
answer = result.get("ANSWER", "")
|
418 |
+
except json.JSONDecodeError:
|
419 |
+
print("\nBoth attempts failed, using fallback answer...")
|
420 |
+
if materials:
|
421 |
+
# If we have materials but no answer, summarize what we know
|
422 |
+
summary_prompt = f"""
|
423 |
+
Summarize the key information from these materials in one sentence.
|
424 |
+
Return ONLY a JSON object in this format:
|
425 |
+
{{"ANSWER": "your summary here"}}
|
426 |
|
427 |
+
MATERIALS:
|
428 |
{search_block}
|
|
|
|
|
429 |
"""
|
430 |
+
raw = self._call_llm(summary_prompt, 150)
|
431 |
+
try:
|
432 |
+
result = json.loads(raw)
|
433 |
+
answer = result.get("ANSWER", "")
|
434 |
+
except json.JSONDecodeError:
|
435 |
+
answer = "I cannot provide a definitive answer at this time."
|
436 |
+
else:
|
437 |
+
answer = "I cannot provide a definitive answer at this time."
|
438 |
|
439 |
state["final_answer"] = answer
|
440 |
state["current_step"] = "done"
|
|
|
515 |
}
|
516 |
|
517 |
final_state = self.workflow.invoke(state)
|
518 |
+
return final_state["final_answer"] # Return the answer string directly, not JSON encoded
|
519 |
|
520 |
def _download_file(self, url: str) -> bytes:
|
521 |
"""Download a file from a URL."""
|