Update AI configuration and HTTP handling: reduce timeout settings for AI requests, implement IPv4 resolution to prevent connection issues, and enhance error messaging for better clarity on network-related errors.
This commit is contained in:
39
v4_ci4/app/Commands/RadarAiPing.php
Normal file
39
v4_ci4/app/Commands/RadarAiPing.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Libraries\Ai\AiFactory;
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
|
||||
/**
|
||||
* Test connectivité Gemini depuis le serveur (pas depuis Windows).
|
||||
* Usage : php spark radar:ai-ping
|
||||
*/
|
||||
class RadarAiPing extends BaseCommand
|
||||
{
|
||||
protected $group = 'Radar';
|
||||
protected $name = 'radar:ai-ping';
|
||||
protected $description = 'Ping API Gemini (complete court) pour valider le réseau serveur.';
|
||||
|
||||
public function run(array $params)
|
||||
{
|
||||
CLI::write('Test AiFactory → Gemini…', 'yellow');
|
||||
try {
|
||||
$ai = AiFactory::client();
|
||||
if (! $ai->isConfigured()) {
|
||||
CLI::error('Clé absente (gemini_api_key.txt)');
|
||||
|
||||
return;
|
||||
}
|
||||
CLI::write('Provider=' . $ai->provider() . ' model=' . $ai->model(), 'white');
|
||||
$t0 = \microtime(true);
|
||||
$res = $ai->complete('Réponds uniquement: PONG');
|
||||
$ms = (int) \round((\microtime(true) - $t0) * 1000);
|
||||
CLI::write('OK en ' . $ms . ' ms — ' . \mb_substr($res->text, 0, 80), 'green');
|
||||
} catch (\Throwable $e) {
|
||||
CLI::error($e->getMessage());
|
||||
CLI::write('Si timeout 0 bytes : firewall/IPv6 sortant vers generativelanguage.googleapis.com', 'yellow');
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -29,7 +29,7 @@ class Ai extends BaseConfig
|
||||
|
||||
public string $geminiBaseUrl = 'https://generativelanguage.googleapis.com/v1beta';
|
||||
|
||||
public int $timeoutSeconds = 90;
|
||||
public int $timeoutSeconds = 25;
|
||||
|
||||
public int $maxOutputTokens = 2048;
|
||||
|
||||
|
||||
@ -31,8 +31,11 @@ final class AiHttp
|
||||
$opts = [
|
||||
\CURLOPT_RETURNTRANSFER => true,
|
||||
\CURLOPT_CUSTOMREQUEST => \strtoupper($method),
|
||||
\CURLOPT_CONNECTTIMEOUT => 10,
|
||||
\CURLOPT_TIMEOUT => $timeout,
|
||||
\CURLOPT_HTTPHEADER => $headers,
|
||||
// cPanel : IPv6 cassé → hang 90s / 0 bytes. Forcer IPv4.
|
||||
\CURLOPT_IPRESOLVE => \CURL_IPRESOLVE_V4,
|
||||
];
|
||||
if ($body !== null) {
|
||||
$opts[\CURLOPT_POSTFIELDS] = $body;
|
||||
@ -43,7 +46,10 @@ final class AiHttp
|
||||
if ($res === false) {
|
||||
$err = \curl_error($ch);
|
||||
\curl_close($ch);
|
||||
throw new AiException('AI HTTP cURL: ' . $err);
|
||||
throw new AiException(
|
||||
'Serveur → Gemini timeout/réseau (' . $err . '). '
|
||||
. 'Souvent IPv6 ou firewall sortant vers generativelanguage.googleapis.com.'
|
||||
);
|
||||
}
|
||||
\curl_close($ch);
|
||||
|
||||
|
||||
@ -94,6 +94,8 @@ class GoogleWorkspaceToken
|
||||
\CURLOPT_CONNECTTIMEOUT => 8,
|
||||
\CURLOPT_TIMEOUT => 25,
|
||||
\CURLOPT_HTTPHEADER => $headers,
|
||||
// cPanel : IPv6 cassé → hang / 0 bytes. Forcer IPv4 (comme AiHttp).
|
||||
\CURLOPT_IPRESOLVE => \CURL_IPRESOLVE_V4,
|
||||
];
|
||||
if ($body !== null) {
|
||||
$opts[\CURLOPT_POSTFIELDS] = $body;
|
||||
|
||||
Reference in New Issue
Block a user