@carbide/l5-llm-router
v1.0.0
Published
LLMRouter 组件,路由链选择 - Day 1 核心组件 L5
Downloads
123
Maintainers
Readme
L5 LLMRouter - 路由链
Day 1 核心组件 L5,基于 LangChain.js 的路由链选择器。
安装
npm install @carbide/l5-llm-router使用
import { LLMRouter } from '@carbide/l5-llm-router';
const router = new LLMRouter({
apiKey: 'your-openai-api-key',
modelName: 'gpt-4'
});
// 添加路由
router.addRoute(
'translate',
'将文本翻译成其他语言',
'将以下文本翻译成英文:{input}'
);
router.addRoute(
'summarize',
'总结长文本',
'总结以下文本:{input}'
);
router.addRoute(
'explain',
'解释概念',
'解释以下概念:{input}'
);
// 自动路由
const result = await router.route('什么是量子计算?');
console.log(result.route); // 选择的路由: explain
console.log(result.result); // 解释内容
// 指定路由
const translation = await router.runWithRoute('translate', '你好世界');API
| 方法 | 说明 |
|------|------|
| addRoute(name, description, template) | 添加路由 |
| route(input) | 自动选择路由并执行 |
| runWithRoute(routeName, input) | 指定路由执行 |
在项目中使用
详见 day-01/21-multi-route-qa 等项目(Day 2)。
