PromptBuilder::executeModelGeneration( WordPressAiClientProvidersModelsContractsModelInterface $model, WordPressAiClientProvidersModelsEnumsCapabilityEnum $capability, WordPressAiClientBuilderslist $messages ): WordPressAiClientResultsDTOGenerativeAiResult

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Executes the model generation based on capability.

Parameters

$modelWordPressAiClientProvidersModelsContractsModelInterfacerequired
The model to use for generation.
$capabilityWordPressAiClientProvidersModelsEnumsCapabilityEnumrequired
The capability to use.
$messages<span class="WordPressAiClientBuilderslist”>WordPressAiClientBuilderslistrequired
The messages to send.

Return

WordPressAiClientResultsDTOGenerativeAiResult The generated result.

Source

private function executeModelGeneration(ModelInterface $model, CapabilityEnum $capability, array $messages): GenerativeAiResult
{
    if ($capability->isTextGeneration()) {
        if (!$model instanceof TextGenerationModelInterface) {
            throw new RuntimeException(sprintf('Model "%s" does not support text generation.', $model->metadata()->getId()));
        }
        return $model->generateTextResult($messages);
    }
    if ($capability->isImageGeneration()) {
        if (!$model instanceof ImageGenerationModelInterface) {
            throw new RuntimeException(sprintf('Model "%s" does not support image generation.', $model->metadata()->getId()));
        }
        return $model->generateImageResult($messages);
    }
    if ($capability->isTextToSpeechConversion()) {
        if (!$model instanceof TextToSpeechConversionModelInterface) {
            throw new RuntimeException(sprintf('Model "%s" does not support text-to-speech conversion.', $model->metadata()->getId()));
        }
        return $model->convertTextToSpeechResult($messages);
    }
    if ($capability->isSpeechGeneration()) {
        if (!$model instanceof SpeechGenerationModelInterface) {
            throw new RuntimeException(sprintf('Model "%s" does not support speech generation.', $model->metadata()->getId()));
        }
        return $model->generateSpeechResult($messages);
    }
    if ($capability->isVideoGeneration()) {
        if (!$model instanceof VideoGenerationModelInterface) {
            throw new RuntimeException(sprintf('Model "%s" does not support video generation.', $model->metadata()->getId()));
        }
        return $model->generateVideoResult($messages);
    }
    // TODO: Add support for other capabilities when interfaces are available
    throw new RuntimeException(sprintf('Capability "%s" is not yet supported for generation.', $capability->value));
}

Changelog

VersionDescription
0.4.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.