remix icon indicating copy to clipboard operation
remix copied to clipboard

ReadableStream type mismatch when deploying to Vercel

Open Klingefjord opened this issue 2 years ago • 5 comments

What version of Remix are you using?

2.0.1

Are all your remix dependencies & dev-dependencies using the same version?

  • [X] Yes

Steps to Reproduce

  • Fork the standard remix template and upgrade to v2
  • Install the vercel/ai package
  • Add /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)
}
  • Deploy to Vercel

Expected Behavior

Response returned as expected when endpoint called.

Actual Behavior

The above works well locally, but fails when deploying to Vercel:

{ 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' }

Klingefjord avatar Sep 27 '23 06:09 Klingefjord

I was getting this error when I set the runtime to 'nodejs' .. once I set it to export const runtime = 'edge' the error goes away.

arvindrajnaidu avatar Dec 12 '23 17:12 arvindrajnaidu

Is there a way to do this without edge runtime? I have dependencies not compatible with edge runtime

jonniedarko avatar Jan 14 '24 20:01 jonniedarko

Is there a way to do this without edge runtime? I have dependencies not compatible with edge runtime

+1

Klingefjord avatar Mar 14 '24 17:03 Klingefjord

(fyi this is still a problem)

Klingefjord avatar Mar 14 '24 17:03 Klingefjord

Has anyone figured out a workaround for this yet? I'm having the same issue trying to use https://github.com/xataio/client-ts

UPDATE: https://github.com/vercel/remix/issues/62#issuecomment-2041038392

maxfi avatar Apr 06 '24 10:04 maxfi