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

ReadableStream type mismatch when deploying to Vercel #7547

Open
1 task done
Klingefjord opened this issue Sep 27, 2023 · 5 comments
Open
1 task done

ReadableStream type mismatch when deploying to Vercel #7547

Klingefjord opened this issue Sep 27, 2023 · 5 comments
Labels
bug:unverified feat:fetch Issues related to @remix-run/web-fetch

Comments

@Klingefjord
Copy link

Klingefjord commented Sep 27, 2023

What version of Remix are you using?

2.0.1

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

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

@arvindrajnaidu
Copy link

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.

@jonniedarko
Copy link

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

@Klingefjord
Copy link
Author

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

+1

@Klingefjord
Copy link
Author

(fyi this is still a problem)

@maxfi
Copy link

maxfi commented Apr 6, 2024

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:
vercel#62 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:unverified feat:fetch Issues related to @remix-run/web-fetch
Projects
None yet
Development

No branches or pull requests

6 participants