cohere-ai / cohere-typescript

The Cohere TypeScript SDK
https://docs.cohere.ai
MIT License
127 stars 18 forks source link

Mutating `global.fetch` causes issues with other libraries #113

Closed wilsonzlin closed 9 months ago

wilsonzlin commented 10 months ago

It appears that this library changes global.fetch if the global fetch does not exist. This causes issues with some other libraries that try to do the same thing, and also overrides the builtin fetch now available in Node.js; in general, mutating globals from a library is not ideal. For example, this caused all fetch calls from the Oracle Cloud SDK to fail, which I have also raised an issue for. As a side note, it also assumes that the platform is Node.js.

Might I suggest using fetch-ponyfill, which provides the same cross-browser fetch polyfill but doesn't mutate the global fetch function? It requires an import, but this should be trivial to migrate to as I found only one call to fetch in this library. Alternatively, perhaps create a local variable like const fetchFn = typeof fetch == "function" ? fetch : require("node-fetch") and use fetchFn instead of mutating global.fetch.

dsinghvi commented 10 months ago

@wilsonzlin thanks for the issue -- Cohere uses Fern to generate their SDKs and we'll be making a change to our generator to fix this!

hoantran-it commented 9 months ago

I've encountered the same issue with global node-fetch after many hours of debugging. @dsinghvi how can this issue be completely resolved? Thank you!

billytrend-cohere commented 9 months ago

Hey both, this issues should be resolved in 7.7.4 please let me know if it doesn't fix!

hoantran-it commented 9 months ago

Hey both, this issues should be resolved in 7.7.4 please let me know if it doesn't fix!

API doesn't work anymore, returns empty when retrieving with for await (const chat of stream)

Screenshot 2024-02-01 at 12 48 36
billytrend-cohere commented 9 months ago

Hey @hoantran-it super grateful to you for reporting this. We p0'd a fix and 7.7.5 should now be good. We are going to add e2e testing to improve stability of this. Thanks for all of your patience.

hoantran-it commented 9 months ago

Hey @hoantran-it super grateful to you for reporting this. We p0'd a fix and 7.7.5 should now be good. We are going to add e2e testing to improve stability of this. Thanks for all of your patience.

@billytrend-cohere thank you! It works well now 🥳