Repository navigation
Stream server-sent events from Python SDK methods that declare them - #62
JaviChulvi wants to merge 1 commit into
Conversation
|
👋 Hello @JaviChulvi, thank you for submitting a
For more guidance, please refer to our Contributing Guide. Don't hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀 |
UltralyticsAssistant
left a comment
There was a problem hiding this comment.
🔍 PR Review
Made with ❤️ by Ultralytics Actions
Reviewed the Python generator, event-stream parsing and lifecycle, and OpenAPI media detection. I found no concrete regressions; LGTM.
UltralyticsAssistant
left a comment
There was a problem hiding this comment.
🔍 PR Review 2
Made with ❤️ by Ultralytics Actions
Since review 1, there were no findings left open. I rechecked the Python streaming request path, event parsing and cleanup, and OpenAPI media detection; I found no new concrete regressions. LGTM.
|
Closing this: we no longer need the streaming parameters. VLM 4B inference merged in ultralytics/portal#5465 through the shared model predict route ( |
An operation can answer with server-sent events, for example a
stream=truerequest whose successful response liststext/event-streamnext toapplication/json. Today the generated Python client buffers the whole body and returns one string such as"data: {...}\n\ndata: {...}\n\n", so a caller sees nothing until the stream ends and then has to parse it.Operations whose successful responses declare
text/event-streamnow return a generator of events when the server actually streams. Each event'sdatais decoded as JSON when it is JSON, and as a string otherwise. When the same operation answers JSON, it behaves exactly as before.httpx.Client.request(), so custom clients, hooks and retries behave as before. Stream-capable calls usesend(..., stream=True)and read the body as before when the response is not an event stream (including 204 and errors).close()/aclose(), even before the first event, and on errors.data, comments and other fields ignored, an unterminated final event dropped.Response | collections.abc.Generator[Any, None, None](AsyncGeneratorfor the async client), and the docstring says to close the generator to stop early.Known limit: an operation declaring JSON under one success status and an event stream under another is still rejected as mixed successful media, as it was before this change.
main)stream=trueagainst a live event-stream APIasync for, first at 0.81 sstreamclose()after the first eventstream=trueAPIErrorwith status and bodydatabun run typecheck,lint,knipand all 22 tests pass; Ruff andcompileallpass on the generated package. Live checks ran against a Platform preview deployment; the SDK's own test suite passes on the regenerated output.🛠️ PR Summary
Made with ❤️ by Ultralytics Actions
🌟 Summary
Generated Python SDK methods whose successful OpenAPI responses declare
text/event-streamnow yield events as they arrive, while retaining the existing response handling for non-stream replies.📊 Key Changes
🎯 Purpose & Impact