vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.03k stars 26.71k forks source link

Problem with chatGPT streaming response in v13.2.4 #47043

Open igorxmath opened 1 year ago

igorxmath commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023
    Binaries:
      Node: 19.7.0
      npm: 9.5.1
      Yarn: N/A
      pnpm: 7.29.1
    Relevant packages:
      next: 13.2.4
      eslint-config-next: 13.2.4
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue

https://github.com/igorxmath/openai-tools

To Reproduce

pnpm install pnpm dev

Describe the Bug

I’ve just updated my app to 13.2.4 version. I just noticed that the streaming of ChatGPT is not working as it should using new route handlers.

Expected Behavior

In the first video, you can see how it used to be (in the old version). In the second one, it’s how it is now.

v13.2.3:

https://user-images.githubusercontent.com/103374874/224544674-6800ad8e-42ff-4645-9b43-00c7716e204a.mp4

v13.2.4:

https://user-images.githubusercontent.com/103374874/224544678-93b3bb1f-b0ef-4208-b7e7-a95a026faf2f.mp4

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

semy commented 1 year ago

@igorxmath How you solved the problem?

igorxmath commented 1 year ago

@igorxmath How you solved the problem?

I solved the problem by adding this:

export const runtime = 'edge'

But ended up with another problem using route handler reported in this issue #46337.

So in the end, I went back to using the old pages api routes.

igorxmath commented 1 year ago

When the runtime is set to nodejs (default) the bug occurs again.