From 596845726e852cc706ae7d53ca1db80a59911280 Mon Sep 17 00:00:00 2001 From: Mikhail Plavskiy Date: Sun, 8 Dec 2024 22:09:10 -0500 Subject: [PATCH] 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. --- litellm/types/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/litellm/types/utils.py b/litellm/types/utils.py index 168af87386..a3a85637e9 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -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