JoshAbrahams21 commited on
Commit
c0dc740
·
verified ·
1 Parent(s): c7b94d2

Update backend.py

Browse files
Files changed (1) hide show
  1. backend.py +11 -9
backend.py CHANGED
@@ -16,26 +16,28 @@ def extract_final_answer(text):
16
  if not text:
17
  return None
18
 
19
- # ✅ Try to match LaTeX-style answers wrapped in $$...$$
20
- match_dollars = re.search(r'final answer[:\-]?\s*\$\$(.+?)\$\$', text, re.IGNORECASE)
 
 
 
 
 
 
21
  if match_dollars:
22
  return match_dollars.group(1).strip()
23
 
24
- # ✅ Try to match LaTeX-style answers wrapped in $...$
25
- match_dollar = re.search(r'final answer[:\-]?\s*\$(.+?)\$', text, re.IGNORECASE)
26
  if match_dollar:
27
  return match_dollar.group(1).strip()
28
 
29
- # ✅ Fallback: match plain text final answer line
30
- match_plain = re.search(r'final answer[:\-]?\s*(.+)', text, re.IGNORECASE)
31
- if match_plain:
32
- return match_plain.group(1).strip()
33
-
34
  # ✅ Final fallback: return last number
35
  fallback = re.findall(r'\b\d+\.?\d*\b', text)
36
  return fallback[-1].strip() if fallback else None
37
 
38
 
 
39
  # Claude API call function
40
  def call_claude(prompt):
41
  headers = {
 
16
  if not text:
17
  return None
18
 
19
+ # ✅ Match full final answer line first (for things like: Final Answer: $x = 3$ or $x = 2$)
20
+ match_full = re.search(r'final answer[:\-]?\s*(.*)', text, re.IGNORECASE)
21
+ if match_full:
22
+ answer = match_full.group(1).strip()
23
+ if answer: return answer
24
+
25
+ # ✅ Match LaTeX-style $$...$$ if used alone
26
+ match_dollars = re.search(r'\$\$(.+?)\$\$', text)
27
  if match_dollars:
28
  return match_dollars.group(1).strip()
29
 
30
+ # ✅ Match LaTeX-style $...$ if used alone
31
+ match_dollar = re.search(r'\$(.+?)\$', text)
32
  if match_dollar:
33
  return match_dollar.group(1).strip()
34
 
 
 
 
 
 
35
  # ✅ Final fallback: return last number
36
  fallback = re.findall(r'\b\d+\.?\d*\b', text)
37
  return fallback[-1].strip() if fallback else None
38
 
39
 
40
+
41
  # Claude API call function
42
  def call_claude(prompt):
43
  headers = {