joshuarauh commited on
Commit
4b72003
·
verified ·
1 Parent(s): 118e67c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -27
app.py CHANGED
@@ -726,10 +726,10 @@ Format your response with clear headers and bullet points."""
726
  logger.error(f"Error in ChatGPT verification: {str(e)}")
727
  return f"Error in ChatGPT verification: {str(e)}"
728
 
729
- def append_chatgpt_verification(initial_response, SYMPY_CONFIRMED, final_verification=None):
730
  """
731
  Main function to handle the ChatGPT verification process.
732
- Returns the original response with the ChatGPT verification appended.
733
  """
734
  try:
735
  # Get the appropriate solution text for verification
@@ -738,7 +738,7 @@ def append_chatgpt_verification(initial_response, SYMPY_CONFIRMED, final_verific
738
  # Get ChatGPT's verification
739
  chatgpt_verification = verify_with_chatgpt(question, solution_text)
740
 
741
- if chatgpt_verification: # Add this check
742
  full_response = f"{initial_response}\n\nChatGPT Verification and Grading:\n{chatgpt_verification}"
743
  return full_response
744
  return initial_response
@@ -808,10 +808,10 @@ Part II. Now select the problem that is number {difficulty} on your exam, state
808
  * The only numerical calculations that should be done are those that could be done on a simple scientific calculator.
809
  * Make sure to simplify completely as far as analytical methods will allow
810
  4. Maintain clear formatting
811
- 5. At the end of the solution output, print SymPy code that you would use to solve or verify the main equations in the question
812
- 6. Observe the folloiwng SymPy Guidelines
813
  {SYMPY_GUIDELINES}
814
- 7. For problems where the subject is Real Analysis, observe the following guidelines:
815
 
816
  a. **Justify Every Step**
817
  - Provide detailed reasoning for each step and explicitly justify every bounding argument, inequality, or limit claim.
@@ -857,23 +857,23 @@ j. **Concluding and Intuitive Explanations**
857
  - Conclude with an intuitive explanation of why the result makes sense, possibly connecting it to known theorems or simple examples.
858
  - In notes after the proof, highlight potential sources of confusion for students and clarify tricky aspects of the problem.
859
 
860
- 9. When finding critical points in multivariable calculus:
861
  - Always check what happens when any variable equals zero (except where undefined)
862
  - Just because a point is ruled out of the domain doesn't mean that entire line/curve is ruled out
863
  - When the Hessian is inconclusive, evaluate the function along the critical curves to determine behavior
864
  - Don't rely solely on the Hessian - consider direct function evaluation and nearby points
865
 
866
- 10. When using symmetry arguments:
867
  - Explicitly state what is symmetric
868
  - Identify the axis/plane of symmetry
869
 
870
- 11. In calculus do not forget opportunities to apply power-reduction formulas for trig functions
871
  - e.g.: Integral from 0 to pi of [cos(theta)]^(2n) d(theta) = (pi / 2^(2n)) * (2n choose n), where choose is the combinatorial choose function
872
 
873
- 12. In expanding or factoring polynomial expressions, be careful not to make errors
874
  - (1+u^2)^2 is equal to (1+2u^2+u^4), NOT equal to (1+3u^2+u^4)
875
 
876
- 13. When finding points where dy/dx = 0 in parametric equations:
877
  - (a) First find the ratio dy/dx = (dy/dt)/(dx/dt)
878
  - (b) Find t-values where this ratio equals 0
879
  - (c) CRITICAL: For any t-values where both dy/dt = 0 AND dx/dt = 0:
@@ -888,7 +888,7 @@ j. **Concluding and Intuitive Explanations**
888
  - Verify the point lies on the curve
889
  - State whether it's a regular point or special point (cusp, corner, etc.)
890
 
891
- 14. Be careful with trigonometric expressions involving powers
892
  - Example: solving sin^2(x)=cos(x) can be solved as 1-cos^2(x)=cos(x)
893
 
894
  """
@@ -925,16 +925,12 @@ j. **Concluding and Intuitive Explanations**
925
  logger.debug("Successfully received response from Anthropic API")
926
 
927
  # Execute SymPy code and append results
928
- sympy_output = extract_and_run_sympy_code_simple(response_text)
929
- has_discrepancy = False # Initialize outside the if block
930
- SYMPY_CONFIRMED = None
931
- revised_solution = None
932
- final_verification = None
933
-
934
- # Store original response text before modifications
935
- original_response = response_text
936
 
937
- # Always do verification analysis
938
  if "Error" in sympy_output:
939
  verification_text = "SymPy verification failed with error. Manual solution must be verified independently."
940
  SYMPY_CONFIRMED = "Inconclusive"
@@ -944,16 +940,15 @@ j. **Concluding and Intuitive Explanations**
944
  response_text = f"{response_text}\n\nSymPy Verification Results:\n```\n{sympy_output}\n```\n\nVerification Analysis:\n{resolution_text}"
945
 
946
  if has_discrepancy and revised_solution:
947
- logger.debug("Performing final verification for problem with discrepancy")
948
  final_verification = perform_final_verification(revised_solution, SYMPY_CONFIRMED)
949
  response_text += "\n\nFinal Expert Verification:\n" + final_verification
950
-
951
  # add the ChatGPT verification
952
  if include_chatgpt == "yes":
953
  response_text = append_chatgpt_verification(
954
  response_text,
955
- SYMPY_CONFIRMED,
956
- final_verification if has_discrepancy else None
957
  )
958
 
959
  # Create LaTeX content
