joshuarauh commited on
Commit
3646962
·
verified ·
1 Parent(s): 5867946

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -1
app.py CHANGED
@@ -25,6 +25,75 @@ anthropic = Anthropic(
25
  MAX_REQUESTS_PER_DAY = 25
26
  request_history = deque(maxlen=1000)
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  def get_difficulty_parameters(difficulty_level):
29
  """Return specific parameters and constraints based on difficulty level"""
30
  parameters = {
@@ -282,7 +351,11 @@ STRICT REQUIREMENTS:
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'],
 
25
  MAX_REQUESTS_PER_DAY = 25
26
  request_history = deque(maxlen=1000)
27
 
28
+ import json
29
+ from pathlib import Path
30
+
31
+ def load_proof_repository():
32
+ """Load the proof repository from the repository file"""
33
+ repo_path = Path("naturalproofs_trench.json")
34
+ try:
35
+ with open(repo_path, "r") as f:
36
+ return json.load(f)
37
+ except Exception as e:
38
+ logger.error(f"Error loading proof repository: {str(e)}")
39
+ return None
40
+
41
+ def get_relevant_proofs(topic):
42
+ """Get relevant proofs from repository based on topic, randomly selecting examples"""
43
+ repository = load_proof_repository()
44
+ if not repository:
45
+ return []
46
+
47
+ # Extract relevant proofs based on topic
48
+ relevant_proofs = []
49
+ for theorem in repository.get("dataset", {}).get("theorems", []):
50
+ # Add proofs that match the topic
51
+ if any(topic.lower() in content.lower() for content in theorem.get("contents", [])):
52
+ # Only include if it has both contents and proofs
53
+ if theorem.get("contents") and theorem.get("proofs"):
54
+ proof_content = {
55
+ "title": theorem.get("title", ""),
56
+ "contents": theorem.get("contents", []),
57
+ "proofs": [p.get("contents", []) for p in theorem.get("proofs", [])]
58
+ }
59
+ relevant_proofs.append(proof_content)
60
+
61
+ # Randomly select 3 proofs if we have more than 3
62
+ if len(relevant_proofs) > 3:
63
+ return random.sample(relevant_proofs, 3)
64
+ return relevant_proofs
65
+
66
+ def enhance_prompt_with_proofs(system_prompt, subject, topic):
67
+ """Enhance the system prompt with relevant proofs if subject is Real Analysis"""
68
+ if subject != "Real Analysis":
69
+ return system_prompt
70
+
71
+ relevant_proofs = get_relevant_proofs(topic)
72
+ if not relevant_proofs:
73
+ return system_prompt
74
+
75
+ # Add proof examples to the prompt
76
+ proof_examples = "\n\nReference these proof examples for style and approach:\n"
77
+ for proof in relevant_proofs[:3]: # Limit to 3 examples to manage token usage
78
+ proof_examples += f"\nTheorem: {proof['title']}\n"
79
+ proof_examples += "Statement: " + " ".join(proof['contents']) + "\n"
80
+ if proof['proofs']:
81
+ proof_examples += "Proof: " + " ".join(proof['proofs'][0]) + "\n"
82
+
83
+ # Add specific instructions for using the examples
84
+ enhanced_prompt = f"""
85
+ {system_prompt}
86
+
87
+ ADDITIONAL PROOF GUIDELINES:
88
+ 1. Consider the following proof examples from established textbooks
89
+ 2. Maintain similar level of rigor and detail
90
+ 3. Use similar proof techniques where applicable
91
+ 4. Follow similar notation and presentation style
92
+
93
+ {proof_examples}
94
+ """
95
+ return enhanced_prompt
96
+
97
  def get_difficulty_parameters(difficulty_level):
98
  """Return specific parameters and constraints based on difficulty level"""
99
  parameters = {
 
351
  #- Use FiniteSet(1, 2, 3) instead of Set([1, 2, 3]) for finite sets
352
  #- Import specific functions instead of using 'from sympy import *'
353
  #- Print results of each calculation step
354
+
355
+ # Enhance the prompt with proof examples if applicable
356
+ if subject == "Real Analysis" and question_type == "proof":
357
+ system_prompt = enhance_prompt_with_proofs(system_prompt, subject, selected_topic)
358
+
359
  logger.debug("Sending request to Anthropic API")
360
  message = anthropic.messages.create(
361
  model=difficulty_params['model'],