This includes a `WP_AI_SUPPORT` constant and a `wp_supports_ai` filter. When false, - `_wp_connectors_get_provider_settings()` will return an empty array (short-circuiting the other functionality). - `WP_AI_Client_Prompt_Builder()` will short-circuit the construction with a `WP_Error()`. `wp_ai_client_prompt()` will still return an instance, to allow for fluidity to remain intact. Priority: `WP_AI_SUPPORT` > `add_filter( 'wp_supports_ai', ...) > (default: true)` Follow-up to [61943], [61749], [61943]. Props justlevine, westonruter, gziolo, flixos90, romainmrhenry, ahortin, chrismcelroyseo, SergeyBiryukov. See #64706. Built from https://develop.svn.wordpress.org/trunk@62067 git-svn-id: http://core.svn.wordpress.org/trunk@61349 1a063a9b-81f0-0310-95a4-ce76da25c4cd
59 lines
2.4 KiB
PHP
59 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* WordPress AI Client API.
|
|
*
|
|
* @package WordPress
|
|
* @subpackage AI
|
|
* @since 7.0.0
|
|
*/
|
|
|
|
use WordPress\AiClient\AiClient;
|
|
|
|
/**
|
|
* Returns whether AI features are supported in the current environment.
|
|
*
|
|
* @since 7.0.0
|
|
*
|
|
* @return bool Whether AI features are supported.
|
|
*/
|
|
function wp_supports_ai(): bool {
|
|
$is_enabled = defined( 'WP_AI_SUPPORT' ) ? WP_AI_SUPPORT : true;
|
|
|
|
/**
|
|
* Filters whether the current request should use AI.
|
|
*
|
|
* This allows plugins and 3rd-party code to disable AI features on a per-request basis, or to even override explicit
|
|
* preferences defined by the site owner.
|
|
*
|
|
* @since 7.0.0
|
|
*
|
|
* @param bool $is_enabled Whether the current request should use AI. Default to WP_AI_SUPPORT constant, or true if
|
|
* the constant is not defined.
|
|
*/
|
|
return (bool) apply_filters( 'wp_supports_ai', $is_enabled );
|
|
}
|
|
|
|
/**
|
|
* Creates a new AI prompt builder using the default provider registry.
|
|
*
|
|
* This is the main entry point for generating AI content in WordPress. It returns
|
|
* a fluent builder that can be used to configure and execute AI prompts.
|
|
*
|
|
* The prompt can be provided as a simple string for basic text prompts, or as more
|
|
* complex types for advanced use cases like multi-modal content or conversation history.
|
|
*
|
|
* @since 7.0.0
|
|
*
|
|
* @param string|MessagePart|Message|array|list<string|MessagePart|array>|list<Message>|null $prompt Optional. Initial prompt content.
|
|
* A string for simple text prompts,
|
|
* a MessagePart or Message object for
|
|
* structured content, an array for a
|
|
* message array shape, or a list of
|
|
* parts or messages for multi-turn
|
|
* conversations. Default null.
|
|
* @return WP_AI_Client_Prompt_Builder The prompt builder instance.
|
|
*/
|
|
function wp_ai_client_prompt( $prompt = null ) {
|
|
return new WP_AI_Client_Prompt_Builder( AiClient::defaultRegistry(), $prompt );
|
|
}
|