fix: add thinkingConfig for Gemini 2.5+ models
gemini-2.5-flash and newer require thinkingBudget:0 to disable thinking mode, otherwise the API rejects the request or returns unexpected format. Regex matches gemini-2.5-* and gemini-3.x-* automatically. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
75eddd16a6
commit
a311a7f0d3
@@ -107,7 +107,10 @@ class ShowConfiguracionChat extends Component
|
||||
->withHeaders(['Content-Type' => 'application/json'])
|
||||
->post("{$url}?key={$key}", [
|
||||
'contents' => [['parts' => [['text' => 'Responde solo "ok"']]]],
|
||||
'generationConfig' => ['maxOutputTokens' => 5, 'temperature' => 0],
|
||||
'generationConfig' => array_merge(
|
||||
['maxOutputTokens' => 5, 'temperature' => 0],
|
||||
preg_match('/gemini-(2\.5|3[\.\d]*)/', $model) ? ['thinkingConfig' => ['thinkingBudget' => 0]] : []
|
||||
),
|
||||
]);
|
||||
|
||||
$ms = (int) ((microtime(true) - $inicio) * 1000);
|
||||
|
||||
@@ -12,11 +12,23 @@ class GeminiIntentService
|
||||
private string $apiKey;
|
||||
private string $apiUrl;
|
||||
|
||||
private string $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->apiKey = ChatConfig::get('gemini_api_key', '');
|
||||
$model = ChatConfig::get('gemini_model', 'gemini-2.0-flash');
|
||||
$this->apiUrl = "https://generativelanguage.googleapis.com/v1beta/models/{$model}:generateContent";
|
||||
$this->model = ChatConfig::get('gemini_model', 'gemini-2.0-flash');
|
||||
$this->apiUrl = "https://generativelanguage.googleapis.com/v1beta/models/{$this->model}:generateContent";
|
||||
}
|
||||
|
||||
private function generationConfig(array $extra = []): array
|
||||
{
|
||||
$config = array_merge(['temperature' => 0.1, 'maxOutputTokens' => 100], $extra);
|
||||
// 2.5+ models require thinkingConfig to avoid response format issues
|
||||
if (preg_match('/gemini-(2\.5|3[\.\d]*)/', $this->model)) {
|
||||
$config['thinkingConfig'] = ['thinkingBudget' => 0];
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,10 +49,7 @@ class GeminiIntentService
|
||||
->timeout(8)
|
||||
->post("{$this->apiUrl}?key={$this->apiKey}", [
|
||||
'contents' => [['parts' => [['text' => $prompt]]]],
|
||||
'generationConfig' => [
|
||||
'temperature' => 0.1,
|
||||
'maxOutputTokens' => 100,
|
||||
],
|
||||
'generationConfig' => $this->generationConfig(),
|
||||
]);
|
||||
|
||||
$tiempoMs = (int) ((microtime(true) - $inicio) * 1000);
|
||||
|
||||
@@ -12,11 +12,22 @@ class GeminiVisionService
|
||||
private string $apiKey;
|
||||
private string $apiUrl;
|
||||
|
||||
private string $model;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->apiKey = ChatConfig::get('gemini_api_key', '');
|
||||
$model = ChatConfig::get('gemini_model', 'gemini-2.0-flash');
|
||||
$this->apiUrl = "https://generativelanguage.googleapis.com/v1beta/models/{$model}:generateContent";
|
||||
$this->model = ChatConfig::get('gemini_model', 'gemini-2.0-flash');
|
||||
$this->apiUrl = "https://generativelanguage.googleapis.com/v1beta/models/{$this->model}:generateContent";
|
||||
}
|
||||
|
||||
private function generationConfig(array $extra = []): array
|
||||
{
|
||||
$config = array_merge(['temperature' => 0.1, 'maxOutputTokens' => 200], $extra);
|
||||
if (preg_match('/gemini-(2\.5|3[\.\d]*)/', $this->model)) {
|
||||
$config['thinkingConfig'] = ['thinkingBudget' => 0];
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,10 +57,7 @@ class GeminiVisionService
|
||||
['inline_data' => ['mime_type' => $mimeType, 'data' => $base64]],
|
||||
],
|
||||
]],
|
||||
'generationConfig' => [
|
||||
'temperature' => 0.1,
|
||||
'maxOutputTokens' => 200,
|
||||
],
|
||||
'generationConfig' => $this->generationConfig(),
|
||||
]);
|
||||
|
||||
$tiempoMs = (int) ((microtime(true) - $inicio) * 1000);
|
||||
|
||||
Reference in New Issue
Block a user