Redesign around Req.stream, step.request, stream, and adapter.stream - #554
Open
wojtekmach wants to merge 30 commits into
Open
Redesign around Req.stream, step.request, stream, and adapter.stream#554wojtekmach wants to merge 30 commits into
Req.stream, step.request, stream, and adapter.stream#554wojtekmach wants to merge 30 commits into
Conversation
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.
This is WIP.
The current design around request, response, and error steps, especially response steps, is fundamentally at odds with streaming. We cannot perform streaming decompression/decoding in response steps since by that time we've already received response body.
The other streaming solution,
into: :selfand%Req.Response.Async{} = resp.bodyis not satisfactory either as while it allows composing that enumerable, we're receiving messages to the current process with no back pressure.We're redesigning Req around arguably the best response streaming option,
Finch.stream_while/5.In this PR we're introducing a few things:
Req.stream(req, acc, fun, options \\ [])steps are now
fn req -> req,mod.request(req, next), andmod.stream(req, acc, fun, next).next, familiar to Tesla users, allows calling the rest of the pipeline.Adapter contract is now
adapter.stream(req, acc, fun)Examples
OpenAI Chat Completions
NDJSON
Reverse Proxy