Deploy: 2026-05-24 01:32:00
This commit is contained in:
@@ -4,7 +4,7 @@ namespace App\Services;
|
||||
|
||||
class GeminiService
|
||||
{
|
||||
public const DEFAULT_MODEL = 'gemini-3.1-flash-lite';
|
||||
public const DEFAULT_MODEL = 'gemini-flash-lite-latest';
|
||||
|
||||
/**
|
||||
* Get a random Gemini API key from a comma-separated list of keys
|
||||
@@ -89,11 +89,19 @@ class GeminiService
|
||||
|
||||
if ($httpCode !== 200) {
|
||||
error_log("[Gemini API Error] HTTP " . $httpCode . " | Response: " . $response);
|
||||
return null;
|
||||
return "عذراً، الخادم الذكي يواجه ضغطاً أو مشكلة تقنية حالياً (خطأ API " . $httpCode . "). يرجى المحاولة بعد قليل.";
|
||||
}
|
||||
|
||||
$data = json_decode($response, true);
|
||||
return $data['candidates'][0]['content']['parts'][0]['text'] ?? null;
|
||||
$text = $data['candidates'][0]['content']['parts'][0]['text'] ?? null;
|
||||
|
||||
if ($text === null) {
|
||||
$reason = $data['candidates'][0]['finishReason'] ?? 'مجهول';
|
||||
error_log("[Gemini Content Error] Reason: " . $reason . " | Response: " . $response);
|
||||
return "عذراً، لم أتمكن من صياغة الرد لأسباب أمنية أو تقنية (السبب: " . $reason . ").";
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user