array( 'confirmReset' => __( 'Are you sure you want to clear all custom instructions and reset to defaults?', 'ai-commerce-assistant' ), 'resetting' => __( 'Resetting...', 'ai-commerce-assistant' ), ), ) ); } /** * Add prompts submenu * * @return void */ public function add_prompts_menu() { add_submenu_page( 'ai-commerce-assistant', __( 'AI Behavior', 'ai-commerce-assistant' ), __( 'AI Behavior', 'ai-commerce-assistant' ), 'manage_options', 'aica-smart-ai-commerce-assistant-behavior', array( $this, 'render_behavior_page' ) ); } /** * Register settings * * @return void */ public function register_settings() { register_setting( 'aica_behavior_settings', 'aica_system_prompts', array( $this, 'sanitize_prompts' ) ); } /** * Sanitize system prompts * * @param array $input Input data * @return array Sanitized data */ public function sanitize_prompts( $input ) { return array( 'base_prompt' => wp_kses_post( $input['base_prompt'] ?? '' ), 'product_recommendation_prompt' => wp_kses_post( $input['product_recommendation_prompt'] ?? '' ), 'cart_management_prompt' => wp_kses_post( $input['cart_management_prompt'] ?? '' ), 'support_prompt' => wp_kses_post( $input['support_prompt'] ?? '' ), 'tone' => sanitize_text_field( $input['tone'] ?? 'friendly' ), 'language_style' => sanitize_text_field( $input['language_style'] ?? 'casual' ), 'max_response_length' => intval( $input['max_response_length'] ?? 150 ), 'include_emojis' => isset( $input['include_emojis'] ) && $input['include_emojis'] === 'yes' ? 'yes' : 'no', ); } /** * Render behavior settings page * * @return void */ public function render_behavior_page() { if ( isset( $_POST['aica_save_behavior'] ) && check_admin_referer( 'aica_behavior_save', 'aica_behavior_nonce' ) ) { $prompts = $this->sanitize_prompts( $_POST['aica_system_prompts'] ); update_option( 'aica_system_prompts', $prompts ); echo '

' . esc_html__( 'AI behavior settings saved successfully!', 'ai-commerce-assistant' ) . '

'; } $prompts = $this->get_prompts(); ?>

🧠

✨

🧩

'', 'product_recommendation_prompt' => '', 'cart_management_prompt' => '', 'support_prompt' => '', 'tone' => 'friendly', 'language_style' => 'casual', 'max_response_length' => 150, 'include_emojis' => 'no', ); $saved = get_option( 'aica_system_prompts', array() ); return wp_parse_args( $saved, $defaults ); } /** * Build complete system prompt for AI * * @param string $context Context (general, product_recommendation, cart, support) * @return string Complete system prompt */ public function build_system_prompt( $context = 'general' ) { $prompts = $this->get_prompts(); $store_name = get_bloginfo( 'name' ); // Build base instructions $base = $prompts['base_prompt'] ?: "You are a helpful AI shopping assistant for {$store_name}. Your goal is to help customers find products, answer questions, and assist with purchases."; // Add tone instructions $tone_map = array( 'friendly' => 'Be warm, friendly, and approachable.', 'professional' => 'Be professional, courteous, and helpful.', 'casual' => 'Be casual, fun, and easy-going.', 'formal' => 'Be formal, respectful, and detailed.', 'enthusiastic' => 'Be enthusiastic, energetic, and positive.', ); $tone_instruction = $tone_map[ $prompts['tone'] ] ?? $tone_map['friendly']; // Add language style $style_map = array( 'simple' => 'Use simple, clear language that anyone can understand.', 'casual' => 'Use natural, conversational language.', 'technical' => 'Use detailed, technical language when appropriate.', 'concise' => 'Keep responses brief and to the point.', ); $style_instruction = $style_map[ $prompts['language_style'] ] ?? $style_map['casual']; // Build context-specific prompt $context_prompt = ''; switch ( $context ) { case 'product_recommendation': $context_prompt = $prompts['product_recommendation_prompt'] ?: 'When recommending products, understand the customer\'s needs first. Suggest 2-3 relevant products with brief descriptions. Always mention the product ID.'; break; case 'cart': $context_prompt = $prompts['cart_management_prompt'] ?: 'For cart management, be clear and efficient. Confirm all additions or removals. If appropriate, suggest proceeding to checkout.'; break; case 'support': $context_prompt = $prompts['support_prompt'] ?: 'For customer support, be empathetic and solution-focused. If you don\'t have information, politely suggest contacting customer support.'; break; } // Length constraint $length_instruction = sprintf( 'Keep responses under %d words.', $prompts['max_response_length'] ); // Emoji instruction $emoji_instruction = ( $prompts['include_emojis'] === 'yes' ) ? 'You may use appropriate emojis to make responses friendlier.' : 'Do not use emojis in responses.'; // Combine all parts $complete_prompt = implode( "\n\n", array_filter( array( $base, $tone_instruction, $style_instruction, $context_prompt, $length_instruction, $emoji_instruction, 'Always be helpful, honest, and respectful.', ) ) ); return $complete_prompt; } } // Initialize // AICA_System_Prompts::get_instance(); // Removed, handled by main plugin class