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

Error thrown when using node's fetch after version 4.12.2 #384

Closed
1 task done
thhermansen opened this issue Oct 17, 2023 · 4 comments
Closed
1 task done

Error thrown when using node's fetch after version 4.12.2 #384

thhermansen opened this issue Oct 17, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@thhermansen
Copy link

thhermansen commented Oct 17, 2023

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

See two commits in https://github.com/thhermansen/openai-node-fetch/commits/main

which in essence consists of a rather small program:

import OpenAI from 'openai'


async function main() {
  new OpenAI({ apiKey: 'SECRET', });

  const response = await fetch('https://google.com')
  console.log(`${response.status} ${response.statusText}`)
}

if (require.main === module) main();

It works fine with openai 4.12.1, but breaks in 4.12.2 where you get an error thrown:

openai-test/node_modules/.pnpm/[email protected]/node_modules/web-streams-polyfill/src/lib/validators/readable-stream.ts:5
    throw new TypeError(`${context} is not a ReadableStream.`);
          ^

TypeError: First parameter has member 'readable' that is not a ReadableStream.
    at assertReadableStream (openai-test/node_modules/.pnpm/[email protected]/node_modules/web-streams-polyfill/src/lib/validators/readable-stream.ts:5:11)
    at convertReadableWritablePair (openai-test/node_modules/.pnpm/[email protected]/node_modules/web-streams-polyfill/src/lib/validators/readable-writable-pair.ts:15:3)
    at ReadableStream.ReadableStream.pipeThrough (openai-test/node_modules/.pnpm/[email protected]/node_modules/web-streams-polyfill/src/lib/readable-stream.ts:211:23)
    at fetchFinale (node:internal/deps/undici/undici:9584:56)
    at mainFetch (node:internal/deps/undici/undici:9476:9)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

The issue is maybe related to 71984ed

To Reproduce

Clone https://github.com/thhermansen/openai-node-fetch and run the code :)

Code snippets

No response

OS

MacOS

Node version

20.8.1

Library version

4.12.1, 4.12.2, 4.12.3

@thhermansen thhermansen added the bug Something isn't working label Oct 17, 2023
@rattrayalex
Copy link
Collaborator

Thanks for reporting this, especially with a repro repo. We're looking into it.

In the meantime, as a workaround, you might try import 'openai/shims/web' or import 'openai/shims/node' before your first import 'openai'.

@rattrayalex rattrayalex self-assigned this Oct 17, 2023
@benbalter
Copy link

benbalter commented Oct 17, 2023

I ran into the same issue. Downgrading to 4.12.1 solved the problem (the shim imports did not, but I may have done them wrong).

Edit to add: Thanks @rattrayalex for the quick response. ❤️

@rattrayalex
Copy link
Collaborator

Thank you for confirming @benbalter and attempting the workaround! I've identified the issue and have a fix in flight.

@rattrayalex
Copy link
Collaborator

This will be released in #386 !

rholinshead pushed a commit to lastmile-ai/semantic-retrieval that referenced this issue Oct 23, 2023
# Get localFileIngestion Script Running

Just some minor changes to get the script running locally. Upgrade openai to 4.12.4 to resolve the readable stream type error (per openai/openai-node#384)

My `.env` file has:
```
OPENAI_API_KEY=
PINECONE_ENVIRONMENT=asia-southeast1-gcp-free
PINECONE_API_KEY=
```
and I have a 'test' index in pinecone with default namespace.

```
ryanholinshead@Ryans-MacBook-Pro semantic-retrieval % npx ts-node examples/ingestion/localFileIngestion.ts
{"id":"chatcmpl-8CevIMd377n4SDZiJ5EBoXDCAobN7","object":"chat.completion","created":1698027936,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"message":{"role":"assistant","content":"There is no specific expiration date for intelligence, as it is not something that can expire like a product or a document. However, intelligence can change and adapt over time depending on factors such as age, education, and life experiences. While some aspects of intelligence may peak during certain stages of life, such as fluid intelligence in early adulthood, other types of intelligence, such as crystallized intelligence, can continue to develop and improve throughout a person's lifetime. Additionally, it is important to recognize that intelligence is a complex and multifaceted concept that cannot be fully captured by a single measure or test."},"finish_reason":"stop"}],"usage":{"prompt_tokens":7,"completion_tokens":119,"total_tokens":126}}
ryanholinshead@Ryans-MacBook-Pro semantic-retrieval %
```
Completion works and I checked the pinecone index to see embeddings inserted into it
rholinshead pushed a commit to lastmile-ai/semantic-retrieval that referenced this issue Oct 23, 2023
# Get localFileIngestion Script Running

Just some minor changes to get the script running locally. Upgrade openai to 4.12.4 to resolve the readable stream type error (per openai/openai-node#384)

My `.env` file has:
```
OPENAI_API_KEY=
PINECONE_ENVIRONMENT=asia-southeast1-gcp-free
PINECONE_API_KEY=
```
and I have a 'test' index in pinecone with default namespace.

```
ryanholinshead@Ryans-MacBook-Pro semantic-retrieval % npx ts-node examples/ingestion/localFileIngestion.ts
{"id":"chatcmpl-8CevIMd377n4SDZiJ5EBoXDCAobN7","object":"chat.completion","created":1698027936,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"message":{"role":"assistant","content":"There is no specific expiration date for intelligence, as it is not something that can expire like a product or a document. However, intelligence can change and adapt over time depending on factors such as age, education, and life experiences. While some aspects of intelligence may peak during certain stages of life, such as fluid intelligence in early adulthood, other types of intelligence, such as crystallized intelligence, can continue to develop and improve throughout a person's lifetime. Additionally, it is important to recognize that intelligence is a complex and multifaceted concept that cannot be fully captured by a single measure or test."},"finish_reason":"stop"}],"usage":{"prompt_tokens":7,"completion_tokens":119,"total_tokens":126}}
ryanholinshead@Ryans-MacBook-Pro semantic-retrieval %
```
Completion works and I checked the pinecone index to see embeddings inserted into it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants