Update app.py
Browse files
app.py
CHANGED
@@ -388,13 +388,14 @@ QUESTION:
|
|
388 |
MATERIALS:
|
389 |
{search_block}
|
390 |
|
391 |
-
|
392 |
"""
|
393 |
try:
|
394 |
-
|
|
|
395 |
|
396 |
# If first attempt fails or is empty, try a more direct prompt
|
397 |
-
if not answer or any(k in answer.lower() for k in ["cannot", "sorry", "don't know"]):
|
398 |
print("\nFirst attempt failed, trying direct prompt...")
|
399 |
direct_prompt = f"""
|
400 |
Answer this question directly and concisely. Use the materials provided.
|
@@ -406,11 +407,13 @@ MATERIALS:
|
|
406 |
{search_block}
|
407 |
|
408 |
If you cannot find an exact answer, provide the most relevant information from the materials.
|
|
|
409 |
"""
|
410 |
-
|
|
|
411 |
|
412 |
# Final validation and fallback
|
413 |
-
if not answer:
|
414 |
print("\nBoth attempts failed, using fallback answer...")
|
415 |
if materials:
|
416 |
# If we have materials but no answer, summarize what we know
|
@@ -418,8 +421,11 @@ If you cannot find an exact answer, provide the most relevant information from t
|
|
418 |
Summarize the key information from these materials in one sentence:
|
419 |
|
420 |
{search_block}
|
|
|
|
|
421 |
"""
|
422 |
-
|
|
|
423 |
else:
|
424 |
answer = "I cannot provide a definitive answer at this time."
|
425 |
|
|
|
388 |
MATERIALS:
|
389 |
{search_block}
|
390 |
|
391 |
+
Write ANSWER: <answer> on its own line.
|
392 |
"""
|
393 |
try:
|
394 |
+
raw = self._call_llm(prompt, 300)
|
395 |
+
answer = raw.split("ANSWER:")[-1].strip()
|
396 |
|
397 |
# If first attempt fails or is empty, try a more direct prompt
|
398 |
+
if not answer or "ANSWER:" not in raw or any(k in answer.lower() for k in ["cannot", "sorry", "don't know"]):
|
399 |
print("\nFirst attempt failed, trying direct prompt...")
|
400 |
direct_prompt = f"""
|
401 |
Answer this question directly and concisely. Use the materials provided.
|
|
|
407 |
{search_block}
|
408 |
|
409 |
If you cannot find an exact answer, provide the most relevant information from the materials.
|
410 |
+
Write ANSWER: <answer> on its own line.
|
411 |
"""
|
412 |
+
raw = self._call_llm(direct_prompt, 300)
|
413 |
+
answer = raw.split("ANSWER:")[-1].strip()
|
414 |
|
415 |
# Final validation and fallback
|
416 |
+
if not answer or "ANSWER:" not in raw:
|
417 |
print("\nBoth attempts failed, using fallback answer...")
|
418 |
if materials:
|
419 |
# If we have materials but no answer, summarize what we know
|
|
|
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 |
+
raw = self._call_llm(summary_prompt, 150)
|
428 |
+
answer = raw.split("ANSWER:")[-1].strip()
|
429 |
else:
|
430 |
answer = "I cannot provide a definitive answer at this time."
|
431 |
|