Skip to content
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

Stop throwing when fetch isnt detected in the environment #666

Closed
1 task done
justinwiley opened this issue Feb 7, 2024 · 1 comment
Closed
1 task done

Stop throwing when fetch isnt detected in the environment #666

justinwiley opened this issue Feb 7, 2024 · 1 comment

Comments

@justinwiley
Copy link

justinwiley commented Feb 7, 2024

Confirm this is a feature request for the Node library and not the underlying OpenAI API.

  • This is a feature request for the Node library

Describe the feature or improvement you're requesting

Testing projects using OpenAI is unusually difficult due to import-time errors if the OpenAI library (mistakenly) believes fetch libraries are missing.

Turning this into a warning, or removing and just adding documentation telling users to use the shim, would remove the need for elaborate mocking, shimming and jest setup files.

See #304 for examples of the work arounds developers need to do to develop and test projects using OpenAI, simply due to this error being thrown.

Example using the latest version of jest and OpenAI:

llm-test.js

import 'web-streams-polyfill/es6' // doent work
import 'openai/shims/node';  // doesnt work
import 'openai/shims/web'; // doesnt work
jest.mock('openai'); // doesnt work

import LLM from './llm.js';

llm.js

import OpenAI from "openai"

Error:

    this environment is missing the following Web Fetch API type: fetch is not defined. Add one of these imports before your first `import … from 'openai'`:
    - `import 'openai/shims/node'` (if you're running on Node)
    - `import 'openai/shims/web'` (otherwise)

Additional context

No response

@rattrayalex
Copy link
Collaborator

Sorry about this. These problems will go away once #402 is merged.

In the meantime, if you import 'openai/shims/node'; you can't also
import 'openai/shims/web';. If doing the node shim doesn't work, you must do import 'openai/shims/web'; and also bring in fetch as a global if your environment doesn't provide it by default.

In the meantime, we unfortunately don't plan to add any other ameliorations, so I'm going to close this as wontfix.

@rattrayalex rattrayalex closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants