Code Monkey home page Code Monkey logo

ai's Introduction

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.

ai's People

Contributors

zhengxs2018 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.