From e6ebca771e641219c72c5daaedfda5da5011bedc Mon Sep 17 00:00:00 2001 From: Linnea Huxford <7308162+mslinnea@users.noreply.github.com> Date: Sat, 8 Feb 2025 18:12:07 -0800 Subject: [PATCH 1/2] Pass service slug to filter --- includes/Services/Decorators/AI_Service_Decorator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/Services/Decorators/AI_Service_Decorator.php b/includes/Services/Decorators/AI_Service_Decorator.php index 16940d7..926638b 100644 --- a/includes/Services/Decorators/AI_Service_Decorator.php +++ b/includes/Services/Decorators/AI_Service_Decorator.php @@ -146,9 +146,11 @@ public function get_model( array $model_params = array(), array $request_options * @param array $model_params The model parameters. Commonly supports at least the parameters * 'feature', 'capabilities', 'generationConfig' and * 'systemInstruction'. + * @param string $service_slug The service slug. + * * @return array The processed model parameters. */ - $filtered_model_params = (array) apply_filters( 'ai_services_model_params', $model_params ); + $filtered_model_params = (array) apply_filters( 'ai_services_model_params', $model_params, $this->service->get_service_slug() ); // Ensure that the feature identifier cannot be changed. $filtered_model_params['feature'] = $model_params['feature']; From 4b98ca05a404d361b074711196101301fc721f05 Mon Sep 17 00:00:00 2001 From: Linnea Huxford <7308162+mslinnea@users.noreply.github.com> Date: Sat, 8 Feb 2025 18:33:31 -0800 Subject: [PATCH 2/2] Update filter example use --- docs/Customizing-AI-Services-Model-Parameters.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/Customizing-AI-Services-Model-Parameters.md b/docs/Customizing-AI-Services-Model-Parameters.md index 5bde02d..16a6e00 100644 --- a/docs/Customizing-AI-Services-Model-Parameters.md +++ b/docs/Customizing-AI-Services-Model-Parameters.md @@ -13,14 +13,16 @@ Here is an example code snippet which injects a custom system instruction whenev ```php add_filter( 'ai_services_model_params', - function ( $params ) { - if ( 'my-movie-expert' === $params['feature'] ) { + function ( $params, $service ) { + if ( 'my-movie-expert' === $params['feature'] && 'google' === $service ) { $params['systemInstruction'] = 'You are a movie expert. You can answer questions about movies, actors, directors, and movie references.'; $params['systemInstruction'] .= ' If the user asks you about anything unrelated to movies, you should politely deny the request.'; $params['systemInstruction'] .= ' You may use famous movie quotes in your responses to make the conversation more engaging.'; } return $params; - } + }, + 10, + 2 ); ```