openai-node icon indicating copy to clipboard operation
openai-node copied to clipboard

Remove unnecessary web-streams-polyfill polluting global namespace

Open jacoblee93 opened this issue 1 year ago • 1 comments

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

The web-streams-polyfill package has a TypeScript bug where it pollutes the global namespace and misdefines [Symbol.asyncIterator] as a property rather than a method:

https://github.com/MattiasBuelens/web-streams-polyfill/blob/master/dist/types/ts3.6/polyfill.d.ts#L26

vs.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AsyncIterator/@@asyncIterator

This causes subtle typing bugs downstream. Furthermore, ReadableStream is now supported in the LTS version of Node, so the polyfill is no longer necessary:

https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream

To Reproduce

Create an interface that extends both ReadableStream and AsyncGenerator after importing the SDK:

import OpenAI from "openai";

interface IterableReadableStreamInterface<T> extends ReadableStream<T>, AsyncGenerator<T> {}

Code snippets

No response

OS

macOS

Node version

18

Library version

4.24.1

jacoblee93 avatar Jan 08 '24 23:01 jacoblee93

I will also file a bug on web-streams-polyfill

jacoblee93 avatar Jan 08 '24 23:01 jacoblee93