Repository navigation
refactor(backends): unify mot.raw.response shape across streaming and non-streaming - #1449
Merged
ajbozarth merged 10 commits intoJul 28, 2026
Merged
Conversation
… non-streaming
Streaming responses from the OpenAI, Watsonx, and LiteLLM backends
previously stored a bare choice-level dict in mot.raw.response
({"message": …, "finish_reason": …}), while non-streaming stored a
full top-level envelope ({"choices": […], "usage": …}). Every consumer
had to branch on "choices" in response to handle both shapes.
Wrap the chat_completion_delta_merge() result in a top-level envelope
in post_processing() for all three backends:
merged = chat_completion_delta_merge(mot.raw.streamed_chunks)
mot.raw.response = {"choices": [merged], "usage": mot.generation.usage}
This makes mot.raw.response always carry the top-level shape, on both
the streaming and non-streaming paths.
Consumer simplifications:
- cli/serve/utils.py extract_finish_reason: remove the top-level
finish_reason fallback; read choices[0].finish_reason unconditionally.
- mellea/stdlib/components/chat.py _parse tool-call branch: replace
the "choices" in response guard with a direct choices[0] index.
- mellea/stdlib/components/chat.py _parse non-tool branch: replace the
dual-fallback (response.get("choices") or [{}] + response.get("message"))
with response["choices"][0].get("message", {}).
Tests:
- Update test_parse_openai_streamed_choice_shape,
test_parse_tool_calls_openai_streamed_choice_shape,
test_parse_tool_calls_openai_streamed_carries_thinking, and
test_tool_call_message_survives_formatter_to_openai_history to use
the new top-level envelope shape.
- Replace test_litellm_per_choice_dict_fallback with
test_litellm_normalized_streaming_shape.
- Add test_openai_streaming_normalized_shape and
test_watsonx_streaming_normalized_shape to test_serve_utils.py.
- Add test_parse_openai_streaming_normalized_shape and
test_parse_tool_calls_openai_streaming_normalized_shape to test_chat.py.
- Add test/backends/test_openai_post_processing.py,
test_watsonx_post_processing.py, and test_litellm_post_processing.py
with post_processing shape assertions and usage/canary tests.
Signed-off-by: Vishal V <[email protected]>
ajbozarth
requested changes
Jul 27, 2026
ajbozarth
left a comment
Member
There was a problem hiding this comment.
Thanks for the contribution, overall it LGTM, but I did note a bunch of tiny "nits" to fix, all in docstrings and comments, but some important to not regress
Comment on lines
-628
to
-630
| # OpenAI-like streamed responses potentially give you chunks of tool calls. | ||
| # As a result, we have to store data between calls and only then | ||
| # check for complete tool calls in the post_processing step. |
Member
There was a problem hiding this comment.
IIUC these comment lines should stay, only the last 2 are about the code being removed
Comment on lines
-1132
to
-1134
| # OpenAI streamed responses give you chunks of tool calls. | ||
| # As a result, we have to store data between calls and only then | ||
| # check for complete tool calls in the post_processing step. |
Comment on lines
-613
to
-615
| # OpenAI streamed responses give you chunks of tool calls. | ||
| # As a result, we have to store data between calls and only then | ||
| # check for complete tool calls in the post_processing step. |
Co-authored-by: Alex Bozarth <[email protected]> Signed-off-by: Vishal V <[email protected]>
Co-authored-by: Alex Bozarth <[email protected]> Signed-off-by: Vishal V <[email protected]>
Co-authored-by: Alex Bozarth <[email protected]> Signed-off-by: Vishal V <[email protected]>
Co-authored-by: Alex Bozarth <[email protected]> Signed-off-by: Vishal V <[email protected]>
Co-authored-by: Alex Bozarth <[email protected]> Signed-off-by: Vishal V <[email protected]>
Co-authored-by: Alex Bozarth <[email protected]> Signed-off-by: Vishal V <[email protected]>
Co-authored-by: Alex Bozarth <[email protected]> Signed-off-by: Vishal V <[email protected]>
Co-authored-by: Alex Bozarth <[email protected]> Signed-off-by: Vishal V <[email protected]>
…reaming and non-streaming difference Signed-off-by: Vishal V <[email protected]>
cptnm3
force-pushed
the
unify-mot-raw-response
branch
from
July 28, 2026 08:38
b42351c to
8815482
Compare
Contributor
Author
|
@ajbozarth thanks for the review! I have applied all the suggestions. Please take a look. |
ajbozarth
approved these changes
Jul 28, 2026
ajbozarth
left a comment
Member
There was a problem hiding this comment.
Thanks for the great work, this was exactly what I had intended to do when opening the issue(with a lot more tests than I probably would have added)
@jakelorocco if you want to take a quick sanity check that this follows what you envisioned, if you're happy feel free to add to the merge queue
jakelorocco
approved these changes
Jul 28, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Jul 28, 2026
Merged
via the queue into
generative-computing:main
with commit Jul 28, 2026
d72a319
10 checks passed
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.
Pull Request
Issue
Fixes #1330
Description
Streaming responses from the OpenAI, Watsonx, and LiteLLM backends previously stored a bare choice-level dict in mot.raw.response ({"message": …, "finish_reason": …}), while non-streaming stored a full top-level envelope ({"choices": […], "usage": …}). Every consumer had to branch on "choices" in response to handle both shapes.
Wrap the chat_completion_delta_merge() result in a top-level envelope in post_processing() for all three backends:
This makes mot.raw.response always carry the top-level shape, on both the streaming and non-streaming paths.
Consumer simplifications:
Tests:
Testing
Attribution
Adding a new component, requirement, sampling strategy, or tool?
If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.
NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.