Registers WordPress abilities as function declarations for the AI model.
Description
Converts each WP_Ability to a FunctionDeclaration using the wpab__ prefix naming convention and passes them to the underlying prompt builder.
Parameters
$abilitiesWP_Ability|stringrequired- The abilities to register, either as WP_Ability objects or ability name strings.
Source
public function using_abilities( ...$abilities ): self {
$declarations = array();
foreach ( $abilities as $ability ) {
if ( is_string( $ability ) ) {
$ability_name = $ability;
$ability = wp_get_ability( $ability );
if ( ! $ability ) {
_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: %s: string value of the ability name. */
__( 'The ability %s was not found.' ),
'<code>' . esc_html( $ability_name ) . '</code>'
),
'7.0.0'
);
continue;
}
}
// This is only here as a sanity check, the method signature should ensure this already.
if ( ! $ability instanceof WP_Ability ) {
continue;
}
$function_name = WP_AI_Client_Ability_Function_Resolver::ability_name_to_function_name( $ability->get_name() );
$input_schema = $ability->get_input_schema();
$declarations[] = new FunctionDeclaration(
$function_name,
$ability->get_description(),
! empty( $input_schema ) ? $input_schema : null
);
}
if ( ! empty( $declarations ) ) {
return $this->using_function_declarations( ...$declarations );
}
return $this;
}
Changelog
| Version | Description |
|---|---|
| 7.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.