Skip to content

Conversation

BenjaminBruenau
Copy link
Contributor

This fixes compatibility with the SSE specification by not sending error messages out with an incompatible fieldname.
Therefore this also ensures proper exceptions when working for example with OpenAI client libraries, instead of being handled as an empty message.

Closes:
#16104

}
}, [&](const json & error_data) {
server_sent_event(sink, "error", error_data);
server_sent_event(sink, "data", json{{"error", error_data}});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like we no longer need the second argument of server_sent_event, as it will always be "data"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that makes sense.
Should this be kept in a way to make it compatible with the actual event field of the SSE spec (in a line above the data - if specified) or should that parameter be completely removed and simply always only use the data line?
e.g.

event: error
data: {error: {....}}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think most parsers will accept format data: {error: {....}}, anything outside of that always caused problems for downstream in the past, like the data: [DONE] for example.

@ngxson
Copy link
Collaborator

ngxson commented Sep 20, 2025

cc @allozaur you may need to update web ui code too (not urgent)

@ngxson ngxson merged commit 459c0c2 into ggml-org:master Sep 20, 2025
54 of 55 checks passed
struct pushed a commit to struct/llama.cpp that referenced this pull request Sep 26, 2025
…aming (ggml-org#16109)

* server: fix SSE and OpenAI compatibility for error messages when streaming

* server: remove obsolete event parameter and use required data fieldname instead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants