|
@@ -10,6 +10,7 @@ Functions:
|
|
|
- tool_call_result(id, content) -> dict: Creates a tool call result message with the specified ID and content.
|
|
|
- is_tool_call(message: ChatCompletionMessage) -> bool: Checks if a message is a tool call.
|
|
|
"""
|
|
|
+
|
|
|
from openai.types.chat import ChatCompletionMessage, ChatCompletionMessageToolCall
|
|
|
from openai.types.chat.chat_completion_message_tool_call import Function
|
|
|
|
|
@@ -48,11 +49,18 @@ def is_tool_call(message: ChatCompletionMessage) -> bool:
|
|
|
def merge_tool_call_delta(tool_calls, tool_call_delta):
|
|
|
if len(tool_calls) - 1 >= tool_call_delta.index:
|
|
|
tool_call = tool_calls[tool_call_delta.index]
|
|
|
- tool_call.function.arguments += tool_call_delta.function.arguments
|
|
|
+ tool_call.function.arguments += (
|
|
|
+ ""
|
|
|
+ if tool_call_delta.function.arguments is None
|
|
|
+ else tool_call_delta.function.arguments
|
|
|
+ )
|
|
|
else:
|
|
|
tool_call = ChatCompletionMessageToolCall(
|
|
|
id=tool_call_delta.id,
|
|
|
- function=Function(name=tool_call_delta.function.name, arguments=tool_call_delta.function.arguments),
|
|
|
+ function=Function(
|
|
|
+ name=tool_call_delta.function.name,
|
|
|
+ arguments=tool_call_delta.function.arguments,
|
|
|
+ ),
|
|
|
type=tool_call_delta.type,
|
|
|
)
|
|
|
tool_calls.append(tool_call)
|