闲社服务运行正常AI智能体自动化平台
s

语义模型路由

技能标识:semantic-model-router

Smart LLM Router — routes every query to the cheapest capable model. Supports 17 models across Anthropic, OpenAI, Google, DeepSeek & xAI (Grok). Uses a pre-trained ML classifier. No extra API keys required.

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.3
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

语义模型路由

语义模型路由器

智能LLM路由器,通过将每个请求路由到能够处理该请求的最便宜模型,可节省高达99%的推理成本。由预训练的机器学习分类器和语义嵌入驱动——无需外部调用,无需API密钥。

安装

bash
openclaw plugins install @rayray1218/semantic-model-router

快速开始

python
from scripts.model_router import ModelRouter

router = ModelRouter()
res = router.route(为金融科技平台设计一个分布式缓存层。)
print(res[report])

[ClawRouter] anthropic/claude-sonnet-4-6 (ELITE, ml, conf=0.97)


成本: $3.0/M | 基准: $10.0/M | 节省: 70.0%

路由工作原理

查询通过3阶段流水线分为三个层级:

  1. 1. 机器学习分类器(主要):基于6000+标注查询训练的Logistic回归模型。从model_weights.py中的嵌入式权重运行,耗时<1ms。
  2. 语义嵌入(备用):通过sentence-transformers计算与层级意图向量的余弦相似度。
  3. 关键词规则(最后手段):无依赖的模式匹配。
层级默认模型典型工作负载成本/1M与基准对比
基础deepseek/deepseek-chat问候、简单问答、闲聊$0.14节省99%
均衡
openai/gpt-4o-mini | 摘要、翻译、解释 | $0.15 | 节省99% | | 精英 | anthropic/claude-sonnet-4-6 | 复杂编码、架构、安全 | $3.00 | 节省70% |

支持的模型(共17个,2026年2月验证)

Anthropic
模型输入/1M输出/1M
anthropic/claude-sonnet-4-6$3.00$15.00 ★ 精英默认
anthropic/claude-opus-4-5
$5.00 | $25.00 |

| anthropic/claude-haiku-4-5 | $0.80 | $4.00 |

OpenAI
模型输入/1M输出/1M
openai/gpt-5$1.25$10.00
openai/gpt-4o
$2.50 | $10.00 |

| openai/gpt-4o-mini | $0.15 | $0.60 ★ 均衡默认 | | openai/o3 | $2.00 | $8.00 | | openai/o4-mini | $1.10 | $4.40 |

Google
模型输入/1M输出/1M
google/gemini-3.0-pro$1.25$10.00
google/gemini-2.5-pro
$1.25 | $10.00 |

| google/gemini-2.5-flash | $0.30 | $2.50 | | google/gemini-2.5-flash-lite | $0.10 | $0.40 |

DeepSeek
模型输入/1M输出/1M
deepseek/deepseek-chat (V3.2)$0.28$0.42 ★ 基础默认
deepseek/deepseek-reasoner (V3.2)
$0.28 | $0.42 |

xAI (Grok)
模型输入/1M输出/1M
xai/grok-3$3.00$15.00
xai/grok-3-mini
$0.30 | $0.50 |

定价来源:各提供商的官方API文档,2026年2月验证。

运行时覆盖模型

python

为精英层使用GPT-5.2,为基础层使用Gemini Flash Lite


router = ModelRouter(
elite_model=openai/gpt-5.2,
balanced_model=google/gemini-2.5-flash,
basic_model=google/gemini-2.5-flash-lite,
)

python

切换层级模型,无需重新创建路由器


router.set_model(ELITE, anthropic/claude-opus-4-5)

列出所有可用模型(命令行)

bash
python3 scripts/model_router.py --list-models

命令行使用

bash

路由单个查询


python3 scripts/model_router.py 从头实现AES加密

覆盖精英模型

python3 scripts/model_router.py --elite openai/gpt-5.2 编写一个编译器

运行完整冒烟测试

python3 scripts/model_router.py

动态关键词扩展

python
router.add_keywords(ELITE, [密码学证明, 零知识])

示例输出

查询 预测 期望 ✓ 成本信息
────────────────────────────────────────────────────────────────────────────────────
你今天过得怎么样? 基础 基础 ✓ $0.14/M 节省98.6%
用三个要点总结这篇文章。 均衡 均衡 ✓ $0.15/M 节省98.5%
在Python中实现线程安全的LRU缓存。 精英 精英 ✓ $3.0/M 节省70.0%

安全与隐私

  • - 零外部调用:所有分类均在本地运行。
  • 无需API密钥:路由器本身不需要任何密钥。
  • 透明权重:所有模型参数位于scripts/model_weights.py中——完全可审计。

节省成本,更智能地路由。为OpenClaw社区构建。

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 semantic-model-router-1776299142 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 semantic-model-router-1776299142 技能

通过命令行安装

skillhub install semantic-model-router-1776299142

下载

⬇ 下载 semantic-model-router v1.0.3(免费)

文件大小: 14.13 KB | 发布时间: 2026-4-16 15:54

v1.0.3 最新 2026-4-16 15:54
- Updated documentation for model tiers, supported providers, and pricing details.
- Expanded model support list to 17 models across Anthropic, OpenAI, Google, DeepSeek, and xAI.
- Clarified routing architecture (ML classifier, semantic fallback, keyword rules).
- Added examples for runtime model override, CLI usage, and dynamic keyword rules.
- Documentation now emphasizes zero external calls and no required API keys.
- Improved quickstart and output explanation for users.
返回顶部