Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream nor ChatCompletionStream types not exported #558

Open
1 task done
edgar0011 opened this issue Dec 10, 2023 · 3 comments
Open
1 task done

Stream nor ChatCompletionStream types not exported #558

edgar0011 opened this issue Dec 10, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@edgar0011
Copy link

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • 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

@edgar0011 edgar0011 added the bug Something isn't working label Dec 10, 2023
@rattrayalex rattrayalex removed the bug Something isn't working label Dec 11, 2023
@rattrayalex
Copy link
Collaborator

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.

@rattrayalex rattrayalex added the enhancement New feature or request label Dec 11, 2023
@edgar0011
Copy link
Author

This is actually good, IMO, but is this documented?

@rattrayalex
Copy link
Collaborator

Thanks! We do need better docs on this. What would you like to see in those docs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants