forum_structure_provider = $forum_structure_provider; $this->chatgpt_api = $chatgpt_api; } /** * Build complete system prompt with all context and instructions * * @param string $bot_username The bot's username for identity instructions * @return string Complete system prompt ready for API */ public function build_system_prompt( $bot_username ) { $system_prompt = get_option( 'ai_bot_system_prompt' ); // Build all instruction blocks $date_instruction = $this->build_date_time_instruction(); $bot_identity_instruction = $this->build_bot_identity_instruction( $bot_username ); $forum_context = $this->build_forum_context_instruction(); // Combine: Date + Identity + Forum Context + Base System Prompt return $date_instruction . $bot_identity_instruction . $forum_context . "\n\n" . $system_prompt; } /** * Build response format instructions for the user prompt * * @param string $bot_username The bot's username * @param string $triggering_username_slug The username slug of the user who triggered the bot * @param string $remote_host The hostname of the remote knowledge source * @return string Formatted response instructions */ public function build_response_instructions( $bot_username, $triggering_username_slug, $remote_host ) { return sprintf( "\n--- Your Response Instructions ---\n". "1. Understand the user query from the 'CURRENT INTERACTION' section. The user who wrote this (and who you are replying to) is @%s.\n". "2. Use the conversation history provided in the message structure above to understand the flow of discussion and maintain context.\n". "3. Primarily use information from 'RELEVANT KNOWLEDGE BASE (LOCAL)' and 'RELEVANT KNOWLEDGE BASE (REMOTE)' to answer the query, if they contain relevant information.\n". "4. You are @%s. Address @%s directly in your reply if appropriate (e.g., 'Hi @%s, ...').\n". "5. **Mentioning Users:** When you need to mention users from the conversation, use the `@username-slug` format from their message prefixes. If you are addressing the user who triggered you, use @%s.\n". "6. Cite the source URL (if provided in the context) primarily when presenting specific facts, figures, or direct quotes from the 'RELEVANT KNOWLEDGE BASE' sections (local or remote) to support your response. For general discussion drawing on the context, citation is less critical.\n". "7. Your *entire* response must be formatted using only HTML tags suitable for direct rendering in a web page (e.g.,

, , , ,