File size: 1,200 Bytes
09da5e5
 
 
9ab5ec4
09da5e5
9ab5ec4
 
9b5b26a
9ab5ec4
9b5b26a
d544a6e
 
9b5b26a
d544a6e
9b5b26a
d544a6e
ae7a494
9ab5ec4
e121372
d544a6e
 
 
 
13d500a
8c01ffb
9ab5ec4
861422e
 
d544a6e
9ab5ec4
 
8fe992b
d544a6e
8c01ffb
 
 
 
d544a6e
 
861422e
8fe992b
 
9ab5ec4
 
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
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
import yaml
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI

# Import the DuckDuckGo search tool
search_tool = DuckDuckGoSearchTool(max_results=5)

# Custom summarization tool
@tool
def extract_summary_from_text(text: str) -> str:
    """Extracts a short summary from the given text.
    Args:
        text: The input text to summarize.
    """
    return text[:300] + "..." if len(text) > 300 else text

# Hugging Face API model
model = HfApiModel(
    max_tokens=2096,
    temperature=0.5,
    model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
    custom_role_conversions=None,
)

# Load prompt templates
with open("prompts.yaml", 'r') as stream:
    prompt_templates = yaml.safe_load(stream)

# ✅ Use CodeAgent instead of WebAgent
agent = CodeAgent(
    model=model,
    tools=[search_tool, extract_summary_from_text, FinalAnswerTool()],  # Add tools
    max_steps=6,
    verbosity_level=1,
    grammar=None,
    planning_interval=None,
    name="WebAgent",
    description="A web-searching AI agent",
    prompt_templates=prompt_templates
)

# Launch Gradio UI
GradioUI(agent).launch()