Tonic commited on
Commit
03948e3
Β·
verified Β·
1 Parent(s): e7d74c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -15,9 +15,38 @@ def format_prompt(formal_statement, informal_prefix=""):
15
  return f"Complete the following Lean 4 code with explanatory comments preceding each line of code:\n\n```lean4\n{LEAN4_DEFAULT_HEADER}{informal_prefix}{formal_statement}"
16
 
17
  def extract_code(response):
18
- """Extract code between lean4 code blocks"""
19
  try:
20
- return re.search(r'```lean4\n(.*?)\n```', response, re.DOTALL).group(1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  except:
22
  return "None"
23
 
 
15
  return f"Complete the following Lean 4 code with explanatory comments preceding each line of code:\n\n```lean4\n{LEAN4_DEFAULT_HEADER}{informal_prefix}{formal_statement}"
16
 
17
  def extract_code(response):
18
+ """Extract code between lean4 code blocks and the model's output"""
19
  try:
20
+ # Extract the model's theorem and proof
21
+ output_match = re.search(r'theorem.*?end\s*```', response, re.DOTALL)
22
+ if output_match:
23
+ model_output = output_match.group(0)
24
+ else:
25
+ model_output = ""
26
+
27
+ # Extract the initial code setup
28
+ setup_match = re.search(r'```lean4\n(.*?)============================', response, re.DOTALL)
29
+ if setup_match:
30
+ setup_code = setup_match.group(1)
31
+ else:
32
+ return "None"
33
+
34
+ # Extract the goal
35
+ goal_match = re.search(r'============================\n\s*(.*?)(?:theorem|$)', response, re.DOTALL)
36
+ if goal_match:
37
+ goal = goal_match.group(1).strip()
38
+ else:
39
+ goal = ""
40
+
41
+ # Combine all parts
42
+ full_code = (
43
+ f"{setup_code.strip()}\n"
44
+ f"============================\n"
45
+ f"{goal}\n\n"
46
+ f"{model_output.strip()}"
47
+ )
48
+
49
+ return full_code
50
  except:
51
  return "None"
52