-
Notifications
You must be signed in to change notification settings - Fork 33
Cosmos3-edge PR 5: end a failed chat stream with an error event instead of stop #296
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,5 +98,18 @@ def chunk(delta, finish=None) -> str: | |
| yield chunk({"audio": {"id": rid("audio"), "data": base64.b64encode(c.data).decode("ascii")}}) | ||
| elif c.modality == "image": | ||
| yield chunk({"content": media_io.png_to_data_url(c.data)}) | ||
| elif c.modality == "error": | ||
| # The request failed after the stream opened (an engine error mid | ||
| # generation, a delivery timeout); the HTTP status is committed, so | ||
| # the failure travels in-band the way the non-streaming path's | ||
| # error body does — not as a normal ``stop``, which a client would | ||
| # take for a complete answer. | ||
| yield sse({"error": { | ||
| "message": c.data.decode("utf-8", "replace"), | ||
| "type": "server_error", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type is hardcoded to "server_error", but the data worker's |
||
| "code": c.metadata.get("status", 500), | ||
| }}) | ||
| yield SSE_DONE | ||
| return | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This early return trips the (reproduced the behavior with a dummy example: prints the "finally reached: not finished") |
||
| yield chunk({}, finish="stop") | ||
| yield SSE_DONE | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this doesn't cover the timeout error, which directly raises an
HTTPExceptioniniter_result_chunks