@carbide/l1-llm-chain
v1.0.0
Published
LLMChain 组件,LangChain.js 基础链 - Day 1 核心组件 L1
Downloads
128
Maintainers
Readme
L1 LLMChain - LangChain.js 基础链
Day 1 核心组件 L1,基于 LangChain.js 的 LLMChain 封装。
安装
npm install @carbide/l1-llm-chain使用
import { LLMChainService } from '@carbide/l1-llm-chain';
const llm = new LLMChainService({
apiKey: 'your-openai-api-key',
modelName: 'gpt-4',
temperature: 0.7,
streaming: true
});
// 普通对话
const response = await llm.chat('你好', [
{ role: 'system', content: '你是一个助手' }
]);
// 流式输出
for await (const chunk of llm.streamChat('讲个故事')) {
console.log(chunk);
}
// 使用自定义模板
const result = await llm.runWithTemplate(
'将以下文本翻译成{language}:{text}',
{ language: '英文', text: '你好世界' }
);API
| 方法 | 说明 |
|------|------|
| chat(message, history?) | 普通对话 |
| streamChat(message) | 流式对话 |
| runWithTemplate(template, variables) | 使用自定义模板 |
在项目中使用
详见 day-01/01-todo-list 等项目。
