naman1102 commited on
Commit
1939d2d
·
1 Parent(s): 6b46fb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -388,15 +388,15 @@ QUESTION:
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"""
@@ -408,30 +408,31 @@ QUESTION:
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."
 
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."