File size: 1,121 Bytes
636244e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9c8e39
636244e
 
 
 
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
import datetime
import pytz
import os
from smolagents import CodeAgent, InferenceClientModel, tool, GradioUI

# --- ツール定義 ---
@tool
def get_current_time_in_timezone(timezone: str) -> str:
    """A tool that fetches the current local time in a specified timezone.
    Args:
        timezone: A string representing a valid timezone (e.g., 'America/New_York').
    """
    try:
        tz = pytz.timezone(timezone)
        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
        return f"The current local time in {timezone} is: {local_time}"
    except Exception as e:
        return f"Error fetching time for timezone '{timezone}': {str(e)}"

# --- モデル設定 ---
# Space上ではHF_TOKENが自動で読み込まれます
model = InferenceClientModel(
    model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
    token=os.environ.get("HF_TOKEN")
)

# --- エージェント作成 ---
agent = CodeAgent(
    tools=[get_current_time_in_timezone], 
    model=model,
    add_base_tools=False # ← False に変える(検索機能をオフにする)
)

# --- UI起動 ---
GradioUI(agent).launch()