Skip to content

Stream nor ChatCompletionStream types not exported #558

Open
@edgar0011

Description

@edgar0011

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions