Spaces:
Sleeping
Sleeping
Update tools/FinalAnswerTool.py
Browse files- tools/FinalAnswerTool.py +6 -3
tools/FinalAnswerTool.py
CHANGED
|
@@ -4,22 +4,25 @@ from src.utils import InputTokenRateLimiter
|
|
| 4 |
from smolagents.tools import Tool
|
| 5 |
from litellm import completion
|
| 6 |
import os
|
|
|
|
| 7 |
|
| 8 |
settings = Settings()
|
| 9 |
print(settings.llm_model_id)
|
| 10 |
class FinalAnswerTool(Tool):
|
| 11 |
name = "final_answer"
|
| 12 |
-
description = "Provides the exact, final answer to the given question."
|
| 13 |
inputs = {
|
| 14 |
"answer": {"type": "string", "description": "The final, correctly formatted answer string."},
|
| 15 |
}
|
| 16 |
output_type = "string"
|
| 17 |
|
| 18 |
def forward(self, answer: str) -> str:
|
| 19 |
-
|
|
|
|
|
|
|
| 20 |
answer = re.sub(r'[\$\{\}\\]', '', answer) # Remove other LaTeX symbols
|
| 21 |
answer = re.sub(r'[^A-Za-z0-9,]', ' ', answer) # Keep letters, digits, commas
|
| 22 |
if not answer:
|
| 23 |
return "NA"
|
| 24 |
-
final_answer = f"
|
| 25 |
return final_answer
|
|
|
|
| 4 |
from smolagents.tools import Tool
|
| 5 |
from litellm import completion
|
| 6 |
import os
|
| 7 |
+
import re
|
| 8 |
|
| 9 |
settings = Settings()
|
| 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 |
+
match = re.search(r'boxed\{([^}]+)\}', answer)
|
| 21 |
+
if match:
|
| 22 |
+
answer = match.group(1)
|
| 23 |
answer = re.sub(r'[\$\{\}\\]', '', answer) # Remove other LaTeX symbols
|
| 24 |
answer = re.sub(r'[^A-Za-z0-9,]', ' ', answer) # Keep letters, digits, commas
|
| 25 |
if not answer:
|
| 26 |
return "NA"
|
| 27 |
+
final_answer = f"{str(answer)}"
|
| 28 |
return final_answer
|