fix(models): populate model_version on AnthropicLlm responses - #6850
Open
omar-infinitusai wants to merge 2 commits into
Open
fix(models): populate model_version on AnthropicLlm responses#6850omar-infinitusai wants to merge 2 commits into
omar-infinitusai wants to merge 2 commits into
Conversation
message_to_generate_content_response() and the streaming message_start handler never read the Anthropic Message.model field, so every LlmResponse AnthropicLlm produced had model_version=None. Other first-party model wrappers (google_llm, lite_llm, apigee_llm) already set this from their respective API responses; AnthropicLlm was the one path where it stayed null, which meant DatabaseSessionService- persisted events and the gen_ai.response.model telemetry attribute had no way to tell which resolved Claude snapshot served a turn. Set model_version=message.model in the non-streaming path. On the streaming path, thread event.message.model through to every yielded LlmResponse, partials included, matching lite_llm.py's parity between partial and final responses. Add real assertions on model_version for both paths (non-streaming and streaming, partial and final), not just the mock plumbing needed to give MagicMock.model a string value. Fixes google#6847
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
AnthropicLlmnever setsLlmResponse.model_version. The Anthropic APIreturns the resolved model snapshot on every response (
Message.model), butneither the non-streaming nor the streaming path reads it. Every other model
wrapper (
google_llm.py,lite_llm.py,apigee_llm.py) already populatesthis field.
Solution:
Set
model_version=message.modelinmessage_to_generate_content_response(),and thread
event.message.modelthrough the streaming path to every yieldedLlmResponse, partials included, matchinglite_llm.py's parity there.Testing Plan
Unit Tests:
Added two tests that assert on
model_versiondirectly (not just mockplumbing): one for the non-streaming response, one covering both a partial
and the final streaming response.
Manual End-to-End (E2E) Tests:
Run against the live Anthropic API by building and running package locally in an existing application.
Checklist