Skip to content

Commit 9599413

Browse files
authored
[BUGFIX] Properly resolve max tokens key for gemini
2 parents 929bc3a + 35507dc commit 9599413

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Classes/Provider/SymfonyAi/SymfonyAiPlatformAdapter.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,18 @@ private function buildOptions(string $model, int $maxTokens, float $temperature,
445445
}
446446

447447
/**
448-
* Resolve the max-tokens option key expected by a Symfony AI bridge based on the used bridge
448+
* Resolve the max-tokens option key expected by a Symfony AI bridge.
449+
*
450+
* Each bridge keeps the option naming convention of its underlying API:
451+
* - Gemini uses camelCase (Google REST API: "maxOutputTokens")
452+
* - OpenAI / OpenResponses use snake_case "max_output_tokens"
453+
* - Anthropic / Mistral / Ollama and most others use legacy "max_tokens"
449454
*/
450455
public static function resolveMaxTokensKey(string $factoryClass): string
451456
{
457+
if (str_contains($factoryClass, '\\Bridge\\Gemini\\')) {
458+
return 'maxOutputTokens';
459+
}
452460
if (str_contains($factoryClass, '\\Bridge\\OpenAi\\')
453461
|| str_contains($factoryClass, '\\Bridge\\OpenResponses\\')
454462
) {

Tests/Unit/Provider/SymfonyAi/SymfonyAiPlatformAdapterTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public static function maxTokensKeyProvider(): \Generator
2929
'Symfony\\AI\\Platform\\Bridge\\OpenResponses\\PlatformFactory',
3030
'max_output_tokens',
3131
];
32+
yield 'Gemini uses camelCase per Google REST API' => [
33+
'Symfony\\AI\\Platform\\Bridge\\Gemini\\PlatformFactory',
34+
'maxOutputTokens',
35+
];
3236
yield 'Anthropic Messages API' => [
3337
'Symfony\\AI\\Platform\\Bridge\\Anthropic\\PlatformFactory',
3438
'max_tokens',

0 commit comments

Comments
 (0)