$msg, 'response' => mb_substr($result['content'], 0, 500), 'model' => $result['model'], 'provider' => $result['provider'], 'tier' => $result['tier'], 'latency_ms' => $result['latency_ms'], 'source' => $result['source'], 'routing' => $result['routing'] ?? null, ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); exit; case 'score': $msg = $_GET['q'] ?? ''; if (empty($msg)) { echo json_encode(['error' => 'Pass ?score&q=your+message']); exit; } echo json_encode(mr_scoreComplexity($msg), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); exit; case 'capabilities': $caps = wevia_listCapabilities(); // Wire dormant capabilities from registry $dormFile = '/opt/wevia-brain/wevia-master-capabilities.json'; if (file_exists($dormFile)) { $dorm = json_decode(file_get_contents($dormFile), true); $caps['dormant_capabilities'] = $dorm['summary'] ?? []; $caps['total_capabilities'] = ($dorm['total'] ?? 0) + count($caps); $caps['dormant_categories'] = array_keys($dorm['categories'] ?? []); } echo json_encode($caps, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); exit; case 'rag': $msg = $_GET['q'] ?? 'Comment fonctionne WEVADS?'; $rag = rag_search($msg); echo json_encode($rag, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); exit; case 'dashboard': header("Content-Type: text/html; charset=utf-8"); $stats = mr_getStats(); $health = mr_healthCheck(); ?>
| Date | Total | Tier 0 (local) | Tier 1 (fast) | Tier 2 (quality) | Latence moy. | Coût |
|---|---|---|---|---|---|---|
| $date | {$total} | "; echo "{$t0} ({$pct0}%) | "; echo "{$t1} | {$t2} | "; echo "{$d['avg_latency']}ms | {$d['cost']}€ |
Exemples:
curl "=$_SERVER['HTTP_HOST']?>/api/wevia-master-api.php?test&q=Bonjour" curl "=$_SERVER['HTTP_HOST']?>/api/wevia-master-api.php?score&q=Explique+comment+optimiser+nginx" curl "=$_SERVER['HTTP_HOST']?>/api/wevia-master-api.php?health"
TIER 0 (Souverain, 0€) → Ollama:11435 [weval-brain-v2, qwen2.5:7b, qwen3:4b, mistral, medllama2] TIER 1 (Free ultra-fast) → Cerebras, Groq, SambaNova TIER 2 (Free quality) → Mistral Cloud, Cohere, Gemini TIER 3 (Frontier, payant) → Claude API, GPT API (non implémenté — dernier recours)
$c) echo "TIER1 $n: {$c['model']} ({$c['speed']})\n";
$t2 = mr_getTier2Providers();
foreach ($t2 as $n => $c) echo "TIER2 $n: {$c['model']} ({$c['speed']})\n";
?>
WEVIA Master Router — WEVAL Consulting — Avril 2026
'POST required. Try ?health, ?stats, ?test, ?dashboard']); exit; } // Debug: log raw input $rawInput = file_get_contents("php://input"); @file_put_contents("/tmp/master-debug.log", date("H:i:s")." RAW=".substr($rawInput,0,200)."\n", FILE_APPEND); $input = json_decode($rawInput, true); $message = $input['message'] ?? $input['msg'] ?? $input['content'] ?? ''; $system = $input['system'] ?? 'Tu es WEVIA, l\'IA cognitive souveraine de WEVAL Consulting.'; $history = $input['history'] ?? []; $options = $input['options'] ?? []; if (empty(trim($message))) { echo json_encode(['error' => 'message required']); exit; } ob_start(); try { $result = mr_route($message, $system, $history, $options); $stray = ob_get_clean(); if (!$result || empty($result)) { echo json_encode(['error'=>'empty_result','stray_output'=>substr($stray,0,500),'provider'=>'unknown','response'=>'']); } else { // Ensure response key exists for admin compatibility if (!isset($result['response']) && isset($result['content'])) { $result['response'] = $result['content']; } $json = json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); if ($json === false) { // JSON encode failed - likely UTF8 issue array_walk_recursive($result, function(&$v){if(is_string($v))$v=mb_convert_encoding($v,'UTF-8','UTF-8');}); $json = json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE); } echo $json; } } catch (\Throwable $e) { $stray = ob_get_clean(); echo json_encode(['error'=>$e->getMessage(),'file'=>basename($e->getFile()),'line'=>$e->getLine(),'stray'=>substr($stray,0,200)]); }