Spaces:
Runtime error
Runtime error
| import datetime | |
| import pytz | |
| import os | |
| from smolagents import CodeAgent, InferenceClientModel, tool, GradioUI | |
| # --- ツール定義 --- | |
| 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() |