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 = "Provides the exact, few comma separated words or a single final answer to the given question." inputs = { "answer": {"type": "string", "description": "The final, correctly formatted answer string."}, } output_type = "string" def forward(self, answer: str) -> str: match = re.search(r'boxed\{([^}]+)\}', answer) if match: answer = match.group(1) answer = re.sub(r'[\$\{\}\\]', '', answer) # Remove other LaTeX symbols answer = re.sub(r'[^A-Za-z0-9,]', ' ', answer) # Keep letters, digits, commas if not answer: return "NA" final_answer = f"{str(answer)}" return final_answer