-
Notifications
You must be signed in to change notification settings - Fork 873
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
Replace node-fetch with undici #392
Comments
Hi @Ethan-Arrowood, Thanks for raising this, it's something we'd be open to – and I appreciate the offer of help. There are a few related packages we rely on in the node-fetch ecosystem we rely on as well; could you help advise on replacements? They are:
|
|
Great!
If you'd be willing to take a crack at porting this, it'd certainly be tremendously appreciated. I think the toughest part will be our file uploads machinery (especially mucking without cross-environment support). We have pretty extensive tests (look for If that proves to be too big an ask, we can add this to our roadmap, it does sound like a good thing to do. |
Yeah apologies our docs aren't ideal. There is a ton of extensibility though.
Happy to do so! Let me take a swing at things next week. I'll also say, are you strictly tied to using Fetch for some sort of interim reasons? Or is the Node.js part of this distinct enough that you could use a better networking client? Undici itself has much better APIs such as |
Interesting, I didn't know that undici offered a different, faster request interface as well. There are a few considerations I'd have:
I'd be a little worried about bifurcating our request pathways between "env-or-user-provided fetch" or "built-in undici .request et al", but if it's what you'd recommend after considering the above and exploring the codebase, I'm certainly open to it! |
Let's start with switching to undici fetch. Would love to dig in deeper in the future. I think it's an interesting problem. This is exactly what fetch in node exists for - interoperability. I think you have an amazing example of cross environment javascript sdk 😁 |
Thanks Ethan! Very excited to see what you come up with! |
Undici fetch does look better! 🎉 My reverse proxy for api.openai.com has a default open setting response buffer, which takes some time to buffer data on I spent a lot of time trying to figure out this problem. I don't know how to make node-fetch support HTTP/2, so changing to undici is a better idea. |
The openai package transitively depends on an outdated version of whatwg-url, which causes nodejs to print a deprecation warning for punycode when running the vision tool. This will be fixed when openai resolves openai/openai-node#392. Until then, override the version of whatwg-url in order to prevent the deprecation warning. See openai/openai-node#527 (comment) for details on this stopgap. Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com>
Confirm this is a feature request for the Node library and not the underlying OpenAI API.
Describe the feature or improvement you're requesting
I noticed this library is still using node-fetch because Node's native fetch is considered experimental.
I think it'd be in the libraries best interest to switch to undici instead. Undici is the fetch implementation in Node.js. For all intents and purposes it is stable (nodejs/undici#1737). We (the maintainers of Undici) have some concerns about marking it as such in Node.js just yet because of the nature of the Fetch api spec (it itself adds breaking changes occasionally - this doesn't fit well with Node.js versioning strategy. It's complicated - read the issue I linked above for more details).
Switching the undici for the shim will enable a significantly easier upgrade path in the future whenever we figure out how to mark it as properly stable in Node.js
Happy to help swap this out too if the maintainers approve 😄 🚀
Additional context
No response
The text was updated successfully, but these errors were encountered: