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

Remix – ReadableStream type mismatch: The "transform.readable" property must be an instance of ReadableStream. Received an instance of ReadableStream #602

Closed
Klingefjord opened this issue Sep 27, 2023 · 11 comments

Comments

@Klingefjord
Copy link

Klingefjord commented Sep 27, 2023

I am using Remix (2.0.1) and Vercel AI (2.2.13).

I am getting this error when submitting a chat message in production (deployed on Vercel using the Remix template).

The error does not occur locally:

{ url: '/chat/completions' }
TypeError [ERR_INVALID_ARG_TYPE]: The "transform.readable" property must be an instance of ReadableStream. Received an instance of ReadableStream
    at new NodeError (node:internal/errors:405:5)
    at ReadableStream.pipeThrough (node:internal/webstreams/readablestream:363:13)
    at AIStream (/var/task/node_modules/ai/dist/index.js:139:29)
    at OpenAIStream (/var/task/node_modules/ai/dist/index.js:360:14)
    at action4 (/var/task/build/build-nodejs-eyJydW50aW1lIjoibm9kZWpzIn0.js:12965:73)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.callRouteActionRR (/var/task/node_modules/@remix-run/server-runtime/dist/data.js:35:16)
    at async callLoaderOrAction (/var/task/node_modules/@remix-run/router/dist/router.cjs.js:3903:16)
    at async submit (/var/task/node_modules/@remix-run/router/dist/router.cjs.js:3275:16)
    at async queryImpl (/var/task/node_modules/@remix-run/router/dist/router.cjs.js:3233:22) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Code to replicate:

/api/chat

import { ChatCompletionRequestMessage, OpenAIApi, Configuration } from "openai-edge"
import {
  OpenAIStream,
  StreamingTextResponse,
} from "ai"

export const action: ActionFunction = async ({
  request,
}: ActionFunctionArgs): Promise<Response> => {
  const json = await request.json()
  const { messages } = json
  const openai = new OpenAIApi(
     new Configuration({
       apiKey: xxxx
     })
  )
  const response = await openai.createChatCompletion({
      model: "gpt-3.5-turbo",
      messages: messages,
      temperature: 0.7,
      stream: true,
    })
  const stream = OpenAIStream(response)
  return new StreamingTextResponse(stream)
}
@Klingefjord
Copy link
Author

Also added here: remix-run/remix#7547

@Klingefjord
Copy link
Author

Actually, probably not a problem with AI package, nor Remix, but the remix build tooling from Vercel.

vercel/remix#60

@MaxLeiter
Copy link
Member

Are you using node 18+?

@Klingefjord
Copy link
Author

Are you using node 18+?

Yes, 18.7

@jacobhjkim
Copy link

Is this resolved? vercel/remix#60 and vercel/remix#56 seems to have resolved it.

@Klingefjord
Copy link
Author

Klingefjord commented Nov 13, 2023

vercel/remix#60

Nope, still an issue! Tried upgrading to latest remix and vercel ai, deployed anew on vercel, still the same error:

TypeError [ERR_INVALID_ARG_TYPE]: The "transform.readable" property must be an instance of ReadableStream. Received an instance of ReadableStream

@MaxLeiter
Copy link
Member

Hey @Klingefjord, could you please create a reproduction so we can check this out?

@maxfi
Copy link

maxfi commented Apr 7, 2024

Probably related: vercel/remix#62

@peterje
Copy link

peterje commented Apr 23, 2024

Omitting the call to installGlobals resolved this locally for me. That function is supposed to be the solution to these problems by polyfilling the fetch standard, but seems to have the opposite effect here.

@nsijwali
Copy link

is this issue resolved?? facing same

@MaxLeiter
Copy link
Member

@nsijwali did you try removing installGlobals? I'm closing this as it seems like a Remix-related bug more than an AI SDK one.

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

6 participants