Files
html/api/wevia-deepseek-web.php
opus 9b19a9c38e
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
AUTO-BACKUP 20260421-1505
2026-04-21 15:05:02 +02:00

75 lines
2.8 KiB
PHP

<?php
@require_once __DIR__ . '/wevia-sanitizer-guard.php'; // WAVE 206 sanitizer guard
// WEVIA DeepSeek Web API — Proxy vers chat.deepseek.com ILLIMITÉ
// Modes: instant, deepthink, search
// Port interne: 8901
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') exit;
$input = json_decode(file_get_contents("php://input"), true);
$message = $input['message'] ?? $_GET['message'] ?? '';
$mode = $input['mode'] ?? $_GET['mode'] ?? 'instant';
if ($_GET['action'] ?? '' === 'health') {
$h = @file_get_contents('http://127.0.0.1:8901/health', false, stream_context_create(['http'=>['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);
}