/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/ClaudeProvider.php (2629B)
apiKey = $apiKey; $this->model = $model; } public function getName(): string { return 'claude'; } public function sendPrompt(string $systemPrompt, string $userPrompt, array $options = []): array { $temperature = $options['temperature'] ?? 0.3; $maxTokens = $options['max_tokens'] ?? 4096; $payload = [ 'model' => $this->model, 'system' => $systemPrompt, 'messages' => [ ['role' => 'user', 'content' => $userPrompt], ], 'temperature' => $temperature, 'max_tokens' => $maxTokens, ]; $ch = curl_init('https://api.anthropic.com/v1/messages'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'x-api-key: ' . $this->apiKey, 'anthropic-version: 2023-06-01', ], 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("Claude API error: $error"); } $data = json_decode($response, true); if ($httpCode !== 200) { $msg = $data['error']['message'] ?? 'Unknown error'; throw new RuntimeException("Claude API error ($httpCode): $msg"); } $content = ''; if (isset($data['content']) && is_array($data['content'])) { foreach ($data['content'] as $block) { if (($block['type'] ?? '') === 'text') { $content .= $block['text']; } } } if (strpos($content, '```') !== false) { preg_match('/```(?:json)?\s*([\s\S]*?)```/', $content, $m); $content = trim($m[1] ?? $content); } $parsed = json_decode($content, true); if (!is_array($parsed)) { throw new RuntimeException("Claude: Failed to parse JSON response: " . substr($content, 0, 200)); } return $parsed; } }