joshuarauh commited on
Commit
f6e4af4
·
verified ·
1 Parent(s): bdc7971

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -277,6 +277,12 @@ STRICT REQUIREMENTS:
277
  - Print intermediate steps and final answers
278
  - Print variable values after they are computed"""
279
 
 
 
 
 
 
 
280
  logger.debug("Sending request to Anthropic API")
281
  message = anthropic.messages.create(
282
  model=difficulty_params['model'],
@@ -362,7 +368,6 @@ def check_and_resolve_discrepancy(initial_response, sympy_output):
362
  by making another API call to Claude.
363
  """
364
  try:
365
- # Create prompt showing both solutions and asking for resolution
366
  resolution_prompt = f"""Here is a mathematics question with two answers.
367
  The first, called Original solution, is a complete solution.
368
  The second, called SymPy Verification, will only provide the final answer.
@@ -382,25 +387,31 @@ Original solution:
382
  SymPy Verification Results:
383
  {sympy_output}
384
 
385
-
386
  Please maintain the same LaTeX formatting as the original solution."""
387
 
388
  # Make API call for resolution
389
  message = anthropic.messages.create(
390
  model="claude-3-5-sonnet-20241022",
391
  max_tokens=4096,
392
- temperature=0.2, # Lower temperature for verification
393
  messages=[{
394
  "role": "user",
395
  "content": resolution_prompt
396
  }]
397
  )
398
 
399
- return message.content[0].text
 
 
 
 
 
 
 
400
  except Exception as e:
401
  logger.error(f"Error in discrepancy resolution: {str(e)}")
402
- return initial_response # Return original response if resolution fails
403
-
404
  # Create Gradio interface
405
  with gr.Blocks() as interface:
406
  gr.Markdown("# Advanced Mathematics Question Generator")
 
277
  - Print intermediate steps and final answers
278
  - Print variable values after they are computed"""
279
 
280
+ #Consider
281
+ #When writing SymPy code:
282
+ #- Use FiniteSet(1, 2, 3) instead of Set([1, 2, 3]) for finite sets
283
+ #- Import specific functions instead of using 'from sympy import *'
284
+ #- Print results of each calculation step
285
+
286
  logger.debug("Sending request to Anthropic API")
287
  message = anthropic.messages.create(
288
  model=difficulty_params['model'],
 
368
  by making another API call to Claude.
369
  """
370
  try:
 
371
  resolution_prompt = f"""Here is a mathematics question with two answers.
372
  The first, called Original solution, is a complete solution.
373
  The second, called SymPy Verification, will only provide the final answer.
 
387
  SymPy Verification Results:
388
  {sympy_output}
389
 
 
390
  Please maintain the same LaTeX formatting as the original solution."""
391
 
392
  # Make API call for resolution
393
  message = anthropic.messages.create(
394
  model="claude-3-5-sonnet-20241022",
395
  max_tokens=4096,
396
+ temperature=0.2,
397
  messages=[{
398
  "role": "user",
399
  "content": resolution_prompt
400
  }]
401
  )
402
 
403
+ resolution_text = message.content[0].text
404
+
405
+ # Check if resolution contains new SymPy code
406
+ if "```python" in resolution_text:
407
+ new_sympy_output = extract_and_run_sympy_code(resolution_text)
408
+ resolution_text += "\n\nNew SymPy Verification Results:\n```\n" + new_sympy_output + "\n```"
409
+
410
+ return resolution_text
411
  except Exception as e:
412
  logger.error(f"Error in discrepancy resolution: {str(e)}")
413
+ return initial_response
414
+
415
  # Create Gradio interface
416
  with gr.Blocks() as interface:
417
  gr.Markdown("# Advanced Mathematics Question Generator")