47 lines
2.0 KiB
PHP
47 lines
2.0 KiB
PHP
<?php
|
|
header("Content-Type: application/json");
|
|
require_once __DIR__."/wevia-brain-orchestrator.php";
|
|
$raw = file_get_contents("php://input");
|
|
$d = @json_decode($raw, true);
|
|
$q = mb_strtolower(trim($d["message"] ?? $_POST["message"] ?? $_GET["m"] ?? ""));
|
|
if(!$q) die(json_encode(["error"=>"no message"]));
|
|
|
|
// 1. Try exec (infra actions)
|
|
$_POST["message"] = $q;
|
|
ob_start();
|
|
@include __DIR__ . "/wevia-exec.php";
|
|
$out = ob_get_clean();
|
|
$r = @json_decode($out, true);
|
|
if($r && !empty($r["response"]) && strpos($r["response"],"Dispo:")===false) {
|
|
die(json_encode(["response"=>"[EXEC] ".$r["response"], "engine"=>"WEVIA-Exec", "intent"=>"action"]));
|
|
}
|
|
|
|
// 2. Try smart router (intent-based IA dispatch)
|
|
|
|
// 2.5 Try orchestrator (multi-agent, UX, E2E dev)
|
|
require_once __DIR__ . "/wevia-orchestrator.php";
|
|
$orch = wevia_orchestrate($q);
|
|
if($orch) {
|
|
die(json_encode(["response"=>$orch["response"], "engine"=>$orch["engine"], "intent"=>$orch["intent"]]));
|
|
}
|
|
require_once __DIR__ . "/wevia-smart-router.php";
|
|
$sr = wevia_smart_route($q);
|
|
if($sr) {
|
|
die(json_encode(["response"=>$sr["response"], "engine"=>$sr["engine"], "intent"=>$sr["intent"]]));
|
|
}
|
|
|
|
// 3. Fallback: Groq fast
|
|
$key = trim(shell_exec("grep GROQ_KEY /etc/weval/secrets.env 2>/dev/null | cut -d= -f2"));
|
|
$ch = curl_init("https://api.groq.com/openai/v1/chat/completions");
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => 1,
|
|
CURLOPT_POSTFIELDS => json_encode(["model"=>"llama-3.3-70b-versatile","messages"=>[["role"=>"system","content"=>"Tu es WEVIA, IA souveraine de WEVAL Consulting. Reponds en francais."],["role"=>"user","content"=>$q]],"max_tokens"=>500]),
|
|
CURLOPT_RETURNTRANSFER => 1,
|
|
CURLOPT_TIMEOUT => 15,
|
|
CURLOPT_HTTPHEADER => ["Authorization: Bearer $key", "Content-Type: application/json"]
|
|
]);
|
|
$resp = curl_exec($ch); curl_close($ch);
|
|
$data = @json_decode($resp, true);
|
|
$answer = $data["choices"][0]["message"]["content"] ?? "Erreur provider";
|
|
echo json_encode(["response"=>$answer, "engine"=>"Groq/Llama-3.3-70B", "intent"=>"chat"]);
|