Files
html/api/wevia-arena-multiagent.php
2026-04-12 22:57:03 +02:00

86 lines
2.9 KiB
PHP

<?php
// WEVAL Arena Multi-Agent — REAL execution across ALL providers
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
if ($_SERVER["REQUEST_METHOD"]==="OPTIONS"){header("Access-Control-Allow-Headers: Content-Type");exit;}
$raw = json_decode(file_get_contents("php://input"), true) ?: [];
$task = $raw["task"] ?? $raw["message"] ?? "";
$agents = $raw["agents"] ?? ["wevia-master", "nim-deepseek", "alibaba-qwen"];
$mode = $raw["mode"] ?? "parallel"; // parallel|sequential|consensus
if (!$task) { echo json_encode(["error" => "no task"]); exit; }
// Load Arena Brain context
$brain = @file_get_contents("/var/www/html/api/arena-brain.md") ?: "";
$context = substr($brain, 0, 800);
$results = [];
$t0 = microtime(true);
foreach ($agents as $agent) {
$url = "https://weval-consulting.com/api/wevia-multi-provider.php";
$body = ["message" => "[Context: $context]\n\nTask: $task", "model" => $agent];
// Special routing for master
if ($agent === "wevia-master") {
$url = "https://weval-consulting.com/api/wevia-master-api.php";
$body = ["message" => $task];
}
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($body),
CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false
]);
$at0 = microtime(true);
$r = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$ams = round((microtime(true) - $at0) * 1000);
$d = @json_decode($r, true);
$content = $d["content"] ?? "";
$provider = $d["provider"] ?? $agent;
$results[] = [
"agent" => $agent,
"provider" => $provider,
"content" => $content,
"chars" => strlen($content),
"ms" => $ams,
"status" => strlen($content) > 10 ? "success" : "failed"
];
}
$total_ms = round((microtime(true) - $t0) * 1000);
$success = array_filter($results, fn($r) => $r["status"] === "success");
// Merge results
$merged = "";
foreach ($results as $i => $r) {
if ($r["status"] === "success") {
$merged .= "### " . strtoupper($r["agent"]) . " (" . $r["chars"] . "ch, " . $r["ms"] . "ms)\n";
$merged .= $r["content"] . "\n\n---\n\n";
}
}
// Pick best for summary
usort($success, fn($a, $b) => $b["chars"] - $a["chars"]);
$best = $success[0] ?? ["content" => "No agent succeeded", "agent" => "none"];
echo json_encode([
"content" => $merged ?: $best["content"],
"best_agent" => $best["agent"],
"summary" => count($success) . "/" . count($results) . " agents succeeded",
"agents" => $results,
"total_ms" => $total_ms,
"provider" => "Arena Multi-Agent (" . count($success) . "/" . count($results) . ")",
"model" => "multi-agent-" . $mode,
"cost" => "0EUR"
]);
?>