Spaces:
Sleeping
Sleeping
File size: 1,982 Bytes
91ed61f a4fc0e3 91ed61f cb91cc3 9a4e876 ac2d3eb 9a4e876 ac2d3eb 4287ca7 ac2d3eb a6e0d09 ac2d3eb a6e0d09 9a4e876 91ed61f 745281b ec0eab0 745281b a4fc0e3 745281b c7726e4 745281b 40f7c1a 745281b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
from smolagents import LiteLLMModel
from src.settings import Settings
from src.utils import InputTokenRateLimiter
from smolagents.tools import Tool
from litellm import completion
import os
import re
settings = Settings()
print(settings.llm_model_id)
class FinalAnswerTool(Tool):
name = "final_answer"
description = """
Takes the agent's computed result and formats the final answer.
If the question asks for time rounded to the nearest *thousand hours*,
you MUST:
1. First compute total time in hours.
2. THEN divide by FINAL ANSWER BY 1000 to convert to 'thousands of hours'.
3. Round that result to the nearest integer.
4. Output ONLY that integer (e.g., 17),
Always output a clean string with ONLY the final answer.
STRICT RULES:
- Do NOT use Markdown formatting.
- Do NOT use bold formatting.
- Do NOT surround the answer with **asterisks**.
- Do NOT add explanations, units, or extra words.
- If the answer is a number, output ONLY the number (e.g., 17000).
- Output must be plain ASCII text, no special symbols.
"""
inputs = {
"answer": {"type": "string", "description": "The final, correctly formatted answer string."}
}
output_type = "string"
def forward(self, answer: str) -> str:
if not answer or str(answer).strip() == "":
return "I am unable to answer" # Fallback string for submission
answer = str(answer).strip()
match = re.search(r'boxed\{([^}]+)\}', answer)
if match:
answer = match.group(1)
# Remove LaTeX symbols and keep letters, digits, commas
answer = re.sub(r'[\$\{\}\\]', '', answer)
answer = re.sub(r'[^A-Za-z0-9,\.\-\+/ ]', ' ', answer)
answer = " ".join(answer.split()) # Remove extra spaces
if not answer:
return "I am unable to answer"
return answer |