ai icon indicating copy to clipboard operation
ai copied to clipboard

Streaming or yield not working on Vercel

Open stephenkalnoske-sans opened this issue 3 months ago • 3 comments

Description

I set up an app just like in the examples. When I run it locally, it streams and yields from function* generators in the render functions perfectly. When I upload to Vercel and run it through there, there is no streaming. Responses still come in, but I don't see any of my spinners or loading messages when sent with yield.

I've made sure to update the ai, openai, and next packages to latest.

Code example

No response

Additional context

No response

stephenkalnoske-sans avatar Mar 19 '24 20:03 stephenkalnoske-sans

I solved this by adding

export const runtime = "edge"

in my page.tsx

Maybe the documentation should reflect that.

stephenkalnoske-sans avatar Mar 19 '24 23:03 stephenkalnoske-sans

@stephenkalnoske-sans which docs page were you looking at?

lgrammel avatar Mar 20 '24 07:03 lgrammel

https://sdk.vercel.ai/docs/concepts/ai-rsc

https://sdk.vercel.ai/docs/api-reference/generative-ui/render

stephenkalnoske-sans avatar Mar 20 '24 12:03 stephenkalnoske-sans

@lgrammel

I have the same issue. I created a minimum project with the example code in the docs and verified it. https://github.com/miurla/my-ai-app/blob/68fcd6540db4a4652093c0ae621a87367471fdcb/app/page.tsx#L7-L8

Is it correct to set export const runtime = "edge"? In Vercel's ChatBot, it doesn't seem to be set to edge, but it works. Are there any necessary settings in Vercel?

miurla avatar Apr 18 '24 14:04 miurla

@miurla can you try export const dynamic = 'force-dynamic'? (edge might not be needed)

CC @shuding re RSC

lgrammel avatar Apr 18 '24 15:04 lgrammel

@lgrammel Thank you for your quick response! I tried it, but it's not working.

https://github.com/miurla/my-ai-app/blob/main/app/page.tsx#L8

miurla avatar Apr 18 '24 15:04 miurla

Additional information

By removing use client from page.tsx and setting export const dynamic = 'force-dynamic', streaming started working. However, a client-side exception occurs.

https://github.com/miurla/morphic/blob/test-stream/app/page.tsx#L3

miurla avatar Apr 23 '24 03:04 miurla

There was a bug up until 14.2.2 with streaming + server actions + Node.js that has since been resolved. https://github.com/miurla/morphic/pull/5#issuecomment-2100788459

This issue seems to have been caused by a combination of factors. It has been resolved in 14.2.3. I think we can close this issue.

miurla avatar May 09 '24 01:05 miurla