ai
ai copied to clipboard
Remix – ReadableStream type mismatch: The "transform.readable" property must be an instance of ReadableStream. Received an instance of ReadableStream
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)
}
Also added here: https://github.com/remix-run/remix/issues/7547
Actually, probably not a problem with AI package, nor Remix, but the remix build tooling from Vercel.
https://github.com/vercel/remix/issues/60
Are you using node 18+?
Are you using node 18+?
Yes, 18.7
Is this resolved? https://github.com/vercel/remix/issues/60 and https://github.com/vercel/remix/pull/56 seems to have resolved it.
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
Hey @Klingefjord, could you please create a reproduction so we can check this out?
Probably related: https://github.com/vercel/remix/issues/62
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.
is this issue resolved?? facing same
@nsijwali did you try removing installGlobals
? I'm closing this as it seems like a Remix-related bug more than an AI SDK one.