Spaces:
Sleeping
Sleeping
Update tools/FinalAnswerTool.py
Browse files- tools/FinalAnswerTool.py +12 -9
tools/FinalAnswerTool.py
CHANGED
|
@@ -10,23 +10,26 @@ settings = Settings()
|
|
| 10 |
print(settings.llm_model_id)
|
| 11 |
class FinalAnswerTool(Tool):
|
| 12 |
name = "final_answer"
|
| 13 |
-
description = "Provides the exact, few comma separated
|
| 14 |
inputs = {
|
| 15 |
"answer": {"type": "string", "description": "The final, correctly formatted answer string."},
|
| 16 |
}
|
| 17 |
output_type = "string"
|
| 18 |
|
| 19 |
def forward(self, answer: str) -> str:
|
| 20 |
-
if answer
|
| 21 |
-
return "
|
| 22 |
|
| 23 |
-
answer = str(answer)
|
| 24 |
match = re.search(r'boxed\{([^}]+)\}', answer)
|
| 25 |
if match:
|
| 26 |
answer = match.group(1)
|
| 27 |
-
|
| 28 |
-
answer = re.sub(r'[
|
|
|
|
|
|
|
|
|
|
| 29 |
if not answer:
|
| 30 |
-
return "
|
| 31 |
-
|
| 32 |
-
return
|
|
|
|
| 10 |
print(settings.llm_model_id)
|
| 11 |
class FinalAnswerTool(Tool):
|
| 12 |
name = "final_answer"
|
| 13 |
+
description = "Provides the exact, few comma separated words or a single final answer to the given question."
|
| 14 |
inputs = {
|
| 15 |
"answer": {"type": "string", "description": "The final, correctly formatted answer string."},
|
| 16 |
}
|
| 17 |
output_type = "string"
|
| 18 |
|
| 19 |
def forward(self, answer: str) -> str:
|
| 20 |
+
if not answer or str(answer).strip() == "":
|
| 21 |
+
return "I am unable to answer" # Fallback string for submission
|
| 22 |
|
| 23 |
+
answer = str(answer).strip()
|
| 24 |
match = re.search(r'boxed\{([^}]+)\}', answer)
|
| 25 |
if match:
|
| 26 |
answer = match.group(1)
|
| 27 |
+
# Remove LaTeX symbols and keep letters, digits, commas
|
| 28 |
+
answer = re.sub(r'[\$\{\}\\]', '', answer)
|
| 29 |
+
answer = re.sub(r'[^A-Za-z0-9,]', ' ', answer)
|
| 30 |
+
answer = " ".join(answer.split()) # Remove extra spaces
|
| 31 |
+
|
| 32 |
if not answer:
|
| 33 |
+
return "I am unable to answer"
|
| 34 |
+
|
| 35 |
+
return answer
|