dart-openai-sdk

1.0.7 • Public • Published

OpenAI API SDK库

Current version Install size
Base Info

Introduction

安装 (Introduction)

npm install dart-openai-sdk

Tips:

  • 注意此项目只用于Node后端使用
  • 使用可以参考test.js中的代码进行使用

Loading

加载此模块 (Loading the module)

// CommonJS
const OpenAI = require('dart-openai-sdk');
const AI = new OpenAI('Your API KEY','Your API Organization');

// ES Module
import OpenAI from 'dart-openai-sdk';
const AI = new OpenAI('Your API KEY','Your API Organization');

new OpenAI() 参数说明:

Usage

常用APIs (Common Usage)

models

列出并描述API中可用的各种模型。你可以参考模型文档来了解有哪些模型可用以及它们之间的区别。
List and describe the various models available in the API. You can refer to the Models documentation to understand what models are available and the differences between them.
import OpenAI from 'dart-openai-sdk';
const AI = new OpenAI('Your API KEY');

let response = await AI.models();
console.log(JSON.stringify(response, null, 2));

retrieveModel

检索一个模型实例,提供关于模型的基本信息,如所有者和许可。
Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
import OpenAI from 'dart-openai-sdk';
const AI = new OpenAI('Your API KEY');

let response = await AI.retrieveModel('Model ID');
console.log(JSON.stringify(response, null, 2));

参数说明:

  • @param {string} model 这个请求要使用的模型的ID。可以通过models查询所有的模型列表。

chat

创建一个聊天会话
Creates a completion for the chat message
import OpenAI from 'dart-openai-sdk';
const AI = new OpenAI('Your API KEY');

let response = await AI.chat('Your Message','Your User ID','Your Model ID');
console.log(JSON.stringify(response, null, 2));

参数说明:

  • @param {string} message 对话消息,你输入的消息
  • @param {string} user 用户ID(同一个用户的对话信息使用同一个UserID)
  • @param {string} model (非必要) 要使用的模型ID (默认使用: gpt-3.5-turbo)

chatByStream

创建一个聊天会话,通过流式获得返回数据
Creates a completion for the chat message
import OpenAI from 'dart-openai-sdk';
const AI = new OpenAI('Your API KEY');

let response = await AI.chatByStream('Your Message','Your User ID','Your Model ID');
console.log(JSON.stringify(response, null, 2));

参数说明:

  • @param {string} message 对话消息,你输入的消息
  • @param {string} user 用户ID(同一个用户的对话信息使用同一个UserID)
  • @param {string} model (非必要) 要使用的模型ID (默认使用: gpt-3.5-turbo)

image

根据提示词生成图片
Creates an image given a prompt.
import OpenAI from 'dart-openai-sdk';
const AI = new OpenAI('Your API KEY');

let response = await AI.image('Female wearing cybernetic exoskeleton character design, concept design sheet, white background, style of yoji shinkawa', '1', 1, '512x512', 'url');
console.log(JSON.stringify(response, null, 2));

参数说明:

  • @param {string} prompt 对所需图像的文字描述。最大长度为1000个字符。
  • @param {string} user 用户ID
  • @param {number} number [1 ~ 10] 要生成的图像的数量。必须在1到10之间。
  • @param {string} size 生成图像的大小。必须是其中之一 ['256x256','512x512','1024x1024']
  • @param {string} response_format 返回生成的图像的格式。必须是以下之一 ['url','b64_json']

Readme

Keywords

Package Sidebar

Install

npm i dart-openai-sdk

Weekly Downloads

1

Version

1.0.7

License

GPL-3.0

Unpacked Size

22.1 kB

Total Files

4

Last publish

Collaborators

  • oen.im