-
Notifications
You must be signed in to change notification settings - Fork 743
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
Internal use of axios causes error inside Cloudflare Workers #30
Comments
I got the same error, because of axios adapters used const { Configuration, OpenAIApi } = require("openai");
+ const fetchAdapter = require("@vespaiach/axios-fetch-adapter")
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
+ baseOptions: {
+ adapter: fetchAdapter
+ }
});
const openai = new OpenAIApi(configuration); Import import { Configuration, OpenAIApi } from 'openai'
+ import fetchAdapter from '@vespaiach/axios-fetch-adapter'
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
+ baseOptions: {
+ adapter: fetchAdapter
+ }
});
const openai = new OpenAIApi(configuration); |
Think you should ditch axios in favour of using fetch directly instead. also form-data is now a piece of legacy and more proper, spec'ed FormData is available to use. When logging anything from if you got problem importing node-fetch@3 b/c it's ESM only then you could opt for something like this: node-fetch/node-fetch#1279 (comment) |
would love to see this fixed — it's a blocker for using this library in Cloudflare, and as other comments have pointed out, there is no reason to use axios when fetch is widely supported |
This is fixed in our upcoming v4! Please give it a try on Cloudflare Workers and let us know if you run into any issues. |
Describe the bug
I am trying to use the client inside a Cloudflare Worker and I get an error as follows:
Seems to be a common problem as the way Axios checks for XHR breaks in CF workers which is a reduced node environment:
https://community.cloudflare.com/t/typeerror-e-adapter-s-adapter-is-not-a-function/166469/2
Recommendation is to use fetch instead.
To Reproduce
Try to use API in a cloudflare worker
Code snippets
No response
OS
Windows 10
Node version
Node v16
Library version
openai v3.1.0
The text was updated successfully, but these errors were encountered: