// Dodaj to do inc/config.php na końcu pliku przed ?> // ========================================== // ANTHROPIC API - optymalizacja tras AI // ========================================== define('ANTHROPIC_API_KEY', 'sk-ant-api03-TWOJ_KLUCZ'); // Wstaw swój klucz function callAnthropicAPI(string $prompt): ?array { if (!defined('ANTHROPIC_API_KEY') || ANTHROPIC_API_KEY === '' || strpos(ANTHROPIC_API_KEY, 'TWOJ') !== false) { return null; } $data = [ 'model' => 'claude-sonnet-4-20250514', 'max_tokens' => 2000, 'messages' => [ ['role' => 'user', 'content' => $prompt] ] ]; $ch = curl_init('https://api.anthropic.com/v1/messages'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'x-api-key: ' . ANTHROPIC_API_KEY, 'anthropic-version: 2023-06-01' ]); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode === 200 && $response) { $decoded = json_decode($response, true); if (isset($decoded['content'][0]['text'])) { $text = $decoded['content'][0]['text']; $jsonMatch = null; if (preg_match('/\{.*\}/s', $text, $jsonMatch)) { return json_decode($jsonMatch[0], true); } } } return null; } // ========================================== // FORMATOWANIE // ========================================== function formatFileSize(int $bytes): string { if ($bytes >= 1048576) { return number_format($bytes / 1048576, 2) . ' MB'; } elseif ($bytes >= 1024) { return number_format($bytes / 1024, 1) . ' KB'; } return $bytes . ' B'; } function calculateDistance(float $lat1, float $lon1, float $lat2, float $lon2): float { $earthRadius = 6371; // km $dLat = deg2rad($lat2 - $lat1); $dLon = deg2rad($lon2 - $lon1); $a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($dLon/2) * sin($dLon/2); $c = 2 * atan2(sqrt($a), sqrt(1-$a)); return $earthRadius * $c; }