plugin_env = $plugin_env; $this->script_registry = $script_registry; $this->style_registry = $style_registry; $this->ai = new Chatbot_AI( $site_env, $network_env, $current_user ); } /** * Adds relevant WordPress hooks. * * @since 0.1.0 */ public function add_hooks(): void { if ( doing_action( 'init' ) ) { $this->register_assets(); } else { add_action( 'init', array( $this, 'register_assets' ) ); } if ( is_admin() ) { add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); add_action( 'admin_footer', array( $this, 'render_app_root' ) ); } else { add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); add_action( 'wp_footer', array( $this, 'render_app_root' ) ); } add_filter( 'ai_services_model_params', array( $this, 'filter_model_params' ) ); } /** * Gets the model parameters to use for the chatbot. * * @since 0.1.0 * * @return array The model parameters, containing 'system_instruction'. */ public function get_model_params(): array { return array( 'systemInstruction' => $this->ai->get_system_instruction(), ); } /** * Registers the assets needed for the chatbot. * * @since 0.1.0 */ public function register_assets(): void { $this->script_registry->register( 'ais_chatbot', array( 'src' => $this->plugin_env->url( 'build/chatbot/index.js' ), 'manifest' => $this->plugin_env->path( 'build/chatbot/index.asset.php' ), 'strategy' => 'defer', ) ); $this->style_registry->register( 'ais_chatbot', array( 'src' => $this->plugin_env->url( 'build/chatbot/style-index.css' ), 'path' => $this->plugin_env->path( 'build/chatbot/style-index.css' ), 'manifest' => $this->plugin_env->path( 'build/chatbot/index.asset.php' ), // Don't use 'wp-components' everywhere because it is too heavy to load for just a button. 'dependencies' => array(), ) ); } /** * Enqueues the assets needed for the chatbot. * * @since 0.1.0 */ public function enqueue_assets(): void { $this->script_registry->enqueue( 'ais_chatbot' ); $this->style_registry->enqueue( 'ais_chatbot' ); } /** * Renders the chatbot app root. * * @since 0.1.0 */ public function render_app_root(): void { ?>
$model_params The model parameters. Commonly supports at least the parameters * 'feature', 'capabilities', 'generationConfig' and 'systemInstruction'. * @return array The filtered model parameters. */ public function filter_model_params( array $model_params ): array { if ( isset( $model_params['feature'] ) && 'ai-services-chatbot' === $model_params['feature'] ) { $model_params = array_merge( $model_params, $this->get_model_params() ); } return $model_params; } }