From 35507dc507d83cca556a76d2a1e79e1a0e954c9e Mon Sep 17 00:00:00 2001 From: Oliver Bartsch Date: Tue, 12 May 2026 21:24:49 +0200 Subject: [PATCH] [BUGFIX] Properly resolve max tokens key for gemini --- .../Provider/SymfonyAi/SymfonyAiPlatformAdapter.php | 10 +++++++++- .../SymfonyAi/SymfonyAiPlatformAdapterTest.php | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Classes/Provider/SymfonyAi/SymfonyAiPlatformAdapter.php b/Classes/Provider/SymfonyAi/SymfonyAiPlatformAdapter.php index 8a6e041..97b4f7b 100644 --- a/Classes/Provider/SymfonyAi/SymfonyAiPlatformAdapter.php +++ b/Classes/Provider/SymfonyAi/SymfonyAiPlatformAdapter.php @@ -445,10 +445,18 @@ private function buildOptions(string $model, int $maxTokens, float $temperature, } /** - * Resolve the max-tokens option key expected by a Symfony AI bridge based on the used bridge + * Resolve the max-tokens option key expected by a Symfony AI bridge. + * + * Each bridge keeps the option naming convention of its underlying API: + * - Gemini uses camelCase (Google REST API: "maxOutputTokens") + * - OpenAI / OpenResponses use snake_case "max_output_tokens" + * - Anthropic / Mistral / Ollama and most others use legacy "max_tokens" */ public static function resolveMaxTokensKey(string $factoryClass): string { + if (str_contains($factoryClass, '\\Bridge\\Gemini\\')) { + return 'maxOutputTokens'; + } if (str_contains($factoryClass, '\\Bridge\\OpenAi\\') || str_contains($factoryClass, '\\Bridge\\OpenResponses\\') ) { diff --git a/Tests/Unit/Provider/SymfonyAi/SymfonyAiPlatformAdapterTest.php b/Tests/Unit/Provider/SymfonyAi/SymfonyAiPlatformAdapterTest.php index 02e347b..071e569 100644 --- a/Tests/Unit/Provider/SymfonyAi/SymfonyAiPlatformAdapterTest.php +++ b/Tests/Unit/Provider/SymfonyAi/SymfonyAiPlatformAdapterTest.php @@ -29,6 +29,10 @@ public static function maxTokensKeyProvider(): \Generator 'Symfony\\AI\\Platform\\Bridge\\OpenResponses\\PlatformFactory', 'max_output_tokens', ]; + yield 'Gemini uses camelCase per Google REST API' => [ + 'Symfony\\AI\\Platform\\Bridge\\Gemini\\PlatformFactory', + 'maxOutputTokens', + ]; yield 'Anthropic Messages API' => [ 'Symfony\\AI\\Platform\\Bridge\\Anthropic\\PlatformFactory', 'max_tokens',