openai-node
openai-node copied to clipboard
Stream nor ChatCompletionStream types not exported
Confirm this is a Node library issue and not an underlying OpenAI API issue
- [X] This is an issue with the Node library
Describe the bug
One of openai.chat.completions.create return types is ApiPromise<Stream<OpenAI.Chat.ChatCompletionChunk>> yet the Stream is not the intrinsic Nodejs Stream, and not exported from openai.
To Reproduce
try to set type of awaited or in Promise return value from openai.chat.completions.create()
Code snippets
import OpenAI from 'openai'
import { config } from 'server/config'
import { errorHandler } from 'server/helpers'
const openai = new OpenAI({
apiKey: config?.OPENAI_API_KEY as string,
})
export const createText = async(prompt: string): Promise<OpenAI.Chat.ChatCompletion | null> => {
try {
const params: OpenAI.Chat.ChatCompletionCreateParams = {
messages: [{ role: 'user', content: prompt }],
model: 'gpt-3.5-turbo',
stream: true,
}
const options: OpenAI.RequestOptions = {}
const chatCompletion: OpenAI.Stream<OpenAI.Chat.ChatCompletionChunk> = await openai.chat.completions.create(params, options)
return chatCompletion
} catch (error: unknown) {
console.error(error)
errorHandler(error)
return null
}
}
OS
any
Node version
18.13.0
Library version
4.20.1
Right now you can
import { Stream } from 'openai/streaming';
import { ChatCompletionStream } from 'openai/lib/ChatCompletionStream';
We'll take a look at adding them to the top-level export.
This is actually good, IMO, but is this documented?
Thanks! We do need better docs on this. What would you like to see in those docs?