Comments (5)
I got the same error, because of axios adapters used XMLHttpRequest
and node http
, but workers used fetch
to send request, so we should specify a fetch
adapter, I found a package @vespaiach/axios-fetch-adapter
, you can refer to the following code
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);
from openai-node.
Think you should ditch axios in favour of using fetch directly instead.
Either use node-fetch, undici or global fetch (NodeJS v18 provides fetch built in - coming from undici)
using fetch instead means it would be more functional inside of service worker, deno, bun.js and any other env. it would be more cross compatible.
also form-data is now a piece of legacy and more proper, spec'ed FormData is available to use.
When logging anything from response.data
then it dumps way too much unnecessary information that cluters the hole terminal
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)
from openai-node.
Looks like this was resurfaced in #47 and I am guessing it will be fixed if / when #45 is merged.
from openai-node.
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
from openai-node.
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.
from openai-node.
Related Issues (20)
- Property 'text' does not exist on type 'MessageContent' HOT 2
- thread_id not recognized from Thread object HOT 5
- Can't build NextJS project with openai library. Getting: Type error: Private identifiers are only available when targeting ECMAScript 2015 and higher. HOT 5
- extra_body parameter support HOT 1
- Vector Store File CreateAndPoll with empty file, last_error.code returned is "invalid_file" but TS say not exist. HOT 1
- Arrays for model names
- OpenAIError: Final run has not been received HOT 1
- Stop using polyfills for Node.js HOT 5
- `openai.files.content` returns raw Response object
- Getting `Unhandled Rejection` event, randomly. HOT 3
- JSONSchema does not support recursive refs & zod also fails to convert similar schemas to JSONSchema correctly HOT 10
- Difficulty in importing { zodResponseFormat } from https://deno.land HOT 7
- `batches.list()` doesn't iterate properly with Azure OpenAI HOT 6
- Zod => JSONSchema conversion creates references to unknown definitions HOT 7
- Structured Outputs fail with gpt4o when Zod schema includes pattern
- openai-deno: Type-checking error for zodResponseFormat with Deno and deno.land imports HOT 1
- License issue HOT 2
- runTools() without stream:true incorrectly emits "message" events for messages passed in
- Structured outputs: base zod schema using `discriminatedUnion` does not generate a valid JSON schema HOT 2
- `Abort on a function call` example is confusing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openai-node.