feat(gemini): expose finish_reason and model_version on StreamingCompletionResponse#1776
Merged
Merged
Conversation
…letionResponse Both fields were being deserialized from the Gemini SSE stream but dropped before the FinalResponse was yielded to callers. Surfaces them for PostHog LLM Analytics ($ai_stop_reason, $ai_model). Also fixes a subtle bug: when the final chunk carries finishReason without content (common in Gemini's streaming protocol), the stream now correctly breaks instead of continuing to wait for more events. RIG-1315 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nResponse The Interactions API does not have a FinishReason equivalent (uses InteractionStatus lifecycle values instead). Surfaces model_version extracted from Interaction.model for symmetry with the Generate Content streaming path. RIG-1315 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
LGTM, gonna add a live regression test as a follow up PR |
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.
Summary
finish_reason: Option<FinishReason>andmodel_version: Option<String>togemini::streaming::StreamingCompletionResponse— both were deserialized from the SSE stream but dropped before theFinalResponsewas yielded to callersmodel_version: Option<String>togemini::interactions_api::streaming::StreamingCompletionResponse, extracted fromInteraction.modelfinishReasonwith nocontent(a common protocol pattern), the stream now correctly breaks instead of continuing to wait for more eventsFinishReasonequivalent (it usesInteractionStatuslifecycle values); onlymodel_versionis added for that path, with a doc comment explaining whyMotivation
Ryzome's PostHog LLM Analytics forwarder needs
$ai_stop_reason(fromfinish_reason) and the resolved model string$ai_model(frommodel_version, which is the exact model likegemini-2.5-pro-preview-05-06rather than the alias the caller requested).Test Plan
test_streaming_completion_response_has_finish_reason_and_model_versioningemini/streaming.rsasserts both fields populate and roundtrip through serde correctlytest_streaming_completion_response_has_model_versionininteractions_api/streaming.rsassertsmodel_versionpopulates and roundtripsCloses RIG-1315