Open AI API Key is not set, the chat app will not load on the front end until API Key is set. Please visit → Open AI to create an api key.";
aichwp_unschedule_initial_embeddings();
}
else {
try {
$openAi = new OpenAIChat(['temperature' => 0.8]);
$response = $openAi->generateResultString(['This is a test. Reply and nothing else.']);
$is_stale = get_option('aichwp_post_embeddings_are_stale');
$is_running = get_option('aichwp_create_initial_embeddings_running');
if ($is_stale == 1 && $is_running == 0) {
aichwp_create_initial_embeddings();
sleep(0.2);
}
} catch (Exception $e) {
echo "
Open AI Key is not functioning correctly, please check the key for validity.
";
aichwp_unschedule_initial_embeddings();
}
}
?>
'#f3f4f6',
'aichwpAIChatMessageBgColor' => '#3c82f6',
'aichwpAIChatMessageTextColor' => '#ffffff',
'aichwpUserChatMessageBgColor' => '#ffffff',
'aichwpUserChatMessageTextColor' => '#001827',
'aichwpChatClearChatTextColor' => '#4b5563',
'aichwpUserAvatarColor' => '#001827',
'aichwpLoadingIconColor' => '#3c82f6',
'aichwpSendButtonColor' => '#3c82f6',
'aichwpSendButtonTextColor' => '#ffffff',
'aichwpChatOpenButtonColor' => '#3c82f6',
);
// Check each default color to see if it's already set
foreach ($default_colors as $color => $default_value) {
if (empty($options[$color])) {
$options[$color] = $default_value;
$options_update_needed = true;
}
}
// Add settings fields for each color
add_settings_field('aichwp_bg_color', 'Bg Color', 'aichwp_color_field', 'aichwp', 'aichwp_colors', ['color' => 'aichwpBgColor']);
add_settings_field('aichwp_ai_chat_message_bg_color', 'AI Chat Message Bg Color', 'aichwp_color_field', 'aichwp', 'aichwp_colors', ['color' => 'aichwpAIChatMessageBgColor']);
add_settings_field('aichwp_ai_chat_message_text_color', 'AI Chat Message Text Color', 'aichwp_color_field', 'aichwp', 'aichwp_colors', ['color' => 'aichwpAIChatMessageTextColor']);
add_settings_field('aichwp_user_chat_message_bg_color', 'User Chat Message Bg Color', 'aichwp_color_field', 'aichwp', 'aichwp_colors', ['color' => 'aichwpUserChatMessageBgColor']);
add_settings_field('aichwp_user_chat_message_text_color', 'User Chat Message Text Color', 'aichwp_color_field', 'aichwp', 'aichwp_colors', ['color' => 'aichwpUserChatMessageTextColor']);
add_settings_field('aichwp_clear_chat_text_color', 'Clear Chat Text Color', 'aichwp_color_field', 'aichwp', 'aichwp_colors', ['color' => 'aichwpChatClearChatTextColor']);
add_settings_field('aichwp_user_avatar_color', 'User Avatar Color', 'aichwp_color_field', 'aichwp', 'aichwp_colors', ['color' => 'aichwpUserAvatarColor']);
add_settings_field('aichwp_loading_icon_color', 'Loading Icon Color', 'aichwp_color_field', 'aichwp', 'aichwp_colors', ['color' => 'aichwpLoadingIconColor']);
add_settings_field('aichwp_send_button_color', 'Send Button Color', 'aichwp_color_field', 'aichwp', 'aichwp_colors', ['color' => 'aichwpSendButtonColor']);
add_settings_field('aichwp_send_button_text_color', 'Send Button Text Color', 'aichwp_color_field', 'aichwp', 'aichwp_colors', ['color' => 'aichwpSendButtonTextColor']);
add_settings_field('aichwp_chat_open_button_color', 'Chat Open Button Color', 'aichwp_color_field', 'aichwp', 'aichwp_colors', ['color' => 'aichwpChatOpenButtonColor']);
// Add section for post types
add_settings_section('aichwp_post_types', 'Post Types', 'aichwp_post_types_section_text', 'aichwp');
$post_types = aichwp_get_post_types();
foreach ($post_types as $post_type) {
$post_type_object = get_post_type_object($post_type);
add_settings_field(
'aichwp_post_type_' . $post_type,
$post_type_object->label,
'aichwp_post_type_field',
'aichwp',
'aichwp_post_types',
['post_type' => $post_type]
);
add_settings_field(
'aichwp_post_meta_fields_' . $post_type,
'',
'aichwp_post_meta_fields_field',
'aichwp',
'aichwp_post_types',
['post_type' => $post_type]
);
}
// Add settings section for chat options
add_settings_section('aichwp_chat_options', 'Chat Options', 'aichwp_chat_options_section_text', 'aichwp');
// Add settings field for chat welcome message
add_settings_field('aichwp_chat_welcome_message', 'Chat Welcome Message', 'aichwp_chat_welcome_message_field', 'aichwp', 'aichwp_chat_options');
// Add settings fields for initial suggested questions
add_settings_field('aichwp_initial_suggested_question_1', 'Initial Suggested Question 1', 'aichwp_initial_suggested_question_field', 'aichwp', 'aichwp_chat_options', ['question_number' => 1]);
add_settings_field('aichwp_initial_suggested_question_2', 'Initial Suggested Question 2', 'aichwp_initial_suggested_question_field', 'aichwp', 'aichwp_chat_options', ['question_number' => 2]);
add_settings_field('aichwp_initial_suggested_question_3', 'Initial Suggested Question 3', 'aichwp_initial_suggested_question_field', 'aichwp', 'aichwp_chat_options', ['question_number' => 3]);
// Set default chat welcome message
$default_chat_welcome_message = "Hi, I am an artificial intelligence assistant who can answer any queries you may have about content on this site. Type your question in the area below to begin.";
if (empty($options['chat_welcome_message'])) {
$options['chat_welcome_message'] = $default_chat_welcome_message;
$options_update_needed = true;
}
if ($options_update_needed) {
update_option('aichwp_settings', $options);
}
}
// Section text
function aichwp_section_text() {
echo 'Configure the main AI Chat With Pages settings below:';
}
// Indexing progress section text
function aichwp_indexing_progress_section_text() {
echo 'Site content indexing:';
}
// Output indexing progress indicator field
function aichwp_indexing_progress_indicator_field() {
$options = get_option('aichwp_settings', array());
if (!isset($options['openai_api_key']) || empty($options['openai_api_key'])) {
echo ' Please set your OpenAI API Key above.';
} else {
echo ''. esc_html(aichwp_get_total_indexed_documents()) .' documents indexed.';
}
}
// Get the total number of indexed documents
function aichwp_get_total_indexed_documents() {
global $wpdb;
$total_indexed = $wpdb->get_var("SELECT COUNT(DISTINCT post_id) FROM {$wpdb->prefix}aichat_post_embeddings WHERE is_active = 1");
return intval($total_indexed);
}
// Output messages per hour limit field
function aichwp_messages_per_hour_limit_field() {
$options = get_option('aichwp_settings', array());
$messages_per_hour_limit = isset($options['messages_per_hour_limit']) ? intval($options['messages_per_hour_limit']) : 50;
echo '';
}
// Output OpenAI chat model field
function aichwp_openai_chat_model_field() {
$options = get_option('aichwp_settings', array());
$openai_chat_model = isset($options['openai_chat_model']) ? esc_attr($options['openai_chat_model']) : 'gpt-3.5-turbo';
echo '