forked from phoenix/litellm-mirror
feat - allow ChatCompletionMessageToolCall, and Function to be used as dict
This commit is contained in:
parent
b56fa0e5c4
commit
0253c2b213
2 changed files with 32 additions and 2 deletions
|
@ -364,8 +364,6 @@ class OpenTelemetry(CustomLogger):
|
||||||
)
|
)
|
||||||
|
|
||||||
message = choice.get("message")
|
message = choice.get("message")
|
||||||
if not isinstance(message, dict):
|
|
||||||
message = message.dict()
|
|
||||||
tool_calls = message.get("tool_calls")
|
tool_calls = message.get("tool_calls")
|
||||||
if tool_calls:
|
if tool_calls:
|
||||||
span.set_attribute(
|
span.set_attribute(
|
||||||
|
|
|
@ -326,6 +326,22 @@ class Function(OpenAIObject):
|
||||||
|
|
||||||
super(Function, self).__init__(**data)
|
super(Function, self).__init__(**data)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
def __setitem__(self, key, value):
|
||||||
|
# Allow dictionary-style assignment of attributes
|
||||||
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
|
||||||
class ChatCompletionDeltaToolCall(OpenAIObject):
|
class ChatCompletionDeltaToolCall(OpenAIObject):
|
||||||
id: Optional[str] = None
|
id: Optional[str] = None
|
||||||
|
@ -385,6 +401,22 @@ class ChatCompletionMessageToolCall(OpenAIObject):
|
||||||
else:
|
else:
|
||||||
self.type = "function"
|
self.type = "function"
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
def __setitem__(self, key, value):
|
||||||
|
# Allow dictionary-style assignment of attributes
|
||||||
|
setattr(self, key, value)
|
||||||
|
|
||||||
|
|
||||||
class Message(OpenAIObject):
|
class Message(OpenAIObject):
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue