getSupportedCapabilities() as $capability ) { if ( $capability->isTextGeneration() ) { return new ChatGptTextGenerationModel( $model_metadata, $provider_metadata ); } } throw new RuntimeException( 'The ChatGPT provider currently only supports text generation models.' ); } /** * {@inheritDoc} * * The SDK's `RequestAuthenticationMethod` enum has no OAuth case at the * time of writing, so we declare `apiKey()` and override the model-level * `getRequestAuthentication()` to substitute our OAuth-aware auth class * regardless of what the registry tries to inject. * * @since 0.1.0 */ protected static function createProviderMetadata(): ProviderMetadata { $description = function_exists( '__' ) ? __( 'OpenAI via your ChatGPT account. Configure under Settings → ChatGPT; do not enter an API key here.', 'ai-provider-for-chatgpt' ) : 'OpenAI via your ChatGPT account. Configure under Settings → ChatGPT; do not enter an API key here.'; $args = array( 'chatgpt', 'ChatGPT', ProviderTypeEnum::cloud(), admin_url( 'options-general.php?page=ai-provider-for-chatgpt' ), // The SDK's auth-method enum only has apiKey(); we declare it so the // picker shows the provider, but the model layer ignores any key // entered there and reads OAuth tokens from TokenStore instead. RequestAuthenticationMethod::apiKey(), ); if ( version_compare( AiClient::VERSION, '1.2.0', '>=' ) ) { $args[] = $description; } if ( version_compare( AiClient::VERSION, '1.3.0', '>=' ) ) { $args[] = dirname( __DIR__, 2 ) . '/assets/images/chatgpt.svg'; } return new ProviderMetadata( ...$args ); } /** * {@inheritDoc} * * @since 0.1.0 */ protected static function createProviderAvailability(): ProviderAvailabilityInterface { return new ListModelsApiBasedProviderAvailability( static::modelMetadataDirectory() ); } /** * {@inheritDoc} * * @since 0.1.0 */ protected static function createModelMetadataDirectory(): ModelMetadataDirectoryInterface { return new ChatGptModelMetadataDirectory(); } }