Coder Social home page Coder Social logo

zhengxs2018 / erniebot-sdk-for-js Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 98 KB

非官方 JS-SDK,可以调用文心大模型的能力,包含文本创作、通用对话、语义向量、AI作图等。

License: MIT License

JavaScript 1.65% TypeScript 98.35%

erniebot-sdk-for-js's Introduction

ERNIE Bot SDK for JavaScript

Typescriptcode style: prettiernpm packagenpm downloadsLicense

非官方 JS-SDK,请勿在生产中使用

可以调用文心大模型的能力,包含文本创作、通用对话、语义向量、AI作图等。

注意: 后续兼容 openai,可能会调整 API 的输出格式。

安装

# With NPM
$ npm i -S @zhengxs/erniebot

# With Yarn
$ yarn add @zhengxs/erniebot

# With PNPM
$ pnpm add @zhengxs/erniebot

使用

AI Studio

默认是 AI Studio 后端。

import ERNIEBot from '@zhengxs/erniebot'

const erniebot = new ERNIEBot({
  apiType: 'aistudio',
  token: 'My API Access Token', // defaults to process.env["EB_ACCESS_TOKEN"]
})

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

  console.log(chatCompletion.result)
}

main()

文心千帆

可以切换为 文心千帆 后端。

import ERNIEBot from '@zhengxs/erniebot'

const erniebot = new ERNIEBot({
  apiType: 'qianfan',
  ak: 'My APP Access Token', // defaults to process.env["EB_AK"]
  sk: 'My APP Secret Token', // defaults to process.env["EB_SK"]
})

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

  console.log(chatCompletion.result)
}

main()

CLI

使用全局安装

# With NPM
$ npm i -g @zhengxs/erniebot-cli

# With Yarn
$ yarn global @zhengxs/erniebot-cli

# With PNPM
$ pnpm add --global @zhengxs/erniebot-cli

使用 erniebot 命令运行。

$ erniebot

关联项目

参考

待办事项

  • 后端支持
  • 功能支持
    • ChatCompletion
    • Embedding
    • Images
    • Files
    • FineTuning
  • 运行时支持
    • NodeJS
    • Deno.js
    • 浏览器
    • 非标准 JS 环境,如:小程序

License

MIT

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.