perf: drop unnecessary none-value fields in tool call loop (#4213)

This commit is contained in:
Soulter
2025-12-26 21:12:34 +08:00
committed by GitHub
parent 19541d9d07
commit bd1b0a2836
+9
View File
@@ -169,6 +169,15 @@ class Message(BaseModel):
)
return self
@model_serializer(mode="wrap")
def serialize(self, handler):
data = handler(self)
if self.tool_calls is None:
data.pop("tool_calls", None)
if self.tool_call_id is None:
data.pop("tool_call_id", None)
return data
class AssistantMessageSegment(Message):
"""A message segment from the assistant."""