Merge pull request #3379 from elisalimli/main

[chore] Improve type-safety in Message & Delta classes
This commit is contained in:
Krish Dholakia 2024-05-01 21:19:52 -07:00 committed by GitHub
commit 24fc934622
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -378,13 +378,16 @@ class Message(OpenAIObject):
super(Message, self).__init__(**params)
self.content = content
self.role = role
self.tool_calls = []
self.function_call = None
if function_call is not None:
self.function_call = FunctionCall(**function_call)
if tool_calls is not None:
self.tool_calls = []
for tool_call in tool_calls:
self.tool_calls.append(ChatCompletionMessageToolCall(**tool_call))
self.tool_calls = [
ChatCompletionMessageToolCall(**tool_call) for tool_call in tool_calls
]
if logprobs is not None:
self._logprobs = ChoiceLogprobs(**logprobs)
@ -407,9 +410,10 @@ class Message(OpenAIObject):
except:
# if using pydantic v1
return self.dict()
class Delta(OpenAIObject):
tool_calls: Optional[List[ChatCompletionDeltaToolCall]]
def __init__(
self,
content=None,