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

0.5.1 • Public • Published

AI SDK

集成 百度文心一言,阿里通义千问,腾讯混元助手 和 讯飞星火认知 等国内大模型的 API,并且适配 OpenAI 的输入与输出。


Report Bug · Request Feature

目录树

TOC


✨ 功能特性

  • 🚀 快速开始: 简单易用,只需一次学习,即可快速接入各种大模型。
  • 💻 多模型集成: 集成了多种国内大模型,为用户提供丰富的对话模型选择,满足不同场景的需求。
  • 💎 体验友好: 无需深入学习,只需提供必要的 API Key,剩下的交给 SDK 处理。
  • 🔌 完美适配: 适配 OpenAI 的输入与输出格式,确保与其他模型的对话无缝对接。

📖 使用文档

📦 安装

要安装 @zhengxs/ai,请运行以下命令:

$ pnpm install @zhengxs/ai

👋 使用

在这里获取你的 accessToken 值。

import { ErnieAI } from '@zhengxs/ai';

const client = new ErnieAI({
  apiKey: 'My API Key', // defaults to process.env["EB_API_KEY"]
});

async function main() {
  const chatCompletion = await client.chat.completions.create({
    model: 'ernie-bot-turbo',
    messages: [{ role: 'user', content: 'Say this is a test' }],
  });
}

main();

支持流式

使用与 OpenAI 的 SDK 完全一致。

import { ErnieAI } from '@zhengxs/ai';

const client = new ErnieAI();

async function main() {
  const stream = await client.chat.completions.create({
    model: 'ernie-bot-turbo',
    messages: [{ role: 'user', content: 'Say this is a test' }],
    stream: true,
  });

  for await (const chunk of stream) {
    process.stdout.write(chunk.choices[0]?.delta?.content || '');
  }
}

main();

⌨️ 本地开发

可以使用 GitHub Codespaces 进行在线开发:

或者使用以下命令进行本地开发:

$ git clone https://github.com/zhengxs2018/ai.git
$ cd ai
$ pnpm install
$ pnpm dev

🔗 更多工具

🤝 参与贡献

我们非常欢迎各种形式的贡献。如果你对贡献代码感兴趣,可以查看我们的 GitHub Issues 大展身手,向我们展示你的奇思妙想。

🕘 Star History

Star History Chart


📝 License

Copyright © 2023 zhengxs2018.
This project is MIT licensed.

Package Sidebar

Install

npm i @zhengxs/ai

Weekly Downloads

27

Version

0.5.1

License

MIT

Unpacked Size

161 kB

Total Files

60

Last publish

Collaborators

  • zhengxs