handle data:[DONE] more robustly
although https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#request-body says >stream boolean Whether to stream back partial progress. If set, tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message but what I see is `data:[DONE]` (without space), e.g. ``` curl -q --location 'http://localhost:8080/openai/deployments/gpt-4o/chat/completions?api-version=2023-07-01-preview' \ --header 'Authorization: Bearer <token>' \ --header 'X-Forwarded-Client-Cert: secret' \ --header 'Content-Type: application/json' \ --data '{ "stream": true, "messages": [ { "role": "user", "content": "hello." } ] }' data:{"choices":[],"created":0,"id":"","model":"","object":"","prompt_filter_results":[{"prompt_index":0,"content_filter_results":{"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}}}]} data:{"choices":[{"content_filter_results":{},"delta":{"refusal":null,"role":"assistant"},"finish_reason":null,"index":0}],"created":1746741184,"id":"chatcmpl-BV3SqfEtCuk3f8fW5x7azEkELkJZ0","model":"gpt-4o-2024-05-13","object":"chat.completion.chunk","system_fingerprint":"fp_ee1d74bde0"} ... data:{"choices":[{"content_filter_results":{"hate":{"filtered":false,"severity":"safe"},"self_harm":{"filtered":false,"severity":"safe"},"sexual":{"filtered":false,"severity":"safe"},"violence":{"filtered":false,"severity":"safe"}},"delta":{"content":"?"},"finish_reason":null,"index":0}],"created":1746741184,"id":"chatcmpl-BV3SqfEtCuk3f8fW5x7azEkELkJZ0","model":"gpt-4o-2024-05-13","object":"chat.completion.chunk","system_fingerprint":"fp_ee1d74bde0"} data:{"choices":[{"content_filter_results":{},"delta":{},"finish_reason":"stop","index":0}],"created":1746741184,"id":"chatcmpl-BV3SqfEtCuk3f8fW5x7azEkELkJZ0","model":"gpt-4o-2024-05-13","object":"chat.completion.chunk","system_fingerprint":"fp_ee1d74bde0"} data:[DONE] ```
This commit is contained in:
parent
ec0180bf95
commit
5db24e4bbc
1 changed files with 1 additions and 1 deletions
|
|
@ -58,7 +58,7 @@ function parseDataLine(line: string): any {
|
|||
}
|
||||
|
||||
function parseSseLine(line: string): { done: boolean; data: any } {
|
||||
if (line.startsWith("data: [DONE]")) {
|
||||
if (line.startsWith("data:[DONE]") || line.startsWith("data: [DONE]")) {
|
||||
return { done: true, data: undefined };
|
||||
}
|
||||
if (line.startsWith("data:")) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue