Giter Club home page Giter Club logo

Comments (5)

aliuq avatar aliuq commented on August 17, 2024 7

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.

jimmywarting avatar jimmywarting commented on August 17, 2024 7

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.

manovotny avatar manovotny commented on August 17, 2024 2

Looks like this was resurfaced in #47 and I am guessing it will be fixed if / when #45 is merged.

from openai-node.

aroman avatar aroman commented on August 17, 2024 1

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.

rattrayalex avatar rattrayalex commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.