'Please provide a message.']); exit; } $resp = LocalAIApi::createResponse([ 'input' => [ ['role' => 'system', 'content' => 'You are a helpful assistant for a real estate MLM company called Kutumbh Infra.'], ['role' => 'user', 'content' => $user_message], ], ]); if (!empty($resp['success'])) { $text = LocalAIApi::extractText($resp); if ($text === '') { $decoded = LocalAIApi::decodeJsonFromResponse($resp); $text = $decoded ? json_encode($decoded, JSON_UNESCAPED_UNICODE) : (string)($resp['data'] ?? ''); } $aiReply = $text; } else { error_log('AI error: ' . ($resp['error'] ?? 'unknown')); $aiReply = 'Sorry, I am having trouble connecting to the AI service.'; } header('Content-Type: application/json'); echo json_encode(['reply' => $aiReply]);