Update app.py
Browse files
app.py
CHANGED
@@ -388,15 +388,15 @@ QUESTION:
|
|
388 |
MATERIALS:
|
389 |
{search_block}
|
390 |
|
391 |
-
Return ONLY
|
392 |
-
{{"ANSWER": "
|
393 |
"""
|
394 |
try:
|
395 |
raw = self._call_llm(prompt, 300)
|
396 |
try:
|
397 |
-
|
398 |
-
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"""
|
@@ -408,30 +408,31 @@ QUESTION:
|
|
408 |
MATERIALS:
|
409 |
{search_block}
|
410 |
|
411 |
-
Return ONLY
|
412 |
-
{{"ANSWER": "
|
413 |
"""
|
414 |
raw = self._call_llm(direct_prompt, 300)
|
415 |
try:
|
416 |
-
|
417 |
-
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 |
-
|
433 |
-
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."
|
|
|
388 |
MATERIALS:
|
389 |
{search_block}
|
390 |
|
391 |
+
Return ONLY this exact JSON object:
|
392 |
+
{{"ANSWER": "<answer text>"}}
|
393 |
"""
|
394 |
try:
|
395 |
raw = self._call_llm(prompt, 300)
|
396 |
try:
|
397 |
+
data = json.loads(raw)
|
398 |
+
answer = data["ANSWER"]
|
399 |
+
except (json.JSONDecodeError, KeyError):
|
400 |
print("\nJSON parse error, trying direct prompt...")
|
401 |
# If first attempt fails, try a more direct prompt
|
402 |
direct_prompt = f"""
|
|
|
408 |
MATERIALS:
|
409 |
{search_block}
|
410 |
|
411 |
+
Return ONLY this exact JSON object:
|
412 |
+
{{"ANSWER": "<answer text>"}}
|
413 |
"""
|
414 |
raw = self._call_llm(direct_prompt, 300)
|
415 |
try:
|
416 |
+
data = json.loads(raw)
|
417 |
+
answer = data["ANSWER"]
|
418 |
+
except (json.JSONDecodeError, KeyError):
|
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 |
|
425 |
MATERIALS:
|
426 |
{search_block}
|
427 |
+
|
428 |
+
Return ONLY this exact JSON object:
|
429 |
+
{{"ANSWER": "<answer text>"}}
|
430 |
"""
|
431 |
raw = self._call_llm(summary_prompt, 150)
|
432 |
try:
|
433 |
+
data = json.loads(raw)
|
434 |
+
answer = data["ANSWER"]
|
435 |
+
except (json.JSONDecodeError, KeyError):
|
436 |
answer = "I cannot provide a definitive answer at this time."
|
437 |
else:
|
438 |
answer = "I cannot provide a definitive answer at this time."
|