openai / openai-node

The official Node.js / Typescript library for the OpenAI API
https://www.npmjs.com/package/openai
Apache License 2.0
7.65k stars 820 forks source link

openai@4.12 do not work on deno runtime? #393

Closed CNSeniorious000 closed 10 months ago

CNSeniorious000 commented 11 months ago

Confirm this is a Node library issue and not an underlying OpenAI API issue

Describe the bug

I try to import openai on my netlify edge function, it works well days ago, but today it raises:

error: Uncaught (in promise) Error: Module not found "https://esm.sh/v133/openai@4.12.4/denonext/resources.js".
       const ret = new Error(getStringFromWasm0(arg0, arg1));
                  ^
       at __wbg_new_15d3966e9981a196 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm.generated.js:417:19)
       at <anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm_bg.wasm:1:93412)
            at <anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm_bg.wasm:1:1499594)
            at <anonymous> (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm_bg.wasm:1:1938165)
            at __wbg_adapter_40 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm.generated.js:231:6)
       at real (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.40.0/eszip_wasm.generated.js:215:14)
       at eventLoopTick (ext:core/01_core.js:183:11)

Note that I found /denonext/resources.js missing from esm.sh. I don't know if this is related.

To Reproduce

new a netlify edge function with just

import OpenAI from "https://esm.sh/openai"

and deploys it

Code snippets

No response

OS

Windows

Node version

deno

Library version

openai v4.12

rattrayalex commented 11 months ago

Thanks for the report, we'll take a look.

On Sat, Oct 21 2023 at 1:35 AM, Muspi Merol @.***> wrote:

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

I try to import openai on my netlify edge function, it works well days ago, but today it raises:

error: Uncaught (in promise) Error: Module not found @./denonext/resources.js". const ret = new Error(getStringFromWasm0(arg0, arg1)); ^ at __wbg_new_15d3966e9981a196 @*.**@*./eszip_wasm.generated.js:417:19) at @*.**@*./eszip_wasm_bg.wasm:1:93412) at @*.**@*./eszip_wasm_bg.wasm:1:1499594) at @*.**@*./eszip_wasm_bg.wasm:1:1938165) at __wbg_adapter_40 @*.**@*./eszip_wasm.generated.js:231:6) at real @*.**@*.***/eszip_wasm.generated.js:215:14) at eventLoopTick (ext:core/01_core.js:183:11)

Note that I found /denonext/resources.js missing from esm.sh. I don't know if this is related. To Reproduce

new a netlify edge function with just

import OpenAI from "https://esm.sh/openai"

and deploys it Code snippets

No response OS

Windows Node version

deno Library version

openai v4.12

— Reply to this email directly, view it on GitHub https://github.com/openai/openai-node/issues/393, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFL6LQBL6VORHMSMULDYFDYANNILAVCNFSM6AAAAAA6J45C5KVHI2DSMVQWIX3LMV43ASLTON2WKOZRHE2TKMZTGQYDENQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

rattrayalex commented 11 months ago

Sorry about this, we're reenabling deno support now and should have it released within a few days.

aar2dee2 commented 11 months ago

Hey,

I'm using openai in Supabase Edge Functions and getting the above error. I tried importing from both npm:openai@4.13.0 and https://raw.githubusercontent.com/openai/openai-node/v4.12.4-deno/mod.ts

Screenshot 2023-10-25 at 3 11 20 PM Screenshot 2023-10-25 at 3 11 24 PM

deno CLI version 1.37.2

rattrayalex commented 11 months ago

Hey, sorry about this. Can you try import OpenAI from 'npm:openai@4'?

Even import OpenAI from "npm:openai@4.13.0" seems to work for me on a Deno Deploy playground, so perhaps it was just a caching issue or something?

If that still doesn't work, can you share your import map?

fi5u commented 10 months ago

@rattrayalex I tried your example of import OpenAI from 'npm:openai@4.13.0' and I'm also getting the same problem. Also, your link to the Deno playground is a 404. I am not using an import map. Deno version 1.37.2.

