Skip to content
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

bug: response header wrong for non streamed responses (no chunks) #2560

Closed
Propheticus opened this issue Apr 1, 2024 · 5 comments
Closed
Assignees
Labels
P1: important Important feature / fix type: bug Something isn't working
Milestone

Comments

@Propheticus
Copy link

Propheticus commented Apr 1, 2024

When calling the /chat/completions API endpoint without "stream": true set, the response is indeed a single JSON object of type "chat.completion" and not a streaming of multiple server event lines starting with "data: " followed by objects of type "chat.completion.chunk".

So instead of

data: {"choices":[{"delta":{"content":" Pos"},"finish_reason":null,"index":0}],"created":1711961792,"id":"GEinhvWFJJLg5Qr8KJ6r","model":"_","object":"chat.completion.chunk"}

data: {"choices":[{"delta":{"content":"itive"},"finish_reason":null,"index":0}],"created":1711961792,"id":"h05jZ89hTwi7thCiVrBR","model":"_","object":"chat.completion.chunk"}

data: {"choices":[{"delta":{"content":"."},"finish_reason":null,"index":0}],"created":1711961792,"id":"5XwVZ6y0S8aIdtRSxSe0","model":"_","object":"chat.completion.chunk"}

data: {"choices":[{"delta":{"content":""},"finish_reason":null,"index":0}],"created":1711961792,"id":"6Vi2z9md1sQCWKhSYRJI","model":"_","object":"chat.completion.chunk"}

data: {"choices":[{"delta":{"content":""},"finish_reason":null,"index":0}],"created":1711961792,"id":"dRmZRw35MDeyq23GHAxr","model":"_","object":"chat.completion.chunk"}

data: {"choices":[{"delta":{"content":""},"finish_reason":"stop","index":0}],"created":1711961792,"id":"fpmpyJEnXHidePQM1cnz","model":"_","object":"chat.completion.chunk"}

data: [DONE]

We get

{"choices":[{"finish_reason":null,"index":0,"message":{"content":" Positive.","role":"assistant"}}],"created":1711962125,"id":"7Y3MXJ4ndC5QW1BrTvd4","model":"_","object":"chat.completion","system_fingerprint":"_","usage":{"completion_tokens":3,"prompt_tokens":59,"total_tokens":62}}

However, the response header still says:

HTTP/1.1 200 OK
Content-Type: text/event-stream
Cache-Control: no-cache
Connection: keep-alive
Access-Control-Allow-Origin: *
Date: Mon, 01 Apr 2024 08:55:47 GMT
Transfer-Encoding: chunked

I would expect a content-type of "application/json" and not "text/event-stream". Also the transfer-encoding: chunked is false.

@Propheticus Propheticus added the type: bug Something isn't working label Apr 1, 2024
@Propheticus Propheticus changed the title bug: response header wrong for non streamed (no chunks) calls bug: response header wrong for non streamed responses (no chunks) Apr 1, 2024
@louis-jan louis-jan added this to the v0.4.11 milestone Apr 3, 2024
@louis-jan
Copy link
Contributor

Great find! @Propheticus

@Van-QA
Copy link
Contributor

Van-QA commented Apr 9, 2024

hi @Propheticus, the issue was resolved in our nightlybuild, would you mind retrying it? thank you

@Propheticus
Copy link
Author

@Van-QA Will do as soon as I get Avast to stop sandboxing and blocking the installer.

@Propheticus
Copy link
Author

That works! Also the JSON is formatted with newlines and indents now.

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-cache
Connection: keep-alive
Access-Control-Allow-Origin: *
Date: Tue, 09 Apr 2024 07:46:50 GMT
Transfer-Encoding: chunked



{
	"choices":[
		{
			"finish_reason":null,
			"index":0,
			"message":{
				"content":" Positive.",
				"role":"assistant"
			}
		}
	],
	"created":1712648810,
	"id":"pfSUz0sCcSG0jTqmQdlg",
	"model":"_",
	"object":"chat.completion",
	"system_fingerprint":"_",
	"usage":{
		"completion_tokens":3,
		"prompt_tokens":59,
		"total_tokens":62
	}
}

@Propheticus
Copy link
Author

2 remarks:

  • The finish_reason is shown as null. That is normal for chunks that are not the last chunk. The last chunk, or in this case the only 'chunk' should mention the stop reason, e.g. "finish_reason":"stop" or .."length". Open AI spec.
    image

  • The Transfer-Encoding: chunked is still shown in the header while I'd expect a Content-Length: <length> instead. HTTP header doc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1: important Important feature / fix type: bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

4 participants