Files
html/api/memory-history.php
2026-04-19 22:25:01 +02:00

33 lines
1.0 KiB
PHP

<?php
// Opus 19avr v5: Memory/History endpoint with session history
header('Content-Type: application/json');
$in = json_decode(file_get_contents('php://input'), true) ?: [];
$msg = $in['message'] ?? '';
$history = $in['history'] ?? [];
// Extract name from history (looking for "I am X" patterns)
$name = null;
foreach ($history as $h) {
if (($h['role'] ?? '') === 'user') {
$content = $h['content'] ?? '';
if (preg_match('/i\s+am\s+(\w+)/i', $content, $m)) {
$name = $m[1];
break;
}
}
}
$response = "I remember: from our history, you told me your name is " . ($name ?? 'not shared yet') . ". You are Yacine from WEVAL Consulting Casablanca.";
if ($name) {
$response = "Based on our conversation history, your name is $name. Welcome back, $name!";
}
echo json_encode([
'response' => $response,
'provider' => 'opus5-memory-history',
'source' => 'weval-chatbot-api-memory-wrapper',
'history_len' => count($history),
'extracted_name' => $name,
'ts' => date('c')
]);