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

46 lines
1.6 KiB
PHP

<?php
// HAMID API PROXY → WEVIA Fast API
// Translates hamid-api.php requests to /api/weval-ia-full format
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
if ($_SERVER["REQUEST_METHOD"] === "OPTIONS") { http_response_code(200); exit; }
$input = json_decode(file_get_contents("php://input"), true) ?: [];
$msg = $input["message"] ?? "";
$action = $input["action"] ?? "";
// Forward to weval-ia-full
$ch = curl_init("http://127.0.0.1/api/weval-ia-full");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => ["Content-Type: application/json", "Host: weval-consulting.com"],
CURLOPT_POSTFIELDS => json_encode([
"message" => $msg,
"language" => "fr",
"action" => $action,
"history" => $input["history"] ?? [],
"mode" => $input["mode"] ?? "fast"
])
]);
$resp = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($code === 200 && $resp) {
$data = json_decode($resp, true);
// Translate to hamid-api format
echo json_encode([
"response" => $data["response"] ?? "",
"provider" => $data["provider"] ?? "WEVIA",
"duration" => $data["latency_ms"] ?? 0,
"kb_count" => 0,
"model" => $data["provider"] ?? "Cerebras",
"error" => null
]);
} else {
echo json_encode(["response" => "", "error" => "API error: HTTP $code", "provider" => "none", "duration" => 0, "kb_count" => 0]);
}