Skip to content

fix: spec compliant instantiation and termination of streams #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2023

Conversation

Lederstrumpf
Copy link
Contributor

@Lederstrumpf Lederstrumpf commented May 21, 2023

Description

This PR fixes #340.

With reference to the example response from localAI from #340 (under "To Reproduce"), here's the corresponding updated response after this PR's changes:

HTTP/1.1 200 OK
Date: Sun, 21 May 2023 10:56:07 GMT
Content-Type: text/event-stream
Vary: Origin
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Connection: keep-alive
Transfer-Encoding: chunked

data: {"object":"chat.completion.chunk","model":"ggml-gpt4all-j","choices":[{"delta":{"role":"assistant"}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}

data: {"object":"chat.completion.chunk","model":"ggml-gpt4all-j","choices":[{"delta":{"content":"1"}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}

data: {"object":"chat.completion.chunk","model":"ggml-gpt4all-j","choices":[{"delta":{"content":" 2"}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}

data: {"object":"chat.completion.chunk","model":"ggml-gpt4all-j","choices":[{"delta":{"content":" 3"}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}

data: {"model":"ggml-gpt4all-j","choices":[{"finish_reason":"stop"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}

data: [DONE]

Diff

diff -u old-response new-response
--- old-response	2023-05-21 14:36:35
+++ new-response	2023-05-21 14:36:35
@@ -1,5 +1,5 @@
 HTTP/1.1 200 OK
-Date: Sun, 21 May 2023 11:01:33 GMT
+Date: Sun, 21 May 2023 10:56:07 GMT
 Content-Type: text/event-stream
 Vary: Origin
 Access-Control-Allow-Origin: *
@@ -7,21 +7,13 @@
 Connection: keep-alive
 Transfer-Encoding: chunked
 
+data: {"object":"chat.completion.chunk","model":"ggml-gpt4all-j","choices":[{"delta":{"role":"assistant"}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}
-event: data
-
-data: {"object":"chat.completion.chunk","model":"ggml-gpt4all-j","choices":[{"delta":{"role":"assistant","content":"1"}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}
+data: {"object":"chat.completion.chunk","model":"ggml-gpt4all-j","choices":[{"delta":{"content":"1"}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}
-
 
-event: data
-
-data: {"object":"chat.completion.chunk","model":"ggml-gpt4all-j","choices":[{"delta":{"role":"assistant","content":" 2"}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}
+data: {"object":"chat.completion.chunk","model":"ggml-gpt4all-j","choices":[{"delta":{"content":" 2"}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}
-
 
-event: data
-
-data: {"object":"chat.completion.chunk","model":"ggml-gpt4all-j","choices":[{"delta":{"role":"assistant","content":" 3"}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}
+data: {"object":"chat.completion.chunk","model":"ggml-gpt4all-j","choices":[{"delta":{"content":" 3"}}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}
-
 
-event: data
-
 data: {"model":"ggml-gpt4all-j","choices":[{"finish_reason":"stop"}],"usage":{"prompt_tokens":0,"completion_tokens":0,"total_tokens":0}}
-

+data: [DONE]

Diff finished.  Sun May 21 14:36:35 2023

Notes for Reviewers

Signed commits

  • Yes, I signed my commits.

Copy link
Owner

@mudler mudler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally - looks good here, thank you!

@mudler mudler merged commit 4aa7884 into mudler:master May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Streaming messages not compliant with openAI spec
2 participants