joshuarauh commited on
Commit
fbc3848
·
verified ·
1 Parent(s): 9223a59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -26
app.py CHANGED
@@ -530,7 +530,7 @@ 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
@@ -605,7 +605,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 from the beginning that fixes any errors and does not refer to SymPy
609
 
610
  Original solution:
611
  {initial_response}
@@ -634,31 +634,26 @@ Please maintain the same LaTeX formatting as the original solution."""
634
  resolution_text += "\n\nNew SymPy Verification Results:\n```\n" + new_sympy_output + "\n```"
635
 
636
  # Determine if there was a discrepancy that required a revised solution
637
- # Check for various phrasings that indicate a revised solution
638
- revision_phrases = ["revised complete solution", "revised solution", "correct complete solution", "corrected solution"]
639
- has_discrepancy = False
640
- found_phrase = None
641
-
642
- for phrase in revision_phrases:
643
- if phrase in resolution_text.lower():
644
- has_discrepancy = True
645
- found_phrase = phrase
646
- break
647
-
648
- # Extract revised solution if it exists
649
  revised_solution = None
650
- if has_discrepancy and found_phrase:
651
- # Look for the revised solution after the explanation
652
- solution_parts = resolution_text.split(found_phrase, maxsplit=1)
653
- if len(solution_parts) > 1:
654
- revised_solution = solution_parts[1].strip()
655
 
656
- # Add additional check for solutions that might appear after "here's the"
657
- if not revised_solution and "here's the" in solution_parts[0].lower():
658
- solution_parts = resolution_text.split("here's the", maxsplit=1)
659
- if len(solution_parts) > 1:
660
- revised_solution = solution_parts[1].strip()
661
- has_discrepancy = True
 
 
 
662
 
663
  return resolution_text, has_discrepancy, revised_solution
664
 
@@ -684,7 +679,7 @@ Please:
684
 
685
  If you find any issues:
686
  1. Clearly explain what is incorrect or missing
687
- 2. Provide a COMPLETE CORRECTED solution
688
  3. Maintain the same LaTeX formatting as the original
689
  4. Include any missing assumptions or conditions
690
  5. If relevant, provide corrected SymPy code
@@ -717,6 +712,7 @@ Please ensure any corrected solution maintains proper LaTeX formatting with $ fo
717
  except Exception as e:
718
  logger.error(f"Error in final verification: {str(e)}")
719
  return f"Error in final verification: {str(e)}"
 
720
 
721
  # Create Gradio interface
722
  with gr.Blocks() as interface:
 
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
 
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 and does not refer to SymPy
609
 
610
  Original solution:
611
  {initial_response}
 
634
  resolution_text += "\n\nNew SymPy Verification Results:\n```\n" + new_sympy_output + "\n```"
635
 
636
  # Determine if there was a discrepancy that required a revised solution
637
+ # First check if there's an inconsistency mentioned
638
+ has_discrepancy = "inconsistent" in resolution_text.lower() or "inconsistency" in resolution_text.lower()
639
+
640
+ # Look for the exact phrase we required in the prompt
 
 
 
 
 
 
 
 
641
  revised_solution = None
642
+ if has_discrepancy:
643
+ marker = "Here is the revised complete solution:"
644
+ parts = resolution_text.split(marker, maxsplit=1)
645
+ if len(parts) > 1:
646
+ revised_solution = parts[1].strip()
647
 
648
+ if not revised_solution:
649
+ # Fallback check for common revision phrases
650
+ revision_phrases = ["revised complete solution:", "revised solution:", "correct solution:", "corrected solution:"]
651
+ for phrase in revision_phrases:
652
+ if phrase in resolution_text.lower():
653
+ parts = resolution_text.split(phrase, maxsplit=1)
654
+ if len(parts) > 1:
655
+ revised_solution = parts[1].strip()
656
+ break
657
 
658
  return resolution_text, has_discrepancy, revised_solution
659
 
 
679
 
680
  If you find any issues:
681
  1. Clearly explain what is incorrect or missing
682
+ 2. Provide a complete corrected solution
683
  3. Maintain the same LaTeX formatting as the original
684
  4. Include any missing assumptions or conditions
685
  5. If relevant, provide corrected SymPy code
 
712
  except Exception as e:
713
  logger.error(f"Error in final verification: {str(e)}")
714
  return f"Error in final verification: {str(e)}"
715
+
716
 
717
  # Create Gradio interface
718
  with gr.Blocks() as interface: