';
+ if (!empty($resp['success'])) {
+ $aiReply = LocalAIApi::extractText($resp);
+
+ if (!empty($aiReply)) {
+ // Simple markdown to HTML
+ $formattedReply = nl2br(htmlspecialchars($aiReply));
+ $formattedReply = preg_replace('/\*\*([^*]+)\*\*/', '
$1', $formattedReply);
+ $formattedReply = preg_replace('/\*([^*]+)\*/', '
$1', $formattedReply);
+ $formattedReply = preg_replace('/`([^`]+)`/', '
$1', $formattedReply);
+ echo '
' . $formattedReply . '
';
+ } else {
+ echo '
AI analysis could not be displayed. The AI returned an empty or invalid response.
';
+ }
+ } else {
+ $error = $resp['error'] ?? 'An unknown error occurred.';
+ echo '
Could not retrieve AI analysis. Error: ' . htmlspecialchars($error) . '
';
+ }
+ echo '