Files
wevads-platform/scripts/hamid-summarize.php
2026-02-26 04:53:11 +01:00

34 lines
1.0 KiB
PHP
Executable File

<?php
set_time_limit(300);
header('Content-Type: application/json');
$text = $_POST['text'] ?? '';
$length = $_POST['length'] ?? 'medium'; // short, medium, long
if (empty($text)) {
echo json_encode(['error' => 'Text required']);
exit;
}
$maxWords = ['short' => 50, 'medium' => 150, 'long' => 300][$length] ?? 150;
// Utiliser HAMID pour résumer
$prompt = "Résume ce texte en maximum $maxWords mots. Sois concis et garde les points essentiels:\n\n$text";
$ctx = stream_context_create([
'http' => ['method' => 'POST', 'header' => 'Content-Type: application/json',
'content' => json_encode(['message' => $prompt, 'provider' => 'mistral']), 'timeout' => 30],
'ssl' => ['verify_peer' => false, 'verify_peer_name' => false]
]);
$response = @file_get_contents("https://127.0.0.1:8443/hamid-api.php", false, $ctx);
$data = json_decode($response, true);
echo json_encode([
'success' => true,
'original_length' => strlen($text),
'summary' => $data['response'] ?? 'Erreur',
'length' => $length
]);