@sumor/llm-connector

llm-connector

一款 Sumor Cloud 工具。
更多文档

这是一个适用于多个云供应商的 llm 连接器。

CI Test Coverage Audit

安装

npm i @sumor/llm-connector --save

先决条件

Node.JS 版本

需要 Node.JS 版本 16.x 或以上

需要 Node.JS ES 模块

由于此包是用 ES 模块编写的,请在您的 package.json 文件中更改以下代码:

{
  "type": "module"
}

用法

聊天

import Model from '@sumor/llm-connector'

const model = new Model({
  type: 'openai',
  key: '123'
})

const response = await model.chat('gpt-3.5-turbo', [
  {
    role: 'system',
    content: 'You are a helpful assistant.'
  },
  {
    role: 'user',
    content: 'Hello'
  }
])

console.log(response)
// 输出: { role: 'assistant', content: 'Hello, how can I help you today?' }

自定义 API 端点 URL

import Model from '@sumor/llm-connector'

const model = new Model({
  type: 'openai',
  key: '123',
  endpoint: {
    chat: 'https://api.openai.com/v1/chat'
  }
})