[BugFix] Omit empty tool_calls from OpenAI chat responses (#44105)

Signed-off-by: QwertyJack <7554089+QwertyJack@users.noreply.github.com>
Signed-off-by: Chauncey <chaunceyjiang@gmail.com>
Co-authored-by: QwertyJack <7554089+QwertyJack@users.noreply.github.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
This commit is contained in:
jack
2026-06-23 13:43:53 +08:00
committed by GitHub
co-authored by QwertyJack Chauncey
parent 3ce5823762
commit 6c427dd401
5 changed files with 133 additions and 4 deletions
@@ -353,6 +353,13 @@ class DeltaMessage(OpenAIBaseModel):
reasoning: str | None = None
tool_calls: list[DeltaToolCall] = Field(default_factory=list)
@model_serializer(mode="wrap")
def _serialize(self, handler):
data = handler(self)
if len(data.get("tool_calls", [])) == 0:
data.pop("tool_calls", None)
return data
class GenerationError(Exception):
"""raised when finish_reason indicates internal server error (500)"""