Deploy on 2026-06-05 17:13:07

This commit is contained in:
Hamza-Ayed
2026-06-05 17:13:07 +03:00
parent 227fd7c412
commit d05e18b59d
3 changed files with 124 additions and 37 deletions

View File

@@ -8,6 +8,7 @@ class AiAnalyzer
{
private ?string $apiKey;
private string $model;
private static ?float $lastCallTime = null;
public function __construct()
{
@@ -108,6 +109,16 @@ PROMPT;
*/
private function callGemini(string $prompt): string
{
if (self::$lastCallTime !== null) {
$elapsed = microtime(true) - self::$lastCallTime;
$minInterval = 4.5; // Space out requests to under 15 RPM
if ($elapsed < $minInterval) {
$sleepTime = $minInterval - $elapsed;
usleep((int)($sleepTime * 1000000));
}
}
self::$lastCallTime = microtime(true);
$url = "https://generativelanguage.googleapis.com/v1beta/models/{$this->model}:generateContent?key={$this->apiKey}";
$payload = json_encode([