send_request($message); if ($response) { error_log('OpenAI API Response: ' . wp_json_encode($response)); } if ($response && isset($response['choices'][0]['message']['content'])) { // Save the user message and the response in session if (!isset($_SESSION['chat_history'])) { $_SESSION['chat_history'] = array(); } $_SESSION['chat_history'][] = [ 'user_message' => $message, 'bot_response' => $response['choices'][0]['message']['content'], ]; echo esc_html($response['choices'][0]['message']['content']); } else { echo 'Could not retrieve a response. Please try again.'; } wp_die(); // This is required to terminate immediately and return a proper response } function get_chat_history() { if (!session_id()) session_start(); if (isset($_SESSION['chat_history'])) { $history = wp_json_encode($_SESSION['chat_history']); echo wp_kses_post($history); } else { echo wp_json_encode([]); } wp_die(); } function boai_chat_simulator_text_field_0_render() { $options = get_option('boai_chat_simulator_settings'); error_log(wp_json_encode($options)); ?> '>