From cb689e436d5ed770d93b0e20cf9436fc255a4f60 Mon Sep 17 00:00:00 2001 From: Michelangelo Mori <328978+blkt@users.noreply.github.com> Date: Fri, 4 Apr 2025 14:17:46 +0200 Subject: [PATCH] Fix Anthropic serialization bug. Excluding defaults caused `tool_choice` to become an empty dictionary in case `{"type": "auto"}` was explicitly provider by the client. Also, we were using the wrong method. --- src/codegate/types/anthropic/_generators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codegate/types/anthropic/_generators.py b/src/codegate/types/anthropic/_generators.py index 64c99229..31362edd 100644 --- a/src/codegate/types/anthropic/_generators.py +++ b/src/codegate/types/anthropic/_generators.py @@ -117,7 +117,7 @@ async def acompletion(request, api_key, base_url): "accept": "application/json", "content-type": "application/json", } - payload = request.json(exclude_defaults=True) + payload = request.model_dump_json(exclude_none=True, exclude_unset=True) if os.getenv("CODEGATE_DEBUG_ANTHROPIC") is not None: print(payload)