Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass service slug to ai_services_model_params filter #23

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/Customizing-AI-Services-Model-Parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
```

Expand Down
4 changes: 3 additions & 1 deletion includes/Services/Decorators/AI_Service_Decorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ public function get_model( array $model_params = array(), array $request_options
* @param array<string, mixed> $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<string, mixed> 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'];
Expand Down
Loading