一个界面照着豆包抠的 AI 助手。主力是安卓端,完全离线自主:不依赖电脑、 不需要另外装 Termux。 安卓端 - 原生 Jetpack Compose,7 个页面,配色/圆角/间距对着真机截图量出来的 - 完整动效:抽屉滑入、页面切换、气泡淡入上移、面板底部升起、typing 三点、按钮回弹 - 内置 Termux:bash/apt/pkg 388 个命令、真 pty 终端; pty 不可用的 ROM 上自动降级成命令控制台 - APK 内嵌 CPython 3.13(Chaquopy),AI 内核跑在手机上 - 设备能力:定位 / 陀螺仪 / 加速度计 / 光线 / 电量 / 剪贴板 - 语音:朗读 + 语音输入,火山豆包音色 / OpenAI 兼容 / 设备自带三级引擎 AI 能力 - 10 家 OpenAI 兼容提供商:方舟 / OpenAI / DeepSeek / Kimi / 智谱 / 通义 / 硅基流动 / OpenRouter / 本地 Ollama / 自定义 - 思考强度按各家支持情况发不同字段(thinking / reasoning_effort / 不发), 认不出来的一律不发,避免给不支持的厂商发字段直接 400 - MCP 三种传输(http / stdio / inproc)、工具热加载、文件上传、权限模式 跨端 - 安卓走原生 Compose,Web / Windows 走 Lynx - Node 与 Python 两份内核接口逐字段一致,关键路径都有对拍脚本 自检脚本(都不需要真 Key) - verify-phone.mjs 设备端 24 项验收 - verify-speech.mjs 语音链路 31 项,两份内核各跑一遍 - parity-thinking.mjs 思考强度映射对拍 - probe-settings-wipe.mjs 设置防清空攻击测试 - mock-llm.mjs 假的 OpenAI + 火山语音服务 许可 MIT;第三方组件(Termux Apache-2.0、Chaquopy、Compose、LynxJS、Electron) 的授权见 LICENSE。
113 lines
3.5 KiB
Python
113 lines
3.5 KiB
Python
"""天气工具:用 open-meteo 免费接口(无需 API Key)。"""
|
||
|
||
import json
|
||
import os
|
||
import sys
|
||
import urllib.parse
|
||
import urllib.request
|
||
|
||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||
from _protocol import serve # noqa: E402
|
||
|
||
TOOL = {
|
||
"name": "get_weather",
|
||
"description": "查询指定城市的当前天气与未来三天预报(open-meteo,无需密钥)。",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"city": {"type": "string", "description": "城市名,例如 宁波、北京、Tokyo"},
|
||
"days": {"type": "number", "description": "预报天数 1-7,默认 3"},
|
||
},
|
||
"required": ["city"],
|
||
},
|
||
}
|
||
|
||
GEO_URL = "https://geocoding-api.open-meteo.com/v1/search"
|
||
FORECAST_URL = "https://api.open-meteo.com/v1/forecast"
|
||
|
||
WEATHER_CODE = {
|
||
0: "晴",
|
||
1: "多云转晴",
|
||
2: "多云",
|
||
3: "阴",
|
||
45: "雾",
|
||
48: "冻雾",
|
||
51: "小毛毛雨",
|
||
53: "毛毛雨",
|
||
55: "大毛毛雨",
|
||
61: "小雨",
|
||
63: "中雨",
|
||
65: "大雨",
|
||
71: "小雪",
|
||
73: "中雪",
|
||
75: "大雪",
|
||
80: "阵雨",
|
||
81: "强阵雨",
|
||
82: "暴雨",
|
||
95: "雷阵雨",
|
||
96: "雷阵雨伴冰雹",
|
||
99: "强雷暴伴冰雹",
|
||
}
|
||
|
||
|
||
def http_json(url, params, timeout=15):
|
||
full = f"{url}?{urllib.parse.urlencode(params)}"
|
||
req = urllib.request.Request(full, headers={"User-Agent": "doubao-kernel/0.1"})
|
||
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||
return json.loads(resp.read().decode("utf-8"))
|
||
|
||
|
||
def run(args):
|
||
city = str(args.get("city", "")).strip()
|
||
if not city:
|
||
raise ValueError("city 不能为空")
|
||
days = max(1, min(7, int(args.get("days", 3) or 3)))
|
||
|
||
geo = http_json(GEO_URL, {"name": city, "count": 1, "language": "zh", "format": "json"})
|
||
results = geo.get("results") or []
|
||
if not results:
|
||
return {"ok": False, "error": f"找不到城市 {city}"}
|
||
place = results[0]
|
||
|
||
forecast = http_json(
|
||
FORECAST_URL,
|
||
{
|
||
"latitude": place["latitude"],
|
||
"longitude": place["longitude"],
|
||
"current": "temperature_2m,relative_humidity_2m,wind_speed_10m,weather_code",
|
||
"daily": "weather_code,temperature_2m_max,temperature_2m_min,precipitation_probability_max",
|
||
"timezone": "auto",
|
||
"forecast_days": days,
|
||
},
|
||
)
|
||
|
||
current = forecast.get("current", {})
|
||
daily = forecast.get("daily", {})
|
||
return {
|
||
"city": place.get("name"),
|
||
"admin": place.get("admin1"),
|
||
"country": place.get("country"),
|
||
"current": {
|
||
"temperature": current.get("temperature_2m"),
|
||
"humidity": current.get("relative_humidity_2m"),
|
||
"wind": current.get("wind_speed_10m"),
|
||
"weather": WEATHER_CODE.get(current.get("weather_code"), current.get("weather_code")),
|
||
"time": current.get("time"),
|
||
},
|
||
"forecast": [
|
||
{
|
||
"date": daily.get("time", [])[i],
|
||
"weather": WEATHER_CODE.get(daily.get("weather_code", [])[i], daily.get("weather_code", [])[i]),
|
||
"high": daily.get("temperature_2m_max", [])[i],
|
||
"low": daily.get("temperature_2m_min", [])[i],
|
||
"rain_probability": daily.get("precipitation_probability_max", [])[i],
|
||
}
|
||
for i in range(len(daily.get("time", [])))
|
||
],
|
||
"source": "open-meteo.com",
|
||
}
|
||
|
||
|
||
if __name__ == "__main__":
|
||
serve(TOOL, run)
|