Spaces:
Build error
Build error
File size: 1,648 Bytes
d3c02bc bb2f929 36ac503 b90777b f10d5f8 36ac503 f10d5f8 36ac503 f10d5f8 36ac503 f10d5f8 36ac503 f10d5f8 36ac503 f10d5f8 b4936e8 |
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
from smolagents import tool
import os
# Initialize model
model = InferenceClientModel(model_id="Qwen/Qwen2.5-72B-Instruct", token = os.environ.get("HF_TOKEN"))
# Custom tools with corrected docstrings
@tool
def add(a: int, b: int) -> int:
"""Add two numbers.
Args:
a: The first number to add
b: The second number to add
"""
return a + b
@tool
def multiply(a: int, b: int) -> int:
"""Multiply two numbers.
Args:
a: The first number to multiply
b: The second number to multiply
"""
return a * b
@tool
def subtract(a: int, b: int) -> int:
"""Subtract two numbers.
Args:
a: The number to subtract from
b: The number to subtract
"""
return a - b
@tool
def divide(a: int, b: int) -> int:
"""Divide two numbers.
Args:
a: The number to divide
b: The divisor
"""
if b == 0:
raise ValueError("Cannot divide by zero.")
return a / b
@tool
def modulus(a: int, b: int) -> int:
"""Get the modulus of two numbers.
Args:
a: The number to get modulus of
b: The modulus divisor
"""
return a % b
# Create agent with tools
agent = CodeAgent(
tools=[DuckDuckGoSearchTool(), add, multiply, subtract, divide, modulus],
model=model,
)
def answer_question(question: str) -> str:
result = agent.run(question)
# Ensure output starts with "FINAL ANSWER:"
if not result.strip().startswith("FINAL ANSWER:"):
result = f"FINAL ANSWER: {result.strip()}"
return result
|