diff --git a/api/chat.php b/api/chat.php index a38a0f6..e0d634e 100644 --- a/api/chat.php +++ b/api/chat.php @@ -44,8 +44,35 @@ if ($_SESSION['question_index'] < count($questions)) { foreach ($_SESSION['answers'] as $index => $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 .= implode("\n\n", $formatted_answers); + $prompt = <<, + "Cynicism": , + "Inefficacy": + }, + "analysis": { + "overallSummary": "", + "exhaustionSummary": "", + "cynicismSummary": "", + "inefficacySummary": "" + }, + "recommendations": [ + { + "title": "", + "description": "" + } + ], + "nextSteps": [ + "" + ] +} + +User's Answers: +EOT; +$prompt .= "\n" . implode("\n", $formatted_answers); $ai_response = LocalAIApi::createResponse([ 'input' => [ diff --git a/results.php b/results.php index 40844a7..3136afa 100644 --- a/results.php +++ b/results.php @@ -10,6 +10,19 @@ if (!isset($_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'] ?? []; $analysis = $results['analysis'] ?? []; $recommendations = $results['recommendations'] ?? []; @@ -37,6 +50,14 @@ unset($_SESSION['results']);

Your Burnout Analysis

+ + +