/home/techb158/workloadmatch.com/Manager/Inc/LLMProviders
NameSizeModeActions
ClaudeProvider.php26290644editdlrm
GeminiProvider.php24910644editdlrm
OpenAIProvider.php21660644editdlrm
ProviderFactory.php19480644editdlrm
ProviderInterface.php1800644editdlrm
Edit: /home/techb158/workloadmatch.com/Manager/Inc/LLMProviders/GeminiProvider.php (2491B)
apiKey = $apiKey; $this->model = $model; } public function getName(): string { return 'gemini'; } public function sendPrompt(string $systemPrompt, string $userPrompt, array $options = []): array { $temperature = $options['temperature'] ?? 0.3; $payload = [ 'contents' => [ [ 'role' => 'user', 'parts' => [ ['text' => $systemPrompt . "\n\n" . $userPrompt], ], ], ], 'generationConfig' => [ 'temperature' => $temperature, 'responseMimeType' => 'application/json', ], ]; $url = 'https://generativelanguage.googleapis.com/v1beta/models/' . $this->model . ':generateContent?key=' . urlencode($this->apiKey); $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 60, ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = curl_error($ch); curl_close($ch); if ($error) { throw new RuntimeException("Gemini API error: $error"); } $data = json_decode($response, true); if ($httpCode !== 200) { $msg = $data['error']['message'] ?? 'Unknown error'; throw new RuntimeException("Gemini API error ($httpCode): $msg"); } $text = $data['candidates'][0]['content']['parts'][0]['text'] ?? ''; $text = trim($text); if (strpos($text, '```') !== false) { preg_match('/```(?:json)?\s*([\s\S]*?)```/', $text, $m); $text = trim($m[1] ?? $text); } $parsed = json_decode($text, true); if (!is_array($parsed)) { throw new RuntimeException("Gemini: Failed to parse JSON response: " . substr($text, 0, 200)); } return $parsed; } }