0.0.1 • Published 11 months ago

encode-llm-sdk v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

encode-llm-sdk

印客学院 大模型 SDK

📖 使用文档

📦 安装

要安装 encode-llm-sdk,请运行以下命令:

$ pnpm install encode-llm-sdk

👋 使用

在这里获取你的 accessToken 值。

import { ErnieAI } from 'encode-llm-sdk';

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 'encode-llm-sdk';

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();
0.0.1

11 months ago