@@ -980,12 +975,12 @@ def extract_and_run_sympy_code_simple(response_text):
980
  # Extract code
981
  sympy_start = response_text.find('```python')
982
  if sympy_start == -1:
983
- return "No SymPy code found in the response."
984
 
985
  code_start = response_text.find('\n', sympy_start) + 1
986
  code_end = response_text.find('```', code_start)
987
  if code_end == -1:
988
- return "Malformed SymPy code block."
989
 
990
  sympy_code = response_text[code_start:code_end].strip()
991
 
 
726
  logger.error(f"Error in ChatGPT verification: {str(e)}")
727
  return f"Error in ChatGPT verification: {str(e)}"
728
 
729
+ def append_chatgpt_verification(initial_response, SYMPY_CONFIRMED=None, final_verification=None):
730
  """
731
  Main function to handle the ChatGPT verification process.
732
+ Now handles cases where SymPy verification wasn't performed.
733
  """
734
  try:
735
  # Get the appropriate solution text for verification
 
738
  # Get ChatGPT's verification
739
  chatgpt_verification = verify_with_chatgpt(question, solution_text)
740
 
741
+ if chatgpt_verification:
742
  full_response = f"{initial_response}\n\nChatGPT Verification and Grading:\n{chatgpt_verification}"
743
  return full_response
744
  return initial_response
 
808
  * The only numerical calculations that should be done are those that could be done on a simple scientific calculator.
809
  * Make sure to simplify completely as far as analytical methods will allow
810
  4. Maintain clear formatting
811
+ 5. For Calculation or Application questions (NOT Proof questions): at the end of the solution output, print SymPy code that you would use to solve or verify the main equations in the question.
812
+ Observe the folloiwng SymPy Guidelines
813
  {SYMPY_GUIDELINES}
814
+ 6. For problems where the subject is Real Analysis, observe the following guidelines:
815
 
816
  a. **Justify Every Step**
817
  - Provide detailed reasoning for each step and explicitly justify every bounding argument, inequality, or limit claim.
 
857
  - Conclude with an intuitive explanation of why the result makes sense, possibly connecting it to known theorems or simple examples.
858
  - In notes after the proof, highlight potential sources of confusion for students and clarify tricky aspects of the problem.
859
 
860
+ 7. When finding critical points in multivariable calculus:
861
  - Always check what happens when any variable equals zero (except where undefined)
862
  - Just because a point is ruled out of the domain doesn't mean that entire line/curve is ruled out
863
  - When the Hessian is inconclusive, evaluate the function along the critical curves to determine behavior
864
  - Don't rely solely on the Hessian - consider direct function evaluation and nearby points
865
 
866
+ 8. When using symmetry arguments:
867
  - Explicitly state what is symmetric
868
  - Identify the axis/plane of symmetry
869
 
870
+ 9. In calculus do not forget opportunities to apply power-reduction formulas for trig functions
871
  - e.g.: Integral from 0 to pi of [cos(theta)]^(2n) d(theta) = (pi / 2^(2n)) * (2n choose n), where choose is the combinatorial choose function
872
 
873
+ 10. In expanding or factoring polynomial expressions, be careful not to make errors
874
  - (1+u^2)^2 is equal to (1+2u^2+u^4), NOT equal to (1+3u^2+u^4)
875
 
876
+ 11. When finding points where dy/dx = 0 in parametric equations:
877
  - (a) First find the ratio dy/dx = (dy/dt)/(dx/dt)
878
  - (b) Find t-values where this ratio equals 0
879
  - (c) CRITICAL: For any t-values where both dy/dt = 0 AND dx/dt = 0:
 
888
  - Verify the point lies on the curve
889
  - State whether it's a regular point or special point (cusp, corner, etc.)
890
 
891
+ 12. Be careful with trigonometric expressions involving powers
892
  - Example: solving sin^2(x)=cos(x) can be solved as 1-cos^2(x)=cos(x)
893
 
894
  """
 
925
  logger.debug("Successfully received response from Anthropic API")
926
 
927
  # Execute SymPy code and append results
928
+ if sympy_output is not None:
929
+ has_discrepancy = False
930
+ SYMPY_CONFIRMED = None
931
+ revised_solution = None
932
+ final_verification = None
 
 
 
933
 
 
934
  if "Error" in sympy_output:
935
  verification_text = "SymPy verification failed with error. Manual solution must be verified independently."
936
  SYMPY_CONFIRMED = "Inconclusive"
 
940
  response_text = f"{response_text}\n\nSymPy Verification Results:\n```\n{sympy_output}\n```\n\nVerification Analysis:\n{resolution_text}"
941
 
942
  if has_discrepancy and revised_solution:
 
943
  final_verification = perform_final_verification(revised_solution, SYMPY_CONFIRMED)
944
  response_text += "\n\nFinal Expert Verification:\n" + final_verification
945
+
946
  # add the ChatGPT verification
947
  if include_chatgpt == "yes":
948
  response_text = append_chatgpt_verification(
949
  response_text,
950
+ SYMPY_CONFIRMED if sympy_output is not None else None,
951
+ final_verification if sympy_output is not None and has_discrepancy else None
952
  )
953
 
954
  # Create LaTeX content
 
975
  # Extract code
976
  sympy_start = response_text.find('```python')
977
  if sympy_start == -1:
978
+ return None # Changed from error message to None
979
 
980
  code_start = response_text.find('\n', sympy_start) + 1
981
  code_end = response_text.find('```', code_start)
982
  if code_end == -1:
983
+ return None # Changed from error message to None
984
 
985
  sympy_code = response_text[code_start:code_end].strip()
986