davidtalmaciu's picture
Update app.py
eae0c09 verified
from smolagents import CodeAgent, HfApiModel, tool
import yaml
import random
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI
# Tool: tell a random joke (no arguments)
@tool
def tell_joke() -> str:
"""A tool that tells a random joke.
Returns:
A funny one-liner from a predefined list.
"""
jokes = [
"Why don't scientists trust atoms? Because they make up everything!",
"Why was the math book sad? Because it had too many problems.",
"Why did the scarecrow win an award? Because he was outstanding in his field!",
"Why did the tomato turn red? Because it saw the salad dressing!",
"Why did the computer get cold? Because it forgot to close its windows."
]
return random.choice(jokes)
# Final answer tool
final_answer = FinalAnswerTool()
# Model
model = HfApiModel(
max_tokens=1024,
temperature=0.7,
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
)
# Load system prompt
with open("prompts.yaml", 'r') as stream:
prompt_templates = yaml.safe_load(stream)
# Create agent
agent = CodeAgent(
model=model,
tools=[final_answer, tell_joke],
max_steps=4,
verbosity_level=1,
prompt_templates=prompt_templates
)
# Launch UI
GradioUI(agent).launch()