WordPress\AiClient\Providers\Models\DTO

ModelRequirements::areMetBypublicWP 0.2.0

Checks whether the given model metadata meets these requirements.

Метод класса: ModelRequirements{}

Хуков нет.

Возвращает

true|false. True if the model meets all requirements, false otherwise.

Использование

$ModelRequirements = new ModelRequirements();
$ModelRequirements->areMetBy( $metadata ): bool;
$metadata(ModelMetadata) (обязательный)
The model metadata to check against.

Список изменений

С версии 0.2.0 Введена.

Код ModelRequirements::areMetBy() WP 7.0

public function areMetBy(\WordPress\AiClient\Providers\Models\DTO\ModelMetadata $metadata): bool
{
    // Create lookup maps for better performance (instead of nested foreach loops)
    $capabilitiesMap = [];
    foreach ($metadata->getSupportedCapabilities() as $capability) {
        $capabilitiesMap[$capability->value] = $capability;
    }
    $optionsMap = [];
    foreach ($metadata->getSupportedOptions() as $option) {
        $optionsMap[$option->getName()->value] = $option;
    }
    // Check if all required capabilities are supported using map lookup
    foreach ($this->requiredCapabilities as $requiredCapability) {
        if (!isset($capabilitiesMap[$requiredCapability->value])) {
            return \false;
        }
    }
    // Check if all required options are supported with the specified values
    foreach ($this->requiredOptions as $requiredOption) {
        // Use map lookup instead of linear search
        if (!isset($optionsMap[$requiredOption->getName()->value])) {
            return \false;
        }
        $supportedOption = $optionsMap[$requiredOption->getName()->value];
        // Check if the required value is supported by this option
        if (!$supportedOption->isSupportedValue($requiredOption->getValue())) {
            return \false;
        }
    }
    return \true;
}