"error","content"=>"No message"]) . "\n\n"; exit; } function sse_send($type, $content) { echo "data: " . json_encode(["type"=>$type,"content"=>$content], JSON_UNESCAPED_UNICODE) . "\n\n"; ob_flush(); flush(); } sse_send("thinking", "Analyse en cours..."); // Call fast engine $ch = curl_init("http://127.0.0.1/api/weval-ia-fast.php"); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode(["message"=>$msg,"mode"=>"fast"]), CURLOPT_HTTPHEADER => ["Content-Type: application/json"], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, ]); $result = curl_exec($ch); curl_close($ch); $d = json_decode($result, true); $resp = $d["response"] ?? "Service en maintenance"; $prov = $d["provider"] ?? "WEVIA"; // Stream response in chunks (simulate typing) $chunks = str_split($resp, 60); foreach ($chunks as $i => $chunk) { sse_send("token", $chunk); usleep(20000); // 20ms between chunks } sse_send("provider", $prov); sse_send("done", "");