xqdoo00o / chatgpt-web

Pure Javascript ChatGPT demo based on OpenAI API
https://xqdoo00o.github.io/chatgpt-web/
MIT License
983 stars 369 forks source link

请教,在后端返回的数据流是完整的输出流,但是页面回答的内容处确中断了输出,没有报错,请问可能是什么原因造成的呢 #127

Closed usawjq closed 5 months ago

usawjq commented 10 months ago

Q:mf A:2022年,我们迎来了10个年头,这段旅程充满了挑战和成就。我们一

抓取的后端连接来看,内容是完整返回了的

{"choices": [{"index": 0, "delta": {"content": "2"}, "finish_reason": null}]} {"choices": [{"index": 0, "delta": {"content": "0"}, "finish_reason": null}]} {"choices": [{"index": 0, "delta": {"content": "2"}, "finish_reason": null}]} {"choices": [{"index": 0, "delta": {"content": "2"}, "finish_reason": null}]} {"choices": [{"index": 0, "delta": {"content": "年"}, "finish_reason": null}]} .....................

usawjq commented 10 months ago

前后端都在一个服务器

xqdoo00o commented 10 months ago

中断的时候停止按钮也消失了吗

usawjq commented 10 months ago

中断后,发送按钮是灰色的,重新填入问题后,又可以发送了

xqdoo00o commented 10 months ago

看起来像是后端的问题,是否使用nginx之类的反代了

usawjq commented 10 months ago

是的,我升级了ng,然后怎么配置都不行,最后只能绕过了NG,解决了问题,但是还是想请教一下 我是1.18nginx,配置中是这么写的,但是还是会返回流偶尔乱码,我这么配置是不对么,感谢

    location /sse {
        proxy_pass http://XXXX.XXX.COM;  
        proxy_http_version 1.1;
        proxy_set_header Connection "keep-alive";
        proxy_buffering off;
        proxy_cache off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 600s;  # 根据需要增加超时时间
        add_header Cache-Control 'no-cache';
        add_header Content-Type 'text/event-stream';
    }
xqdoo00o commented 10 months ago

按理说有个proxy_buffering off;是不会有这种问题,升级下nginx版本试试

tomatocuke commented 10 months ago

是的,我升级了ng,然后怎么配置都不行,最后只能绕过了NG,解决了问题,但是还是想请教一下 我是1.18nginx,配置中是这么写的,但是还是会返回流偶尔乱码,我这么配置是不对么,感谢

    location /sse {
        proxy_pass http://XXXX.XXX.COM;  
        proxy_http_version 1.1;
        proxy_set_header Connection "keep-alive";
        proxy_buffering off;
        proxy_cache off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 600s;  # 根据需要增加超时时间
        add_header Cache-Control 'no-cache';
        add_header Content-Type 'text/event-stream';
    }

有时候乱码是 temperature 参数给的太大接近2了。 openAI 就会乱码胡说。