Auto commit: 2025-11-18T11:08:58.699Z
This commit is contained in:
parent
3317cb7a89
commit
86776affbc
25
api/chat.php
25
api/chat.php
@ -45,30 +45,7 @@ if ($_SESSION['question_index'] < count($questions)) {
|
|||||||
$formatted_answers[] = "Q: " . $questions[$index] . "\nA: " . $answer;
|
$formatted_answers[] = "Q: " . $questions[$index] . "\nA: " . $answer;
|
||||||
}
|
}
|
||||||
$prompt = <<<EOT
|
$prompt = <<<EOT
|
||||||
You are a burnout analysis expert. A user has answered a survey on a 1-5 scale (1='Never', 5='Always').
|
Analyze the user's survey answers and return ONLY a raw JSON object with the specified structure. Do not include any other text or formatting.
|
||||||
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:
|
User's Answers:
|
||||||
EOT;
|
EOT;
|
||||||
|
|||||||
@ -2,6 +2,8 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
const chatWindow = document.getElementById('chat-window');
|
const chatWindow = document.getElementById('chat-window');
|
||||||
const chatInput = document.getElementById('chat-input');
|
const chatInput = document.getElementById('chat-input');
|
||||||
const sendBtn = document.getElementById('send-btn');
|
const sendBtn = document.getElementById('send-btn');
|
||||||
|
const progressContainer = document.getElementById('progress-container');
|
||||||
|
const inputContainer = document.getElementById('input-container');
|
||||||
|
|
||||||
function addMessage(message, sender) {
|
function addMessage(message, sender) {
|
||||||
const messageElement = document.createElement('div');
|
const messageElement = document.createElement('div');
|
||||||
@ -50,17 +52,22 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
const data = await getNextQuestion(rating);
|
const data = await getNextQuestion(rating);
|
||||||
|
|
||||||
if (data.redirect) {
|
if (data.redirect) {
|
||||||
window.location.href = data.redirect;
|
inputContainer.style.display = 'none';
|
||||||
|
progressContainer.style.display = 'block';
|
||||||
|
// Wait a bit for the user to see the progress bar
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.href = data.redirect;
|
||||||
|
}, 2000);
|
||||||
} else if (data.question) {
|
} else if (data.question) {
|
||||||
addMessage(data.question, 'bot');
|
addMessage(data.question, 'bot');
|
||||||
|
chatInput.disabled = false;
|
||||||
|
sendBtn.disabled = false;
|
||||||
|
chatInput.focus();
|
||||||
} else if (data.message) {
|
} else if (data.message) {
|
||||||
addMessage(data.message, 'bot');
|
addMessage(data.message, 'bot');
|
||||||
chatInput.style.display = 'none';
|
chatInput.style.display = 'none';
|
||||||
sendBtn.style.display = 'none';
|
sendBtn.style.display = 'none';
|
||||||
}
|
}
|
||||||
chatInput.disabled = false;
|
|
||||||
sendBtn.disabled = false;
|
|
||||||
chatInput.focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendBtn.addEventListener('click', handleUserInput);
|
sendBtn.addEventListener('click', handleUserInput);
|
||||||
@ -79,4 +86,4 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startConversation();
|
startConversation();
|
||||||
});
|
});
|
||||||
@ -25,8 +25,11 @@ if (session_status() == PHP_SESSION_NONE) {
|
|||||||
<div class="card-body" id="chat-window" style="height: 400px; overflow-y: auto;">
|
<div class="card-body" id="chat-window" style="height: 400px; overflow-y: auto;">
|
||||||
<!-- Chat messages will be appended here -->
|
<!-- Chat messages will be appended here -->
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<div class="input-group">
|
<div id="progress-container" class="progress" style="display: none;">
|
||||||
|
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 100%">Analyzing...</div>
|
||||||
|
</div>
|
||||||
|
<div class="input-group" id="input-container">
|
||||||
<input type="text" id="chat-input" class="form-control" placeholder="Rate from 1 (Strongly Disagree) to 5 (Strongly Agree)">
|
<input type="text" id="chat-input" class="form-control" placeholder="Rate from 1 (Strongly Disagree) to 5 (Strongly Agree)">
|
||||||
<button id="send-btn" class="btn btn-primary">
|
<button id="send-btn" class="btn btn-primary">
|
||||||
<i class="bi bi-send"></i>
|
<i class="bi bi-send"></i>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user