Auto commit: 2025-11-18T11:05:11.990Z
This commit is contained in:
parent
6a8221f33b
commit
3317cb7a89
31
api/chat.php
31
api/chat.php
@ -44,8 +44,35 @@ if ($_SESSION['question_index'] < count($questions)) {
|
|||||||
foreach ($_SESSION['answers'] as $index => $answer) {
|
foreach ($_SESSION['answers'] as $index => $answer) {
|
||||||
$formatted_answers[] = "Q: " . $questions[$index] . "\nA: " . $answer;
|
$formatted_answers[] = "Q: " . $questions[$index] . "\nA: " . $answer;
|
||||||
}
|
}
|
||||||
$prompt = "You are a burnout analysis expert. A user has completed a burnout survey. The user answered on a scale of 1-5 where 1 is 'Never' and 5 is 'Always'. Analyze the following survey answers and provide a detailed analysis.\n\nReturn the response as a JSON object. The JSON object must have the following keys: \"scores\", \"analysis\", \"recommendations\", and \"nextSteps\".\n\n- The 'scores' key should contain an object with 'Exhaustion', 'Cynicism', and 'Inefficacy' as keys, each with a numeric score from 0 to 5.\n- The 'analysis' key should contain an object with 'overallSummary', 'exhaustionSummary', 'cynicismSummary', and 'inefficacySummary' as keys, each containing a string with the corresponding analysis.\n- The 'recommendations' key should contain an array of objects, where each object has a 'title' and a 'description'.\n- The 'nextSteps' key should contain an array of strings.\n\nAnswers:";
|
$prompt = <<<EOT
|
||||||
$prompt .= implode("\n\n", $formatted_answers);
|
You are a burnout analysis expert. A user has answered a survey on a 1-5 scale (1='Never', 5='Always').
|
||||||
|
Analyze their answers and return ONLY a raw JSON object with the following structure:
|
||||||
|
{
|
||||||
|
"scores": {
|
||||||
|
"Exhaustion": <number>,
|
||||||
|
"Cynicism": <number>,
|
||||||
|
"Inefficacy": <number>
|
||||||
|
},
|
||||||
|
"analysis": {
|
||||||
|
"overallSummary": "<string>",
|
||||||
|
"exhaustionSummary": "<string>",
|
||||||
|
"cynicismSummary": "<string>",
|
||||||
|
"inefficacySummary": "<string>"
|
||||||
|
},
|
||||||
|
"recommendations": [
|
||||||
|
{
|
||||||
|
"title": "<string>",
|
||||||
|
"description": "<string>"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nextSteps": [
|
||||||
|
"<string>"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
User's Answers:
|
||||||
|
EOT;
|
||||||
|
$prompt .= "\n" . implode("\n", $formatted_answers);
|
||||||
|
|
||||||
$ai_response = LocalAIApi::createResponse([
|
$ai_response = LocalAIApi::createResponse([
|
||||||
'input' => [
|
'input' => [
|
||||||
|
|||||||
30
results.php
30
results.php
@ -10,6 +10,19 @@ if (!isset($_SESSION['results'])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$results = $_SESSION['results'];
|
$results = $_SESSION['results'];
|
||||||
|
|
||||||
|
// Attempt to decode if the results are a JSON string
|
||||||
|
if (is_string($results)) {
|
||||||
|
$decoded_results = json_decode($results, true);
|
||||||
|
if (json_last_error() === JSON_ERROR_NONE) {
|
||||||
|
$results = $decoded_results;
|
||||||
|
} else {
|
||||||
|
// Handle the case where the string is not valid JSON
|
||||||
|
$results = []; // Reset to a safe value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$scores = $results['scores'] ?? [];
|
$scores = $results['scores'] ?? [];
|
||||||
$analysis = $results['analysis'] ?? [];
|
$analysis = $results['analysis'] ?? [];
|
||||||
$recommendations = $results['recommendations'] ?? [];
|
$recommendations = $results['recommendations'] ?? [];
|
||||||
@ -37,6 +50,14 @@ unset($_SESSION['results']);
|
|||||||
<h1>Your Burnout Analysis</h1>
|
<h1>Your Burnout Analysis</h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
<?php if (empty($scores) || empty($analysis) || empty($recommendations) || empty($nextSteps)): ?>
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
<h4 class="alert-heading">Analysis Failed</h4>
|
||||||
|
<p>We're sorry, but there was an error generating your burnout analysis. The data we received was incomplete or corrupted.</p>
|
||||||
|
<hr>
|
||||||
|
<p class="mb-0">Please try the survey again. If the problem persists, please contact support.</p>
|
||||||
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
<?php if (!empty($analysis['overallSummary'])):
|
<?php if (!empty($analysis['overallSummary'])):
|
||||||
?>
|
?>
|
||||||
<div class="alert alert-light" role="alert">
|
<div class="alert alert-light" role="alert">
|
||||||
@ -120,7 +141,7 @@ unset($_SESSION['results']);
|
|||||||
<p>No specific next steps available at this time.</p>
|
<p>No specific next steps available at this time.</p>
|
||||||
<?php
|
<?php
|
||||||
endif; ?>
|
endif; ?>
|
||||||
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer text-center">
|
<div class="card-footer text-center">
|
||||||
<a href="index.php" class="btn btn-primary">Take the Survey Again</a>
|
<a href="index.php" class="btn btn-primary">Take the Survey Again</a>
|
||||||
@ -130,8 +151,11 @@ unset($_SESSION['results']);
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
const scores = <?php echo json_encode($scores); ?>;
|
const scores = <?php echo json_encode($scores); ?>;
|
||||||
const ctx = document.getElementById('burnoutChart').getContext('2d');
|
const canvas = document.getElementById('burnoutChart');
|
||||||
|
if (canvas) {
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
const burnoutChart = new Chart(ctx, {
|
const burnoutChart = new Chart(ctx, {
|
||||||
type: 'radar',
|
type: 'radar',
|
||||||
data: {
|
data: {
|
||||||
@ -156,6 +180,8 @@ unset($_SESSION['results']);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user