fix(types): default Choice/Message/StreamChunk for litellm-fixture-compat (v0.4.6)#12
Merged
Conversation
…res work
Continued litellm-fixture-compat work uncovered by dynamiq's integration
mock. The mock fixture does:
model_r = ModelResponse()
model_r["choices"][0]["message"]["content"] = mock_text
Litellm's ``ModelResponse()`` constructs with one default Choice
containing an empty assistant Message; arcllm's ``choices: list[Choice]
= []`` left choices empty, so ``[0]`` raised IndexError.
Defaults realigned with litellm:
- ``Message.role`` defaults to ``"assistant"`` (was required)
- ``Choice.index`` defaults to 0 (was required)
- ``Choice.message`` defaults via ``msgspec.field(default_factory=Message)``
- ``ChunkChoice.index`` / ``.delta`` get the same treatment
- ``ModelResponse.choices`` and ``StreamChunk.choices`` default to a
list with one empty Choice/ChunkChoice (via ``default_factory``)
Real provider responses always overwrite these — adapters set every
field on parse. The defaults exist purely to make ``ModelResponse()``
constructible-and-usable in test fixtures.
Also picks up the ruff-format whitespace fix in tests/test_exceptions.py
that landed broken in 0.4.5.
Bumps to 0.4.6.
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.
Continued litellm-fixture-compat work uncovered by dynamiq integration mocks. Defaults Message.role='assistant', Choice.index=0/Choice.message=Message(), ModelResponse.choices=[Choice()], StreamChunk.choices=[ChunkChoice()]. Real provider responses always overwrite these — defaults exist purely so ModelResponse() is constructible-and-usable in fixtures. Also picks up ruff-format whitespace fix from 0.4.5.
Note
Low Risk
Low risk: changes are limited to default field values/constructors for response type structs to improve test/fixture ergonomics, with real provider responses expected to override them.
Overview
Improves LiteLLM fixture compatibility by making
ModelResponse()/StreamChunk()constructible with a usable default shape:Message.rolenow defaults to"assistant",Choice/ChunkChoicedefaultindex=0and default-construct theirmessage/delta, andModelResponse.choices/StreamChunk.choicesdefault to a single empty choice viadefault_factory.Bumps package version to
0.4.6inarcllm/__init__.pyandpyproject.toml, with a minor test formatting tweak.Reviewed by Cursor Bugbot for commit 2dd55d6. Bugbot is set up for automated code reviews on this repo. Configure here.