-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add ModelResponse.finish_reason and set provider_response_id while streaming
#2590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
4422cb0 to
35185ad
Compare
|
spell check in pre commit failed |
| if chunk.response.id and self.provider_response_id is None: | ||
| self.provider_response_id = chunk.response.id | ||
| if self.finish_reason is None: | ||
| incomplete_reason = getattr(getattr(chunk.response, 'incomplete_details', None), 'reason', None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, why do we need getattr here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using nested getattr(..., default=None) safely handles both cases without exceptions and without assuming dict access:
• getattr(chunk.response, 'incomplete_details', None) guards missing field
• getattr(..., 'reason', None) guards missing reason on that object
An alternative like (incomplete_details or {}).get('reason') won’t work reliably because incomplete_details isn’t always a dict.
e81aabc to
23f12ba
Compare
| { | ||
| **response.usage.opentelemetry_attributes(), | ||
| 'gen_ai.response.model': response_model, | ||
| events = self.instrumentation_settings.messages_to_otel_events(messages) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes shouldn't be necessary (anymore)
|
@fatelei Please merge main, there are some merge conflicts that are preventing the tests and linter to run in CI |
ModelResponse.finish_reason and set provider_response_id while streaming
# Conflicts: # uv.lock
ModelResponse.finish_reason and set provider_response_id while streamingModelResponse.finish_reason, set provider_response_id while streaming, set both on OTel spans
ModelResponse.finish_reason, set provider_response_id while streaming, set both on OTel spansModelResponse.finish_reason and set provider_response_id while streaming
fix #886