Skip to content
/ ai Public

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

License

Notifications You must be signed in to change notification settings

zhengxs2018/ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

286a1fd · Nov 18, 2024

History

31 Commits
Nov 30, 2023
Jun 28, 2024
Dec 10, 2023
Jun 28, 2024
Jun 28, 2024
May 26, 2024
Nov 30, 2023
Dec 16, 2023
Nov 30, 2023
May 25, 2024
May 25, 2024
Nov 30, 2023
Nov 30, 2023
Nov 30, 2023
Dec 3, 2023
Nov 30, 2023
Nov 18, 2024
May 25, 2024
Jun 28, 2024
Nov 30, 2023
May 25, 2024
May 25, 2024

Repository files navigation

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 task <path/to/file>

注意 可以使用 task 直接运行示例的 ts 文件,如 pnpm task ai/samples/qwen/chat/create.ts

🔗 更多工具

🤝 参与贡献

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

🕘 Star History

Star History Chart


📝 License

Copyright © 2023 zhengxs2018.
This project is MIT licensed.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Languages