j-js commited on
Commit
18361f1
·
verified ·
1 Parent(s): 856c390

Update generate_question_support.py

Browse files
Files changed (1) hide show
  1. generate_question_support.py +36 -9
generate_question_support.py CHANGED
@@ -62,26 +62,53 @@ def percent_template(q, nums):
62
 
63
 
64
  def algebra_template(q, nums):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  return {
66
- "first_step": "Write the equation clearly and identify the variable.",
67
- "hint_1": f"Look at the structure: {q['questionText'][:50]}...",
68
  "hint_2": "Undo operations in reverse order.",
69
- "hint_3": "Keep both sides balanced while isolating the variable.",
70
  "walkthrough_steps": [
71
- "Identify the equation.",
72
  "Move constants to one side.",
73
  "Undo multiplication/division.",
74
- "Solve for the variable."
75
  ],
76
  "method_explanation": [
77
- "Solve by isolating the variable step by step.",
78
- "Reverse operations carefully.",
79
- "Check your result by substitution."
80
  ],
81
  "common_trap": "Forgetting to apply operations to both sides."
82
  }
83
 
84
-
85
  def ratio_template(q, nums):
86
  return {
87
  "first_step": "Break the ratio into total parts.",
 
62
 
63
 
64
  def algebra_template(q, nums):
65
+ text = q["questionText"]
66
+
67
+ # Try to extract equation
68
+ match = re.search(r"([^\?]+)=([^\?]+)", text)
69
+
70
+ if match:
71
+ lhs = match.group(1).strip()
72
+ rhs = match.group(2).strip()
73
+
74
+ return {
75
+ "first_step": f"Start with the equation: {lhs} = {rhs}",
76
+ "hint_1": "Focus on isolating the variable.",
77
+ "hint_2": "Undo addition/subtraction first.",
78
+ "hint_3": "Then undo multiplication/division.",
79
+ "walkthrough_steps": [
80
+ f"Start with: {lhs} = {rhs}",
81
+ "Move constants to one side.",
82
+ "Undo multiplication/division.",
83
+ "Solve for the variable."
84
+ ],
85
+ "method_explanation": [
86
+ "Solve by isolating the variable.",
87
+ "Reverse operations step by step.",
88
+ "Keep both sides balanced."
89
+ ],
90
+ "common_trap": "Forgetting to reverse operations in the correct order."
91
+ }
92
+
93
+ # fallback if parsing fails
94
  return {
95
+ "first_step": "Identify the variable and isolate it step by step.",
96
+ "hint_1": "Look at what operations are applied to the variable.",
97
  "hint_2": "Undo operations in reverse order.",
98
+ "hint_3": "Keep both sides balanced while simplifying.",
99
  "walkthrough_steps": [
100
+ "Identify the variable.",
101
  "Move constants to one side.",
102
  "Undo multiplication/division.",
103
+ "Simplify to isolate the variable."
104
  ],
105
  "method_explanation": [
106
+ "Algebra problems require isolating the variable.",
107
+ "Reverse operations systematically."
 
108
  ],
109
  "common_trap": "Forgetting to apply operations to both sides."
110
  }
111
 
 
112
  def ratio_template(q, nums):
113
  return {
114
  "first_step": "Break the ratio into total parts.",