feat(ChatCompletionDeltaToolCall): add dictionary-like access methods

Add dictionary-style access support to ChatCompletionDeltaToolCall class:
- Add __contains__ for 'in' operator support
- Add get() method with default value support
- Add __getitem__ for dict-style access

This makes the class more flexible by supporting both object and dictionary access patterns.
This commit is contained in:
Mikhail Plavskiy 2024-12-08 22:09:10 -05:00
parent 0c0498dd60
commit 596845726e

View file

@ -281,6 +281,18 @@ class ChatCompletionDeltaToolCall(OpenAIObject):
type: Optional[str] = None
index: int
def __contains__(self, key):
# Define custom behavior for the 'in' operator
return hasattr(self, key)
def get(self, key, default=None):
# Custom .get() method to access attributes with a default value if the attribute doesn't exist
return getattr(self, key, default)
def __getitem__(self, key):
# Allow dictionary-style access to attributes
return getattr(self, key)
class HiddenParams(OpenAIObject):
original_response: Optional[Union[str, Any]] = None