npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dart-openai-sdk

v1.0.7

Published

OpenAI api-reference sdk

Downloads

21

Readme

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() 参数说明:

  • @param {string} key OpenAI API KEY (Find Key: https://platform.openai.com/account/api-keys)
  • @param {string} organization OpenAI API Organization (Find Key: https://platform.openai.com/account/api-keys)
  • @param {string} api_url https://api.openai.com/v1
  • @param {number} max_cache_num 对话缓存的最大条数
  • @param {boolean} debug 是否调试模式,会打印出一些日志信息

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']