['timeout'=>3]])); echo $h ?: json_encode(['status' => 'offline', 'error' => 'DeepSeek Web API not running']); exit; } if ($_GET['action'] ?? '' === 'init') { $h = @file_get_contents('http://127.0.0.1:8901/init', false, stream_context_create(['http'=>['timeout'=>15]])); echo $h ?: json_encode(['error' => 'init failed']); exit; } if (!$message) { echo json_encode([ 'service' => 'WEVIA DeepSeek Web', 'modes' => ['instant' => 'Réponse rapide', 'deepthink' => 'Raisonnement profond (CoT)', 'search' => 'Recherche web'], 'unlimited' => true, 'cost' => '0€', 'usage' => 'POST {"message":"votre question","mode":"deepthink"}' ]); exit; } // Call internal DeepSeek Web API service $ctx = stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => 'Content-Type: application/json', 'content' => json_encode(['message' => $message, 'mode' => $mode]), 'timeout' => 90, ] ]); $response = @file_get_contents('http://127.0.0.1:8901', false, $ctx); if ($response) { $data = json_decode($response, true); // Sanitize: replace DeepSeek branding with WEVIA if (isset($data['content'])) { $data['content'] = str_replace(['DeepSeek', 'deepseek'], ['WEVIA Engine', 'wevia-engine'], $data['content']); } echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); } else { // Fallback: use existing cascade (Groq/Cerebras/Gemini) $fallback_url = 'http://127.0.0.1/api/wevia-deepseek-proxy.php'; $fallback = @file_get_contents($fallback_url, false, stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => "Content-Type: application/json\r\nHost: weval-consulting.com", 'content' => json_encode(['message' => $message, 'mode' => $mode]), 'timeout' => 30, ] ])); $data = $fallback ? json_decode($fallback, true) : ['error' => 'All providers offline']; $data['fallback'] = true; $data['note'] = 'DeepSeek Web offline, used cascade fallback'; echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); }