File size: 2,077 Bytes
5d9a943
 
9b5b26a
 
8fe992b
f7e00bd
 
 
 
 
 
 
5d9a943
9b5b26a
 
4d64b6a
436590b
 
 
 
5d9a943
4d64b6a
9b5b26a
5d9a943
f7e00bd
4d64b6a
3c6b4da
9b5b26a
d6481e4
 
3c6b4da
 
4d64b6a
9b5b26a
5d9a943
9b5b26a
 
 
f7e00bd
4d64b6a
3c6b4da
 
4d64b6a
3c6b4da
 
4d64b6a
3c6b4da
9b5b26a
 
d6481e4
 
9b5b26a
4d64b6a
8c01ffb
6aae614
5d9a943
4d64b6a
436590b
5d9a943
b91f349
 
4d64b6a
 
13d500a
8c01ffb
4d64b6a
d6481e4
 
5d9a943
4d64b6a
8c01ffb
8fe992b
5d9a943
 
 
 
d6481e4
 
5d9a943
8c01ffb
 
4d64b6a
8fe992b
 
4d64b6a
5d9a943
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import os
from huggingface_hub import login
import datetime
import pytz

from smolagents import (
    CodeAgent,
    DuckDuckGoSearchTool,
    InferenceClientModel,
    load_tool,
    tool
)
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI

# 1) Authenticate with your HF token
hf_token = os.getenv("HF_HUB_TOKEN")
if not hf_token:
    raise RuntimeError("HF_HUB_TOKEN env var not set")
login(hf_token)

# 2) Define tools with compliant docstrings
@tool
def my_custom_tool(arg1: str, arg2: int) -> str:
    """
    Placeholder tool.

    Args:
        arg1: A sample string.
        arg2: A sample integer.

    Returns:
        A placeholder response.
    """
    return "What magic will you build?"

@tool
def get_current_time_in_timezone(timezone: str) -> str:
    """
    Fetch the current time in a specified timezone.

    Args:
        timezone: A tz database name (e.g., 'Europe/Paris').

    Returns:
        Local time as 'YYYY-MM-DD HH:MM:SS', or an error message.
    """
    try:
        tz = pytz.timezone(timezone)
        now = datetime.datetime.now(tz)
        return now.strftime("The current local time in %Z (%z) is %Y-%m-%d %H:%M:%S")
    except Exception as e:
        return f"Error fetching time: {e}"

final_answer = FinalAnswerTool()

# 3) Load the model WITHOUT an unsupported provider override
model = InferenceClientModel(
    model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
    max_tokens=2096,
    temperature=0.5,
    api_key=hf_token             # ensure your token is passed here
    # provider omitted to use default "auto"
)

# 4) Load built-in tools
image_gen = load_tool("agents-course/text-to-image", trust_remote_code=True)
web_search = DuckDuckGoSearchTool()

# 5) Instantiate CodeAgent using default prompt templates
agent = CodeAgent(
    model=model,
    tools=[
        final_answer,
        my_custom_tool,
        get_current_time_in_timezone,
        image_gen,
        web_search,
    ],
    max_steps=6,
    verbosity_level=1,
    add_base_tools=False
)

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