rtc-voice-chat/backend/tools/builtin/weather.py
2026-04-02 09:40:23 +08:00

24 lines
636 B
Python

import httpx
from tools.registry import tool_registry
@tool_registry.register(
name="query_weather",
description="查询指定城市的实时天气信息",
parameters={
"type": "object",
"properties": {
"city": {"type": "string", "description": "城市名称,如:北京、上海"},
},
"required": ["city"],
},
)
def query_weather(city: str) -> str:
try:
resp = httpx.get(f"https://wttr.in/{city}?format=3", timeout=3)
resp.raise_for_status()
return resp.text.strip()
except Exception as exc:
return f"天气查询失败:{exc}"