WordPress\AiClient\Builders

PromptBuilder::isSupportedpublicWP 0.1.0

Checks if the current prompt is supported by the selected model.

Method of the class: PromptBuilder{}

No Hooks.

Returns

true|false. True if supported, false otherwise.

Usage

$PromptBuilder = new PromptBuilder();
$PromptBuilder->isSupported( ?CapabilityEnum $capability ): bool;
?CapabilityEnum $capability
.
Default: null

Changelog

Since 0.1.0 Introduced.
Since 0.3.0 Method visibility changed to public.

PromptBuilder::isSupported() code WP 7.0

public function isSupported(?CapabilityEnum $capability = null): bool
{
    // If no intended capability provided, infer from output modalities
    if ($capability === null) {
        // First try to infer from a specific model if one is set
        if ($this->model !== null) {
            $inferredCapability = $this->inferCapabilityFromModelInterfaces($this->model);
            if ($inferredCapability !== null) {
                $capability = $inferredCapability;
            }
        }
        // If still no capability, infer from output modalities
        if ($capability === null) {
            $capability = $this->inferCapabilityFromOutputModalities();
        }
    }
    // Build requirements with the specified capability
    $requirements = ModelRequirements::fromPromptData($capability, $this->messages, $this->modelConfig);
    // If the model has been set, check if it meets the requirements
    if ($this->model !== null) {
        return $requirements->areMetBy($this->model->metadata());
    }
    try {
        // Check if any models support these requirements
        $models = $this->registry->findModelsMetadataForSupport($requirements);
        return !empty($models);
    } catch (InvalidArgumentException $e) {
        // No models support the requirements
        return \false;
    }
}