Supabase CLI 1.106.1
Version 1.30.3 is already installed
Bundling scene-description-to-image-prompt
Error bundling function: exit status 1
file:///Users/tf/Projects/ds/supabase/functions/import_map.json
file:///Users/tf/Projects/ds/supabase/functions/scene-description-to-image-prompt/index.ts
error: Uncaught (in promise) Error: Module not found "npm:openai@4.13.0".
      const ret = new Error(getStringFromWasm0(arg0, arg1));
                  ^
    at __wbg_new_8d2af00bc1e329ee (https://deno.land/x/eszip@v0.35.0/eszip_wasm.generated.js:513:19)
    at <anonymous> (https://deno.land/x/eszip@v0.35.0/eszip_wasm_bg.wasm:1:1559899)
    at <anonymous> (https://deno.land/x/eszip@v0.35.0/eszip_wasm_bg.wasm:1:1398157)
    at <anonymous> (https://deno.land/x/eszip@v0.35.0/eszip_wasm_bg.wasm:1:1895031)
    at __wbg_adapter_40 (https://deno.land/x/eszip@v0.35.0/eszip_wasm.generated.js:229:6)
    at real (https://deno.land/x/eszip@v0.35.0/eszip_wasm.generated.js:213:14)
fi5u commented 10 months ago

Importing an older version works fine: import OpenAI from 'npm:openai@4.11'

rattrayalex commented 10 months ago

Thanks for writing in @fi5u . Sorry for the 404; here's a public playground: https://dash.deno.com/playground/fair-goose-52

Given this code:

import OpenAI from 'npm:openai@4'
import {VERSION} from 'npm:openai@4/version'
import {VERSION as v413} from 'npm:openai@4.13.0/version'

const client = new OpenAI({apiKey: 'TODO'})

Deno.serve((req: Request) => new Response(`OpenAI Version ${VERSION}, can also import ${v413}`));

I see this result:

OpenAI Version 4.14.0, can also import 4.13.0

Can you try an equivalent in Supabase and share the result?

I'm not familiar with their offering and how it might be different from vanilla Deno Deploy (or how to get started with a function on their platform).

fi5u commented 10 months ago

@rattrayalex Thanks for the response. When trying your example with Supabase, as before, it fails to bundle (output below). I'm new to both Supabase and Deno so I'm not sure what's happening here. I'm ok sticking with the working v.4.11 until this is fixed.

Version 1.30.3 is already installed
Bundling scene-description-to-image-prompt
Error bundling function: exit status 1
file:///Users/tf/Projects/ds/supabase/functions/import_map.json
file:///Users/tf/Projects/ds/supabase/functions/scene-description-to-image-prompt/index.ts
error: Uncaught (in promise) Error: Module not found "npm:openai@4".
      const ret = new Error(getStringFromWasm0(arg0, arg1));
                  ^
    at __wbg_new_8d2af00bc1e329ee (https://deno.land/x/eszip@v0.35.0/eszip_wasm.generated.js:513:19)
    at <anonymous> (https://deno.land/x/eszip@v0.35.0/eszip_wasm_bg.wasm:1:1559899)
    at <anonymous> (https://deno.land/x/eszip@v0.35.0/eszip_wasm_bg.wasm:1:1398157)
    at <anonymous> (https://deno.land/x/eszip@v0.35.0/eszip_wasm_bg.wasm:1:1895031)
    at __wbg_adapter_40 (https://deno.land/x/eszip@v0.35.0/eszip_wasm.generated.js:229:6)
    at real (https://deno.land/x/eszip@v0.35.0/eszip_wasm.generated.js:213:14)
aar2dee2 commented 10 months ago

Hey @rattrayalex,

Thanks for looking into this 🙏🏼

I tried npm:openai@4, npm:openai@4.13.0, npm:openai@4.11.0 and npm:openai@4.12.4 and all return a Error: Module not found "npm:open@<version> error. Here's my import_map_deploy.json:

{
  "imports": {
    "https": "https://deno.land/std@0.204.0/http/server.ts",
    "npm:openai": "npm:openai@4.12.4",
    "xhr": "https://deno.land/x/xhr@0.3.0/mod.ts",
    "supabase-js": "https://esm.sh/@supabase/supabase-js@2.21.0",
    "common-tags": "https://esm.sh/common-tags@1.8.2",
    "gpt3-tokenizer": "https://esm.sh/gpt3-tokenizer@1.1.5",
    "common/*": "./common/*",
    "langchain/": "https://esm.sh/langchain@0.0.92&no-dts/",
    "pdf-parse": "https://esm.sh/v125/pdf-parse@1.1.1",
    "stripe": "https://esm.sh/stripe@13.5.0?target=deno"
  }
}

and the deno.json

{
  "compilerOptions": {
    "allowJs": true,
    "lib": ["deno.window"],
    "strict": true
  },
  "lint": {
    "include": ["."],
    "exclude": [],
    "rules": {
      "tags": ["recommended"],
      "include": ["ban-untagged-todo"],
      "exclude": ["no-unused-vars"]
    }
  },
  "fmt": {
    "useTabs": true,
    "lineWidth": 80,
    "indentWidth": 4,
    "semiColons": false,
    "singleQuote": true,
    "proseWrap": "preserve",
    "include": ["."],
    "exclude": []
  },
  "test": {
    "include": ["."],
    "exclude": []
  },
  "importMap": "./import_map_deploy.json"
}

Note: My deno version is 1.37.2, but the version on the hosted Supabase project is 1.30.3. Unsure if this may be causing errors, have reached out to the Supabase team for this.

aar2dee2 commented 10 months ago

I tried serving the Supabase Edge Function locally. This uses Supabase edge-runtime. I'm using edge_runtime version 1.22.3 which has Deno version 1.37.1. Still running into the same error.

Screenshot 2023-10-26 at 2 11 07 PM
rattrayalex commented 10 months ago

Thank you very much @aar2dee2 and @fi5u for the detailed reports. I've passed this along to the folks at Deno.

@fi5u out of curiosity, the import that's working for you is this, correct?

import OpenAI from 'https://esm.sh/openai@4.11.0'
fi5u commented 10 months ago

@rattrayalex My working import looks like this:

import OpenAI from 'https://esm.sh/openai@4.11'
aar2dee2 commented 10 months ago

@rattrayalex My working import looks like this:

import OpenAI from 'https://esm.sh/openai@4.11'

This is working for me too! Thanks @fi5u

rattrayalex commented 10 months ago

We've released v4.15.3 to deno.land/x/, which you can use like so:

import OpenAI from 'https://deno.land/x/openai@v4.15.3/mod.ts';

We're working to also publish 4.16.0, which contains the changes from DevDay's announcements, shortly.

aar2dee2 commented 10 months ago

We've released v4.15.3 to deno.land/x/, which you can use like so:

import OpenAI from 'https://deno.land/x/openai@v4.15.3/mod.ts';

This works in Supabase Edge Functions. Thanks a ton!

rattrayalex commented 10 months ago

Thank you for confirming!

We've now also published v4.16.1 which includes today's api releases:

import OpenAI from 'https://deno.land/x/openai@v4.16.1/mod.ts';

Going forward, we'll be publishing to demo.land/x/openapi, which is the recommended way to use this package from supabase and netlify edge functions.

joshling1919 commented 10 months ago

Wanted to see if anyone else was able to get the latest deno openai 4.16.1 version working on a supabase edge function. When trying to stream chunks, I consistently seem to only get 1 part back that looks like this:

{
  id: "chatcmpl-8IPirfnuikMfsLCSj3uxhXPmqeU7k",
  object: "chat.completion.chunk",
  created: 1699399473,
  model: "gpt-4-0613",
  choices: [
    {
      index: 0,
      delta: { role: "assistant", content: "" },
      finish_reason: null
    }
  ]

but then nothing else.

Streaming was working okay when using "https://deno.land/x/openai@1.4.3/mod.ts"

rattrayalex commented 10 months ago

@joshling1919 can you open that as a separate issue, and share the code you're using to make the request?

buyblvd-ryan commented 10 months ago

@rattrayalex @fi5u Fun fact that's not published anywhere on the internet, Supabase's server-side for edge functions isn't running a version of Deno that supports npm: flagging. Gotta use esm.sh or similar, which is a problem when it doesn't play nice as with this issue. The only real hint for this is that they tell you to use esm.sh to import supabase-js in one of the edge function tutorials.

No point in going to Deno, their stuff is all working. Supabase just won't update their edge function configuration to support npm packages for some reason. Thanks for creating a dedicated Deno build, that's the only thing that's been reliable for me so far.

rattrayalex commented 10 months ago

Great news, esm.sh has fixed their bug and this package can now be imported via esm.sh in Deno like so:

import OpenAI from "https://esm.sh/openai";

https://www.val.town/v/rattrayalex/VERSION

ije commented 10 months ago

also added a testing ensure this package wouldn't break in future updates

aar2dee2 commented 10 months ago
import OpenAI from "https://esm.sh/openai";

this works with Supabase Edge Functions! 🚀