Files
html/api/weval-ia-local.php
2026-04-12 22:57:03 +02:00

41 lines
1.8 KiB
PHP

<?php
set_time_limit(50);
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit; }
if ($_SERVER['REQUEST_METHOD'] === 'GET') { die(json_encode(['status'=>'ok','engine'=>'granite4 local'])); }
$in = json_decode(file_get_contents('php://input'), true) ?: [];
$msg = trim($in['message'] ?? '');
if (strlen($msg) < 2) { die(json_encode(['error'=>'message required'])); }
if (preg_match('/(image|photo|visuel|genere.*image|futuris)/i', $msg)) {
die(json_encode(['response'=>"![Image](https://picsum.photos/seed/wevia/1024/768)",'provider'=>'Picsum (local)','sources'=>[]]));
}
$ch = curl_init('http://151.80.235.110:11434/api/chat');
curl_setopt_array($ch, [
CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 45, CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode([
'model' => 'granite4',
'messages' => [
['role'=>'system','content'=>'Tu es WEVIA, assistant IA souverain. Reponds en francais, structure avec markdown, tableaux et code mermaid quand pertinent.'],
['role'=>'user','content'=>mb_substr($msg,0,1500)]
],
'stream' => false, 'think' => false,
'options' => ['num_predict'=>400,'temperature'=>0.7]
])
]);
$r = curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);
if ($code == 200 && $r) {
$d = json_decode($r, true);
$t = trim($d['message']['content'] ?? '');
if (strlen($t) > 10) {
die(json_encode(['response'=>$t,'provider'=>'S151 granite4 (CPU local)','sources'=>[]]));
}
}
die(json_encode(['response'=>'S151 granite4 timeout/error','provider'=>'error','sources'=>[]]));