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

Replace axios and other dependencies with native counterparts, add type support for `stream`

Open dqbd opened this issue 2 years ago • 1 comments

This PR replaces NPM dependencies such asaxios and form-data with native counterparts, making the codebase lighter and available for different non-Node environments.

We are aware of the existing pull requests for this feature (see #10, thanks @gfortaine), but this PR aims to be a more lightweight implementation (no external dependencies needed) and with a similar API to reduce migration friction.

Additionally, we have added type support for streaming, which enables TypeScript to return correct types when stream: true. This makes it easier for developers to work with streams in a type-safe manner.

https://user-images.githubusercontent.com/1443449/220939140-70058c48-ae0b-47e0-a576-7f7d99fa723a.mp4

Changelog:

  • Remove axios and form-data dependency with a simplified call to fetch (this is a breaking change, users w/out native Fetch support must polyfill/ponyfill)
  • Modify existing templates from typescript-axios template found here: https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/main/resources/typescript-axios (maybe we should just apply patches instead?)
  • Add an additional TypeScript source transformer using ts-morph to add proper type support for stream: true

dqbd avatar Feb 23 '23 14:02 dqbd

https://github.com/openai/openai-node/pull/45#issuecomment-1455258096

gfortaine avatar Mar 06 '23 00:03 gfortaine

This PR is better suited for the openai-node repository. We are also working on a v4 version that adds support for streaming and other features. Please continue the discussion there: https://github.com/openai/openai-node/discussions/182.

athyuttamre avatar Jul 05 '23 22:07 athyuttamre