| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare (strict_types=1); 4 namespace WordPress\AiClient\Providers\ApiBasedImplementation; 5 6 use Exception; 7 use WordPress\AiClient\Providers\Contracts\ModelMetadataDirectoryInterface; 8 use WordPress\AiClient\Providers\Contracts\ProviderAvailabilityInterface; 9 /** 10 * Class to check availability for an API-based provider via a test request to the endpoint to list models. 11 * 12 * This class should be used for cloud-based providers that offer a model listing endpoint which requires 13 * authentication. A request to this endpoint is used to determine if the provider is properly configured 14 * with valid credentials. 15 * 16 * @since 0.1.0 17 */ 18 class ListModelsApiBasedProviderAvailability implements ProviderAvailabilityInterface 19 { 20 /** 21 * @var ModelMetadataDirectoryInterface The model metadata directory to use for checking availability. 22 */ 23 private ModelMetadataDirectoryInterface $modelMetadataDirectory; 24 /** 25 * Constructor. 26 * 27 * @since 0.1.0 28 * 29 * @param ModelMetadataDirectoryInterface $modelMetadataDirectory The model metadata directory to use for checking 30 * availability. 31 */ 32 public function __construct(ModelMetadataDirectoryInterface $modelMetadataDirectory) 33 { 34 $this->modelMetadataDirectory = $modelMetadataDirectory; 35 } 36 /** 37 * {@inheritDoc} 38 * 39 * @since 0.1.0 40 */ 41 public function isConfigured(): bool 42 { 43 try { 44 // Attempt to list models to check if the provider is available. 45 $this->modelMetadataDirectory->listModelMetadata(); 46 return \true; 47 } catch (Exception $e) { 48 // If an exception occurs, the provider is not available. 49 return \false; 50 } 51 } 52 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Jun 13 09:38:55 2026 | Cross-referenced by PHPXref |