feat: return raw bytes from call_runner for non-JSON responses - #51
Open
rickstaa wants to merge 1 commit into
Open
feat: return raw bytes from call_runner for non-JSON responses#51rickstaa wants to merge 1 commit into
rickstaa wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the last gap after #25: the buffered
call_runnerpath required every response to be a JSON object, so binary-returning apps (an image, say — the hf-inference text-to-image API returns rawimage/jpegbytes) forced a base64-in-JSON shim into every runner and client. Streaming already handled bytes (stream=True→aiter_bytes()); this brings the buffered path to parity, mirroring the familiar requests model (r.json()/r.contentvsiter_content).What
http.request_data()— same request semantics and error mapping asrequest_json, but returns(body_bytes, content_type)without assuming JSON.request_jsonis now a thin wrapper over it (fetch + parse), behavior unchanged.call_runner(non-stream): JSON content types parse intoresult.dataexactly as before (including the strict object check andsession_idpickup). Any other content type returnsresult.raw(bytes) +result.content_typeinstead of raising "expected JSON object".LiveRunnerCallResult: new optionalrawandcontent_typefields;content_typeis also set on JSON results.Compatibility
Strictly additive: every response that succeeded before behaves identically. The only changed case is one that previously raised — a non-JSON content type — which now succeeds with bytes. One edge note: a server returning JSON with a non-JSON content type (e.g. bare
text/plain) now lands inrawinstead of being parsed; aiohttp'sjson_response(what the examples use) always setsapplication/json.Why
With this, a runner that fronts a bytes-returning API needs no transform at all — the example-apps
api-proxycan drop its base64 envelope, and a runner can literally be a stock nginxproxy_pass(See livepeer/runner-app-examples#45).Tested
tests/test_call_runner_raw.py(5 cases against a live aiohttp server): JSON unchanged incl. session_id, binary → raw + content_type, invalid JSON with JSON content type still raises, JSON array still rejected, HTTP errors still raise. Full suite passes (14).