35851-vm/followup.php
2025-11-19 15:51:26 +00:00

41 lines
1.5 KiB
PHP

<?php
require_once __DIR__ . '/ai/LocalAIApi.php';
$request_body = file_get_contents('php://input');
$data = json_decode($request_body, true);
$conversation = $data['conversation'] ?? null;
$analysis = $data['analysis'] ?? null;
$follow_up_question = $data['follow_up_question'] ?? null;
if ($conversation && $analysis && $follow_up_question) {
$prompt = "The user has received an initial burnout analysis and has a follow-up question. Here is the context:\n\n";
$prompt .= "**Original Survey Answers:**\n";
foreach ($conversation as $item) {
$prompt .= "Q: " . $item['question'] . "\nA: " . $item['answer'] . "\n";
}
$prompt .= "\n**Initial AI Analysis:**\n" . strip_tags($analysis) . "\n";
$prompt .= "\n**User's Follow-up Question:**\n" . $follow_up_question . "\n";
$prompt .= "Please provide a concise and helpful response to the user's question, keeping the context in mind. Format the response as simple HTML.";
$resp = LocalAIApi::createResponse(
[
'input' => [
['role' => 'system', 'content' => 'You are a helpful assistant specializing in mental health and burnout analysis.'],
['role' => 'user', 'content' => $prompt],
],
]
);
if (!empty($resp['success'])) {
echo LocalAIApi::extractText($resp);
} else {
echo "Sorry, I couldn't process your request. Please try again later.";
}
} else {
http_response_code(400);
echo "Invalid request. Missing data.";
}