Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -169,7 +169,7 @@ def find_relevant_theorems(query):
|
|
| 169 |
similarity = util.pytorch_cos_sim(query_embedding, theorem_embedding).item()
|
| 170 |
print(f"Similarity with {theorem['name']}: {similarity}") # Debugging
|
| 171 |
|
| 172 |
-
if similarity > 0.
|
| 173 |
relevant_theorems.append((theorem, similarity))
|
| 174 |
# Sort the theorems by similarity
|
| 175 |
relevant_theorems.sort(key=lambda x: x[1], reverse=True)
|
|
@@ -197,29 +197,6 @@ def solve_problem_with_gpt(query, theorems_used):
|
|
| 197 |
return f"Error: {str(e)}" # Return error message
|
| 198 |
|
| 199 |
|
| 200 |
-
# Function to validate the solution using GPT
|
| 201 |
-
'''
|
| 202 |
-
def validate_solution_with_gpt(result, query, theorems_used):
|
| 203 |
-
# Create a prompt for GPT to validate the result
|
| 204 |
-
prompt = f"Using the following theorems: {theorems_used}, check if the solution to the problem '{query}' is correct. The result is {result}. Is this correct?"
|
| 205 |
-
|
| 206 |
-
try:
|
| 207 |
-
# Use the updated API structure
|
| 208 |
-
response = client.chat.completions.create(
|
| 209 |
-
model="gpt-4", # Or use another model like "gpt-3.5-turbo"
|
| 210 |
-
messages=[
|
| 211 |
-
{"role": "system", "content": "You are a mathematical assistant that validates solutions to problems using provided theorems."},
|
| 212 |
-
{"role": "user", "content": prompt}
|
| 213 |
-
],
|
| 214 |
-
)
|
| 215 |
-
|
| 216 |
-
validation_feedback = response.choices[0].message.content
|
| 217 |
-
return True, validation_feedback # Validation success and feedback
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
except Exception as e:
|
| 221 |
-
return False, f"Error: {str(e)}" # Return False in case of errors
|
| 222 |
-
'''
|
| 223 |
def validate_solution_with_gpt(solution, query, relevant_theorems):
|
| 224 |
"""
|
| 225 |
Validate the solution using GPT by asking if the solution is consistent with the given theorems.
|
|
|
|
| 169 |
similarity = util.pytorch_cos_sim(query_embedding, theorem_embedding).item()
|
| 170 |
print(f"Similarity with {theorem['name']}: {similarity}") # Debugging
|
| 171 |
|
| 172 |
+
if similarity > 0.35: # A threshold to consider multiple relevant theorems
|
| 173 |
relevant_theorems.append((theorem, similarity))
|
| 174 |
# Sort the theorems by similarity
|
| 175 |
relevant_theorems.sort(key=lambda x: x[1], reverse=True)
|
|
|
|
| 197 |
return f"Error: {str(e)}" # Return error message
|
| 198 |
|
| 199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
def validate_solution_with_gpt(solution, query, relevant_theorems):
|
| 201 |
"""
|
| 202 |
Validate the solution using GPT by asking if the solution is consistent with the given theorems.
|