Example 1
Example 1
let client = new OpenAI.Client({ apikey: '...', }); // NOTE: All methods can throw! let reply = await client.completion({ model: '...', prompt: '...', }); console.assert(reply.object === 'text_completion'); // NOTE: All methods can throw! let stream = await client.completion({ model: '...', prompt: '...', stream: true, // << required! }); for await (let event of stream) { console.assert(event.object === 'text_completion') }
Client(options: AuthOptions)
chat(input: Chat.Request,signal?: AbortSignal,): Promise<Chat.Output>
Dispatch a Chat Completions request.
When input includes stream: true, then a ReadableStream is returned for message streaming.
Otherwise the full Chat.Output JSON object is returned.
Important: Will throw the Response on 4xx or 5xx status!
chat(input: Chat.Stream.Request,signal?: AbortSignal,): Promise<Chat.Stream.Output>
completion(input: Completion.Stream.Request,signal?: AbortSignal,): Promise<Completion.Stream.Output>
Dispatch a Completions (legacy) request.
When input includes stream: true, then a ReadableStream is returned for message streaming.
Otherwise the full Completion.Output JSON object is returned.
Important: Will throw the Response on 4xx or 5xx status!
completion(input: Completion.Request,signal?: AbortSignal,): Promise<Completion.Output>