Fix OpenAI stream wrapper attribute delegation#1098
Closed
devin-ai-integration[bot] wants to merge 5 commits intomainfrom
Closed
Fix OpenAI stream wrapper attribute delegation#1098devin-ai-integration[bot] wants to merge 5 commits intomainfrom
devin-ai-integration[bot] wants to merge 5 commits intomainfrom
Conversation
- Add __getattr__ method to OpenAIAsyncStreamWrapper and OpenaiStreamWrapper - Fixes 'choices' attribute error when accessing stream attributes - Follows existing pattern from agno instrumentor for attribute delegation - Enables transparent access to underlying stream properties like choices, model, id Co-Authored-By: Alex <meta.alex.r@gmail.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
- Test __getattr__ method in both OpenaiStreamWrapper and OpenAIAsyncStreamWrapper - Verify proper delegation of choices, model, id, and usage attributes - Test AttributeError handling for missing attributes - Addresses codecov/patch coverage requirement for PR #1098 Co-Authored-By: Alex <meta.alex.r@gmail.com>
- Consolidate multi-line imports to single line - Remove trailing whitespace - Format list definitions for consistency - Addresses pre-commit checks failure in PR #1098 Co-Authored-By: Alex <meta.alex.r@gmail.com>
…pper-choices-attribute
…pper-choices-attribute
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.
Fix OpenAI Stream Wrapper Attribute Delegation
Fixes #1101
Problem
Users integrating AgentOps with ChainLit and other frameworks were encountering the error:
This occurred when code tried to access attributes like
choiceson OpenAI streaming responses that were wrapped by AgentOps instrumentation.Root Cause
The
OpenAIAsyncStreamWrapperandOpenaiStreamWrapperclasses act as proxies around OpenAI stream objects but didn't implement__getattr__to delegate attribute access to the underlying stream. When code accessedstream.choices, Python looked for the attribute on the wrapper class, couldn't find it, and raised anAttributeError.Solution
Added
__getattr__method to both wrapper classes following the established pattern in the codebase (similar toagentops/instrumentation/agentic/agno/instrumentor.py):This ensures any attribute not explicitly defined on the wrapper gets forwarded to the underlying stream object, making the wrapper transparent to users.
Changes
__getattr__method toOpenAIAsyncStreamWrapperclass__getattr__method toOpenaiStreamWrapperclass (sync version) for consistencyself._streamTesting
choices,model,id, and other stream attributesCompatibility
Link to Devin run: https://app.devin.ai/sessions/37821e78215c47a2965b384be6169155
Requested by: Alex (meta.alex.r@gmail.com)