joshuarauh commited on
Commit
6f7bf4c
·
verified ·
1 Parent(s): 02551fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -11
app.py CHANGED
@@ -499,7 +499,7 @@ STRICT REQUIREMENTS:
499
  logger.error("No content received from Anthropic API")
500
  return "Error: No content received from API", None, None
501
 
502
- response_text = message.content[0].text
503
  logger.debug("Successfully received response from Anthropic API")
504
 
505
  # Execute SymPy code and append results
@@ -530,10 +530,6 @@ STRICT REQUIREMENTS:
530
  logger.debug("Successfully created temporary files")
531
 
532
  return response_text, questions_path, full_path
533
-
534
- except Exception as e:
535
- logger.error(f"Error generating question: {str(e)}")
536
- return f"Error: {str(e)}", None, None
537
 
538
  def extract_and_run_sympy_code_simple(response_text):
539
  """
@@ -605,8 +601,7 @@ def check_and_resolve_discrepancy(initial_response, sympy_output):
605
  If the two answers are inconsistent with each other then please:
606
  1. Identify which solution is correct
607
  2. Explain the error in the incorrect solution
608
- 3. Provide a revised COMPLETE solution that fixes any errors, does not refer to SymPy,
609
- and does not refer to the Original solution even if this means large parts of the Original solution are repeated.
610
 
611
  Original solution:
612
  {initial_response}
@@ -635,15 +630,31 @@ Please maintain the same LaTeX formatting as the original solution."""
635
  resolution_text += "\n\nNew SymPy Verification Results:\n```\n" + new_sympy_output + "\n```"
636
 
637
  # Determine if there was a discrepancy that required a revised solution
638
- has_discrepancy = "revised complete solution" in resolution_text.lower()
 
 
 
 
 
 
 
 
 
639
 
640
  # Extract revised solution if it exists
641
  revised_solution = None
642
- if has_discrepancy:
643
  # Look for the revised solution after the explanation
644
- solution_parts = resolution_text.split("revised complete solution", maxsplit=1)
645
  if len(solution_parts) > 1:
646
  revised_solution = solution_parts[1].strip()
 
 
 
 
 
 
 
647
 
648
  return resolution_text, has_discrepancy, revised_solution
649
 
@@ -669,7 +680,7 @@ Please:
669
 
670
  If you find any issues:
671
  1. Clearly explain what is incorrect or missing
672
- 2. Provide a COMPLETE corrected solution
673
  3. Maintain the same LaTeX formatting as the original
674
  4. Include any missing assumptions or conditions
675
  5. If relevant, provide corrected SymPy code
 
499
  logger.error("No content received from Anthropic API")
500
  return "Error: No content received from API", None, None
501
 
502
+ response_text = message.content[0].text
503
  logger.debug("Successfully received response from Anthropic API")
504
 
505
  # Execute SymPy code and append results
 
530
  logger.debug("Successfully created temporary files")
531
 
532
  return response_text, questions_path, full_path
 
 
 
 
533
 
534
  def extract_and_run_sympy_code_simple(response_text):
535
  """
 
601
  If the two answers are inconsistent with each other then please:
602
  1. Identify which solution is correct
603
  2. Explain the error in the incorrect solution
604
+ 3. Provide a revised complete solution from the beginning that fixes any errors and does not refer to SymPy
 
605
 
606
  Original solution:
607
  {initial_response}
 
630
  resolution_text += "\n\nNew SymPy Verification Results:\n```\n" + new_sympy_output + "\n```"
631
 
632
  # Determine if there was a discrepancy that required a revised solution
633
+ # Check for various phrasings that indicate a revised solution
634
+ revision_phrases = ["revised complete solution", "revised solution", "correct complete solution", "corrected solution"]
635
+ has_discrepancy = False
636
+ found_phrase = None
637
+
638
+ for phrase in revision_phrases:
639
+ if phrase in resolution_text.lower():
640
+ has_discrepancy = True
641
+ found_phrase = phrase
642
+ break
643
 
644
  # Extract revised solution if it exists
645
  revised_solution = None
646
+ if has_discrepancy and found_phrase:
647
  # Look for the revised solution after the explanation
648
+ solution_parts = resolution_text.split(found_phrase, maxsplit=1)
649
  if len(solution_parts) > 1:
650
  revised_solution = solution_parts[1].strip()
651
+
652
+ # Add additional check for solutions that might appear after "here's the"
653
+ if not revised_solution and "here's the" in solution_parts[0].lower():
654
+ solution_parts = resolution_text.split("here's the", maxsplit=1)
655
+ if len(solution_parts) > 1:
656
+ revised_solution = solution_parts[1].strip()
657
+ has_discrepancy = True
658
 
659
  return resolution_text, has_discrepancy, revised_solution
660
 
 
680
 
681
  If you find any issues:
682
  1. Clearly explain what is incorrect or missing
683
+ 2. Provide a COMPLETE CORRECTED solution
684
  3. Maintain the same LaTeX formatting as the original
685
  4. Include any missing assumptions or conditions
686
  5. If relevant, provide corrected SymPy code