60 lines
2.3 KiB
PHP
60 lines
2.3 KiB
PHP
<?php
|
|
header("Content-Type: application/json");
|
|
$path = "/var/www/html/api/ambre-tool-pdf-premium.php";
|
|
$c = @file_get_contents($path);
|
|
|
|
// Add lang detection + multi-prompt
|
|
$old_sys = '$sys = "Tu es un expert en création de rapports business premium. Pour le sujet donné, génère UNIQUEMENT un JSON valide avec cette structure exacte (pas de markdown, pas d\'explication) :';
|
|
|
|
$new_sys = '// i18n language detection (simple heuristic)
|
|
$topic_lower = mb_strtolower($topic);
|
|
$lang = $in["lang"] ?? null;
|
|
if (!$lang) {
|
|
// Detect from content
|
|
if (preg_match("/\b(the|is|are|and|of|for|to|with|on|in|a)\b/i", $topic_lower) && !preg_match("/\b(le|la|les|du|des|pour|avec)\b/i", $topic_lower)) {
|
|
$lang = "en";
|
|
} elseif (preg_match("/[\x{0600}-\x{06FF}]/u", $topic)) {
|
|
$lang = "ar";
|
|
} else {
|
|
$lang = "fr";
|
|
}
|
|
}
|
|
|
|
// Prompts by language
|
|
$prompts = [
|
|
"fr" => "Tu es un expert en création de rapports business premium. Pour le sujet donné, génère UNIQUEMENT un JSON valide avec cette structure exacte (pas de markdown, pas d\'explication) :",
|
|
"en" => "You are an expert in premium business report creation. For the given topic, generate ONLY valid JSON with this exact structure (no markdown, no explanation). All text in English :",
|
|
"ar" => "أنت خبير في إنشاء تقارير الأعمال المتميزة. للموضوع المحدد، قم بإنشاء JSON صالح فقط بهذه البنية الدقيقة (بدون markdown، بدون شرح). جميع النصوص باللغة العربية :",
|
|
];
|
|
$sys = $prompts[$lang] ?? $prompts["fr"];
|
|
$sys .= "';
|
|
|
|
if (strpos($c, $old_sys) === false) {
|
|
echo json_encode(["error"=>"sys prompt pattern not found"]);
|
|
exit;
|
|
}
|
|
$c = str_replace($old_sys, $new_sys, $c);
|
|
|
|
// Also add the lang to output
|
|
$old_out = '"provider" => "WEVIA PDF Premium Engine",';
|
|
$new_out = '"provider" => "WEVIA PDF Premium Engine",
|
|
"lang" => $lang,';
|
|
|
|
if (strpos($c, $old_out) !== false) {
|
|
$c = str_replace($old_out, $new_out, $c);
|
|
}
|
|
|
|
$backup = "/opt/wevads/vault/pdf-premium.GOLD-" . date("Ymd-His") . "-i18n";
|
|
@copy($path, $backup);
|
|
$wrote = @file_put_contents($path, $c);
|
|
|
|
// Lint
|
|
$lint = @shell_exec("php -l $path 2>&1");
|
|
|
|
echo json_encode([
|
|
"wrote" => $wrote,
|
|
"size" => strlen($c),
|
|
"backup" => basename($backup),
|
|
"lint" => trim($lint),
|
|
]);
|