Routes LLM requests to a local model (Ollama, LM Studio, llamafile) before falling back to cloud APIs. Tracks token savings and cost avoidance in a persistent dashboard. Use when: (1) user asks to run a task with a local model first, (2) user wants to reduce cloud API costs or keep requests private, (3) user asks to see their token savings or LLM routing dashboard, (4) any request where local-vs-cloud routing should be decided automatically. Supports Ollama, LM Studio, and llamafile as local pro
优先将请求路由到本地大语言模型;仅在必要时回退到云端。追踪每一个决策,展示真实的令牌和成本节省。
bash
python3 skills/local-first-llm/scripts/check_local.py
返回 JSON:{ any_available: true, best: { provider: ollama, models: [...] } }
bash
python3 skills/local-first-llm/scripts/route_request.py \
--prompt 总结这份会议记录 \
--tokens 800 \
--local-available \
--local-provider ollama
返回:{ decision: local, reason: ..., complexity_score: -1 }
执行请求后,进行记录:
bash
python3 skills/local-first-llm/scripts/track_savings.py log \
--tokens 800 \
--model gpt-4o \
--routed-to local
bash
python3 skills/local-first-llm/scripts/dashboard.py
┌─────────────────────────────────────────────────────┐
│ 1. check_local.py → 本地提供商是否在运行? │
│ │
│ 2. route_request.py → 本地还是云端? │
│ - 敏感度检查 (私有数据 → 本地) │
│ - 复杂度评分 (高分 → 云端) │
│ - 可用性检查 (无本地 → 云端) │
│ │
│ 3. 使用选定的提供商执行 │
│ │
│ 4. track_savings.py log → 记录结果 │
│ │
│ 5. dashboard.py → 显示累计节省 │
└─────────────────────────────────────────────────────┘
| 条件 | 路由 |
|---|---|
| 无可用本地提供商 | ☁️ 云端 |
| 提示词包含敏感数据(密码、密钥、API 密钥、社会安全号码 等) |
完整评分详情请参见 references/routing-logic.md。
当 route_request.py 返回 decision: local 时,发送请求:
bash
curl http://localhost:11434/api/generate \
-d {model: llama3.2, prompt: 你的提示词, stream: false}
bash
curl http://localhost:1234/v1/chat/completions \
-H Content-Type: application/json \
-d {model: local-model, messages: [{role: user, content: 你的提示词}]}
仪表盘读取 ~/.openclaw/local-first-llm/savings.json(自动创建)。
┌─────────────────────────────────────────┐
│ 🧠 本地优先大语言模型 — 仪表盘 │
├─────────────────────────────────────────┤
│ 本地大语言模型: ✅ ollama (llama3.2...)│
├─────────────────────────────────────────┤
│ 总请求数: 42 │
│ 路由到本地: 31 (73.8%) │
│ 路由到云端: 11 │
├─────────────────────────────────────────┤
│ 节省令牌: 84,200 │
│ 节省成本: $0.4210 │
└─────────────────────────────────────────┘
重置节省数据:
bash
python3 skills/local-first-llm/scripts/track_savings.py reset
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 local-first-llm-1776307868 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 local-first-llm-1776307868 技能
skillhub install local-first-llm-1776307868
文件大小: 10.17 KB | 发布时间: 2026-4-16 18:45