Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -605,7 +605,10 @@ 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.
|
|
|
|
|
|
|
609 |
|
610 |
Original solution:
|
611 |
{initial_response}
|
@@ -634,26 +637,58 @@ 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 |
-
#
|
638 |
-
|
|
|
|
|
|
|
|
|
639 |
|
640 |
-
# Look for the
|
|
|
641 |
revised_solution = None
|
|
|
642 |
if has_discrepancy:
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
|
|
|
|
|
|
|
|
647 |
|
|
|
648 |
if not revised_solution:
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
654 |
if len(parts) > 1:
|
655 |
revised_solution = parts[1].strip()
|
656 |
-
|
|
|
657 |
|
658 |
return resolution_text, has_discrepancy, revised_solution
|
659 |
|
@@ -712,8 +747,7 @@ Please ensure any corrected solution maintains proper LaTeX formatting with $ fo
|
|
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:
|
719 |
gr.Markdown("# Advanced Mathematics Question Generator")
|
|
|
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. Write "Here is the revised complete solution:" and then write out the ENTIRE solution from beginning
|
609 |
+
to end, including all parts that were correct and the corrections for any incorrect parts.
|
610 |
+
Do not refer to the original solution or say things like "the rest remains the same" - write
|
611 |
+
out everything in full.
|
612 |
|
613 |
Original solution:
|
614 |
{initial_response}
|
|
|
637 |
resolution_text += "\n\nNew SymPy Verification Results:\n```\n" + new_sympy_output + "\n```"
|
638 |
|
639 |
# Determine if there was a discrepancy that required a revised solution
|
640 |
+
# Check for any indication of inconsistency or error
|
641 |
+
inconsistency_phrases = [
|
642 |
+
"inconsistent", "inconsistency", "incorrect", "error", "wrong",
|
643 |
+
"differs", "different", "discrepancy", "mistaken", "mistake"
|
644 |
+
]
|
645 |
+
has_discrepancy = any(phrase in resolution_text.lower() for phrase in inconsistency_phrases)
|
646 |
|
647 |
+
# Look for the required marker phrase and extract the solution after it
|
648 |
+
marker = "Here is the revised complete solution:"
|
649 |
revised_solution = None
|
650 |
+
|
651 |
if has_discrepancy:
|
652 |
+
# Split at the marker
|
653 |
+
if marker in resolution_text:
|
654 |
+
parts = resolution_text.split(marker, maxsplit=1)
|
655 |
+
if len(parts) > 1:
|
656 |
+
revised_solution = parts[1].strip()
|
657 |
+
# If the solution seems too short (might be partial), don't accept it
|
658 |
+
if len(revised_solution) < 100: # Rough minimum length for a complete solution
|
659 |
+
revised_solution = None
|
660 |
|
661 |
+
# If we didn't find a complete solution, force a recheck
|
662 |
if not revised_solution:
|
663 |
+
logger.debug("Initial solution extraction failed, requesting a complete solution")
|
664 |
+
# Make a new API call specifically requesting a complete solution
|
665 |
+
complete_solution_prompt = f"""The previous solution had inconsistencies. Please provide a complete solution
|
666 |
+
from beginning to end. Start your response with exactly this phrase:
|
667 |
+
"Here is the revised complete solution:"
|
668 |
+
Then write out the entire solution, including all parts both correct and corrected.
|
669 |
+
Do not refer to the original solution or say any parts remain the same.
|
670 |
+
|
671 |
+
Original problem and verification results:
|
672 |
+
{initial_response}
|
673 |
+
|
674 |
+
SymPy Results:
|
675 |
+
{sympy_output}"""
|
676 |
+
|
677 |
+
try:
|
678 |
+
message = anthropic.messages.create(
|
679 |
+
model="claude-3-5-sonnet-20241022",
|
680 |
+
max_tokens=4096,
|
681 |
+
temperature=0.2,
|
682 |
+
messages=[{"role": "user", "content": complete_solution_prompt}]
|
683 |
+
)
|
684 |
+
|
685 |
+
new_response = message.content[0].text
|
686 |
+
if marker in new_response:
|
687 |
+
parts = new_response.split(marker, maxsplit=1)
|
688 |
if len(parts) > 1:
|
689 |
revised_solution = parts[1].strip()
|
690 |
+
except Exception as e:
|
691 |
+
logger.error(f"Error in solution recheck: {str(e)}")
|
692 |
|
693 |
return resolution_text, has_discrepancy, revised_solution
|
694 |
|
|
|
747 |
except Exception as e:
|
748 |
logger.error(f"Error in final verification: {str(e)}")
|
749 |
return f"Error in final verification: {str(e)}"
|
750 |
+
|
|
|
751 |
# Create Gradio interface
|
752 |
with gr.Blocks() as interface:
|
753 |
gr.Markdown("# Advanced Mathematics Question Generator")
|