ankitsethia1397's picture
update2
3bce71b verified
Raw
History Blame Contribute Delete
1.51 kB
import os
import re
from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel
# =========================================================
# MODEL (FREE GROQ API)
# =========================================================
model = OpenAIServerModel(
model_id="llama3-70b-8192",
api_base="https://api.groq.com/openai/v1",
api_key=os.getenv("GROQ_API_KEY")
)
# =========================================================
# TOOLS
# =========================================================
search_tool = DuckDuckGoSearchTool()
agent = CodeAgent(
tools=[search_tool],
model=model,
max_steps=4,
verbosity_level=1
)
# =========================================================
# CLEAN OUTPUT
# =========================================================
def clean_output(text):
if text is None:
return ""
text = str(text).strip()
text = re.sub(r"^```.*?\n", "", text, flags=re.DOTALL)
text = re.sub(r"```$", "", text)
return text.strip()
# =========================================================
# MAIN SOLVER FUNCTION
# =========================================================
def answer_question(question: str) -> str:
prompt = f"""
You are solving a GAIA benchmark task.
Question:
{question}
IMPORTANT:
- Return ONLY the final answer
- No explanation
- No markdown
- No extra words
"""
try:
result = agent.run(prompt)
return clean_output(result)
except Exception as e:
return f"ERROR: {str(e)}"