getTimeout() === null) { $options->setTimeout($timeout); } return $options; } /** * {@inheritDoc} * * @since 0.1.0 */ protected static function createModel( ModelMetadata $modelMetadata, ProviderMetadata $providerMetadata ): ModelInterface { $capabilities = $modelMetadata->getSupportedCapabilities(); foreach ($capabilities as $capability) { if ($capability->isImageGeneration()) { return new DeApiImageGenerationModel($modelMetadata, $providerMetadata); } if ($capability->isTextToSpeechConversion()) { return new DeApiTextToSpeechConversionModel($modelMetadata, $providerMetadata); } if ($capability->isVideoGeneration()) { return new DeApiVideoGenerationModel($modelMetadata, $providerMetadata); } // Embedding generation support was added in AI Client 1.4.0. if ( $capability->isEmbeddingGeneration() && interface_exists(EmbeddingGenerationModelInterface::class) ) { return new DeApiEmbeddingGenerationModel($modelMetadata, $providerMetadata); } } throw new RuntimeException( 'Unsupported model capabilities: ' . implode(', ', $capabilities) ); } /** * {@inheritDoc} * * @since 0.1.0 */ protected static function createProviderMetadata(): ProviderMetadata { $providerMetadataArgs = [ 'deapi', 'deAPI', ProviderTypeEnum::cloud(), 'https://app.deapi.ai/register', RequestAuthenticationMethod::apiKey(), ]; // Provider description support was added in AI Client 1.2.0. if (version_compare(AiClient::VERSION, '1.2.0', '>=')) { $description = 'Image and video generation, image editing, text-to-speech and embeddings with open models such as FLUX, LTX and MiniMax.'; if (function_exists('__')) { // phpcs:ignore Generic.Files.LineLength.TooLong $description = __('Image and video generation, image editing, text-to-speech and embeddings with open models such as FLUX, LTX and MiniMax.', 'ai-provider-for-deapi'); } $providerMetadataArgs[] = $description; } // Provider logoPath support was added in AI Client 1.3.0. if (version_compare(AiClient::VERSION, '1.3.0', '>=')) { $pluginDir = dirname(__DIR__, 2); if (defined('AI_PROVIDER_FOR_DEAPI_PLUGIN_DIR')) { $definedPluginDir = constant('AI_PROVIDER_FOR_DEAPI_PLUGIN_DIR'); if (is_string($definedPluginDir)) { $pluginDir = $definedPluginDir; } } $providerMetadataArgs[] = $pluginDir . '/assets/images/deapi.svg'; } return new ProviderMetadata(...$providerMetadataArgs); } /** * {@inheritDoc} * * @since 0.1.0 */ protected static function createProviderAvailability(): ProviderAvailabilityInterface { // A valid key can list models. The gateway answers 401 for a missing or rejected key. return new DeApiProviderAvailability(); } /** * {@inheritDoc} * * @since 0.1.0 */ protected static function createModelMetadataDirectory(): ModelMetadataDirectoryInterface { return new DeApiModelMetadataDirectory(); } }