chatgpt-web icon indicating copy to clipboard operation
chatgpt-web copied to clipboard

切换成 Azure 后无法自动 Stop 对话

Open stulzq opened this issue 2 years ago • 3 comments

改了下代码支持 Azure OpenAI ,只改了请求的 url 拼接和 header,没有动其他逻辑。

我对比了 OpenAI 和 Azure OpenAI 响应的数据格式是一致的,但是为什么无法自动 Stop 呢。

Azure 响应:

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"role":"assistant"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"你"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"好"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"!"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"有"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"什"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"么"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"我"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"可以"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"为"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"您"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"做"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"的"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"吗"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"?"}}],"usage":null}

data: {"id":"chatcmpl-6xGsJBcDHMv8KUJDuk14JV32ZL3BZ","object":"chat.completion.chunk","created":1679584239,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":"stop","delta":{}}],"usage":null}

data: [DONE]

对话完成无法 Stop:

image

直到超时:

image

stulzq avatar Mar 23 '23 14:03 stulzq

可以分享一下您是怎么改的吗?谢谢

cnkang avatar Mar 23 '23 15:03 cnkang

可以分享一下您是怎么改的吗?谢谢

等我改好了提 PR

stulzq avatar Mar 23 '23 15:03 stulzq

跟到 chatgpt 这个包里面,发现接收请求最后的 [DONE] 竟然没收到,不知道为啥,POSTMAN 调用是正常的

stulzq avatar Mar 23 '23 16:03 stulzq

已解决,做了个 proxy https://github.com/stulzq/azure-openai-proxy

stulzq avatar Mar 24 '23 08:03 stulzq