38 lines
1.9 KiB
PHP
38 lines
1.9 KiB
PHP
<?php
|
|
header("Content-Type: application/json");
|
|
$msg = json_decode(file_get_contents("php://input"), true)["message"] ?? "system status";
|
|
|
|
// Load keys
|
|
$env=[];foreach(file("/etc/weval/secrets.env") as $l){$l=trim($l);if($l&&$l[0]!=="#"&&strpos($l,"=")!==false){list($k,$v)=explode("=",$l,2);$env[trim($k)]=trim($v);}}
|
|
|
|
// Compact tool list
|
|
$tools_str = "system_status:System+docker+disk\nnonreg:Run 153 tests\narena_health:Provider health\noffice_status:Office365 comptes\nethica_stats:HCP count\nseo_check:SEO audit\ndisk_usage:Disk analysis\ncascade_status:Provider cascade\ngit_push:Push GitHub\nbackup_gold:GOLD backup\narena_budget:Budget tracker\nbrain_send:WEVADS status\nanalytics:Plausible\nsecurity_scan:SSL+ports\nl99_score:L99 framework\nhubs_status:All hubs check\ndocker_scan:Docker ports\ncron_scan:Cron jobs\narena_chat:General AI chat";
|
|
|
|
$sys = "Tu routes les messages vers des outils. Reponds UNIQUEMENT en JSON valide sans markdown:\n{\"tools\":[\"nom\"],\"summary\":\"bref\"}\nOutils:\n$tools_str";
|
|
|
|
$key = $env["GROQ_KEY"];
|
|
$ch = curl_init("https://api.groq.com/openai/v1/chat/completions");
|
|
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_POST=>true, CURLOPT_TIMEOUT=>10, CURLOPT_SSL_VERIFYPEER=>false,
|
|
CURLOPT_HTTPHEADER=>["Content-Type: application/json","Authorization: Bearer $key"],
|
|
CURLOPT_POSTFIELDS=>json_encode(["model"=>"llama-3.3-70b-versatile",
|
|
"messages"=>[["role"=>"system","content"=>$sys],["role"=>"user","content"=>$msg]],
|
|
"max_tokens"=>100,"temperature"=>0])]);
|
|
$r = curl_exec($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
$d = json_decode($r, true);
|
|
$text = $d["choices"][0]["message"]["content"] ?? "EMPTY";
|
|
|
|
// Parse
|
|
$parsed = null;
|
|
if (preg_match("/\{.*\}/s", $text, $m)) {
|
|
$parsed = json_decode($m[0], true);
|
|
}
|
|
|
|
echo json_encode([
|
|
"groq_code" => $code,
|
|
"llm_raw" => $text,
|
|
"parsed" => $parsed,
|
|
"tools" => $parsed["tools"] ?? [],
|
|
"msg" => $msg
|
|
]);
|
|
?>
|