fix: move thinkingConfig to root level of Gemini request body
thinkingConfig must be a top-level key in the request, NOT nested inside generationConfig. This is required for gemini-2.5-flash and newer models. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
a311a7f0d3
commit
eb6bb8e7f3
@@ -21,14 +21,17 @@ class GeminiIntentService
|
||||
$this->apiUrl = "https://generativelanguage.googleapis.com/v1beta/models/{$this->model}:generateContent";
|
||||
}
|
||||
|
||||
private function generationConfig(array $extra = []): array
|
||||
private function buildRequest(array $contents, array $genConfig = []): array
|
||||
{
|
||||
$config = array_merge(['temperature' => 0.1, 'maxOutputTokens' => 100], $extra);
|
||||
// 2.5+ models require thinkingConfig to avoid response format issues
|
||||
$body = [
|
||||
'contents' => $contents,
|
||||
'generationConfig' => array_merge(['temperature' => 0.1, 'maxOutputTokens' => 100], $genConfig),
|
||||
];
|
||||
// thinkingConfig goes at root level (NOT inside generationConfig) for 2.5+ models
|
||||
if (preg_match('/gemini-(2\.5|3[\.\d]*)/', $this->model)) {
|
||||
$config['thinkingConfig'] = ['thinkingBudget' => 0];
|
||||
$body['thinkingConfig'] = ['thinkingBudget' => 0];
|
||||
}
|
||||
return $config;
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,10 +50,9 @@ class GeminiIntentService
|
||||
try {
|
||||
$response = Http::withHeaders(['Content-Type' => 'application/json'])
|
||||
->timeout(8)
|
||||
->post("{$this->apiUrl}?key={$this->apiKey}", [
|
||||
'contents' => [['parts' => [['text' => $prompt]]]],
|
||||
'generationConfig' => $this->generationConfig(),
|
||||
]);
|
||||
->post("{$this->apiUrl}?key={$this->apiKey}",
|
||||
$this->buildRequest([['parts' => [['text' => $prompt]]]])
|
||||
);
|
||||
|
||||
$tiempoMs = (int) ((microtime(true) - $inicio) * 1000);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user