File size: 1,435 Bytes
9b5b26a
 
c19d193
1d6da9a
f604625
9b5b26a
 
1d6da9a
 
ae7a494
b4eb62c
f604625
ae7a494
b4eb62c
e121372
1d6da9a
f604625
b279bcb
f604625
13d500a
8c01ffb
b4eb62c
9b5b26a
8c01ffb
b4eb62c
861422e
 
9b5b26a
1d6da9a
8c01ffb
8fe992b
1d6da9a
 
8c01ffb
 
 
1d6da9a
 
861422e
8fe992b
 
f604625
 
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
import datetime
import pytz
import yaml
from smolagents import CodeAgent, HfApiModel, load_tool, tool, DuckDuckGoSearchTool
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI

# Instantiate the DuckDuckGo search tool provided by smolagents.
duckduckgo_tool = DuckDuckGoSearchTool()

# Final answer tool (must be included)
final_answer = FinalAnswerTool()

# Define the model configuration.
model = HfApiModel(
    max_tokens=1000,  # Reduced max_tokens to help prevent token limit issues.
    temperature=0.5,
    model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
    custom_role_conversions=None,
)

# Optionally, load an additional tool from the Hub (e.g., a text-to-image tool)
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)

# Load prompt templates from YAML.
with open("prompts.yaml", 'r') as stream:
    prompt_templates = yaml.safe_load(stream)
    
# Initialize the CodeAgent with the DuckDuckGo search tool.
agent = CodeAgent(
    model=model,
    tools=[final_answer, duckduckgo_tool],
    max_steps=3,  # Reduced steps to limit the chain-of-thought length.
    verbosity_level=1,
    grammar=None,
    planning_interval=None,
    name="SearchAgent",
    description="An AI agent that uses DuckDuckGo search to fetch information from the web.",
    prompt_templates=prompt_templates
)

# Launch the Gradio UI to interact with the agent.
GradioUI(agent).launch()