WordPress\AiClient\Builders

PromptBuilder::executeModelGeneration │ private │ WP 0.4.0

Executes the model generation based on capability.

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

Хуков нет.

Возвращает

GenerativeAiResult. The generated result.

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

// private - только в коде основоного (родительского) класса
$result = $this->executeModelGeneration( $model, $capability, $messages ): GenerativeAiResult;
$model(ModelInterface) (обязательный)
The model to use for generation.
$capability(CapabilityEnum) (обязательный)
The capability to use.
$messages(list) (обязательный)
The messages to send.

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

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

Код PromptBuilder::executeModelGeneration() WP 7.1.2

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));
}