@zhengxs/langchain-tools
TypeScript icon, indicating that this package has built-in type declarations

0.1.0-alpha.2 • Public • Published

@zhengxs/langchain-tools

[!WARNING] 请勿在生产环境中使用。

基于 langchain 的辅助工具,解决多模型动态调用的问题。

除了内置大模型之外,也可以基于 langchain 调用本地模型或反向代理的接口。

🚀 快速开始

要安装 @zhengxs/langchain-tools,请运行以下命令:

# Use PNPM
$ pnpm add @zhengxs/langchain-tools

# Use Yarn
$ yarn add @zhengxs/langchain-tools

# Use NPM
$ npm i -S @zhengxs/langchain-tools

默认支持 OpenAI, Anthropic, 通义千问, 文心千帆 平台模型的调用。

import { HumanMessage } from '@langchain/core/messages';
import { ChatModelFactoryRegistry } from '@zhengxs/langchain-tools';

export const modelRegistry = new ChatModelFactoryRegistry([
  // 支持 OpenAI 大模型
  {
    name: 'openai',
    options: {
      apiKey: process.env.OPENAI_API_KEY,
    },
  },
  // 支持百度文心云千帆系列模型
  {
    name: 'qianfan',
    test: /^ERNIE-Bot/,
    options: {
      apiKey: process.env.QIAN_FANG_API_KEY,
      secretKey: process.env.QIAN_FANG_SECRET_KEY,
    },
  },
  // 支持通义千问和百川系列模型
  {
    name: 'tongyi',
    test: /^(qwen|baichuan|llama2)/,
    options: {
      apiKey: process.env.QWEN_API_KEY,
    },
  },
]);

const model = modelRegistry.build({
  model: 'Ernie-Bot-turbo', // or qwen-turbo or gpt-3.5-turbo
});

const messages = [new HumanMessage('Hello')];

await model.invoke(messages);
//=> AIMessage { content: "Hello! ...you may have." }

除了内置的通道,也可以通过自定义工厂函数接入本地模型或反向代理的接口,详见 对话模型注册工厂

📖 使用文档

⏳ 待办事项

  • [ ] 对话记忆胶囊

📝 License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @zhengxs/langchain-tools

Weekly Downloads

4

Version

0.1.0-alpha.2

License

MIT

Unpacked Size

30.9 kB

Total Files

6

Last publish

Collaborators

  • zhengxs