mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(autogpt/llm): Omit AssistantChatMessage.tool_calls if no tool calls are present
OpenAI likes neither `tool_calls=[]` nor `tool_calls=None`. If no `tool_calls` are in the message, the key must be omitted.
This partially reverts commit 67bafa6302.
---
Co-authored-by: kcze <kpczerwinski@gmail.com>
This commit is contained in:
@@ -423,7 +423,7 @@ class OpenAIProvider(
|
||||
tool_calls=(
|
||||
[AssistantToolCall(**tc.dict()) for tc in _assistant_msg.tool_calls]
|
||||
if _assistant_msg.tool_calls
|
||||
else list()
|
||||
else None
|
||||
),
|
||||
)
|
||||
response = ChatModelResponse(
|
||||
@@ -570,7 +570,10 @@ class OpenAIProvider(
|
||||
messages: list[ChatMessage], *_, **kwargs
|
||||
) -> ChatCompletion:
|
||||
raw_messages = [
|
||||
message.dict(include={"role", "content", "tool_calls", "name"})
|
||||
message.dict(
|
||||
include={"role", "content", "tool_calls", "name"},
|
||||
exclude_none=True,
|
||||
)
|
||||
for message in messages
|
||||
]
|
||||
return await self._client.chat.completions.create(
|
||||
|
||||
@@ -91,7 +91,7 @@ class AssistantToolCallDict(TypedDict):
|
||||
class AssistantChatMessage(ChatMessage):
|
||||
role: Literal["assistant"] = "assistant"
|
||||
content: Optional[str]
|
||||
tool_calls: list[AssistantToolCall] = Field(default_factory=list)
|
||||
tool_calls: Optional[list[AssistantToolCall]] = None
|
||||
|
||||
|
||||
class AssistantChatMessageDict(TypedDict, total=False):
|
||||
|
||||
Reference in New Issue
Block a user