wp-includes/php-ai-client/src/Providers/ApiBasedImplementation/GenerateTextApiBasedProviderAvailability.php:23Class to check availability for an API-based provider via a test request to the endpoint to generate text.
$modelWordPress\AiClient\Providers\ApiBasedImplementation\ModelInterface&TextGenerationModelInterfaceprivateclass GenerateTextApiBasedProviderAvailability implements ProviderAvailabilityInterface{ /** * @var ModelInterface&TextGenerationModelInterface The model to use for checking availability. */ private ModelInterface $model; /** * Constructor. * * @since 0.1.0 * * @param ModelInterface $model The model to use for checking availability. */ public function __construct(ModelInterface $model) { if (!$model instanceof TextGenerationModelInterface) { throw new Exception('The model class to check provider availability must implement TextGenerationModelInterface.'); } $this->model = $model; } /** * {@inheritDoc} * * @since 0.1.0 */ public function isConfigured(): bool { // Set config to use as few resources as possible for the test. $modelConfig = ModelConfig::fromArray([ModelConfig::KEY_MAX_TOKENS => 1]); $this->model->setConfig($modelConfig); try { // Attempt to generate text to check if the provider is available. $this->model->generateTextResult([new Message(MessageRoleEnum::user(), [new MessagePart('a')])]); return \true; } catch (Exception $e) { // If an exception occurs, the provider is not available. return \false; } }}Introduced in 0.1.0. Unchanged from 7.0.4 through 7.1.0.
Signature, return type and hooks compared across 2 parsed releases.
src/wp-includes/php-ai-client/src/Providers/ApiBasedImplementation/GenerateTextApiBasedProviderAvailability.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.