0.0.3 • Published 12 months ago

@song940/openai v0.0.3

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

@song940/openai

OpenAI JS SDK

Installation

npm install @song940/openai

Usage

import { OpenAI } from '@song940/openai';
import { OpenAI } from 'https://lsong.org/chatgpt-demo/openai.js';

const openai = new OpenAI({
  api: 'https://oai.lsong.org/v1',
  apiKey: 'YOUR_API_KEY',
});

const response = await openai.createChatCompletion({
  model: 'gpt-3.5-turbo',
  messages: [{ role: 'user', content: 'Hello!' }],
});

console.log(response.choices[0].message.content);

// or stream

const response = openai.createChatCompletion({
  model: 'gpt-3.5-turbo',
  messages: [{ role: 'user', content: 'Hello!' }],
});

for await (const part of response) {
  console.log(part.choices[0]?.delta?.content);
}

Demo: https://lsong.org/chatgpt-demo

License

MIT License

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

2 years ago

0.0.0

2 years ago