WordPress\AiClient\Builders

PromptBuilder::__constructpublicWP 0.1.0

Constructor.

Method of the class: PromptBuilder{}

No Hooks.

Returns

null. Nothing (null).

Usage

$PromptBuilder = new PromptBuilder();
$PromptBuilder->__construct( $registry, $prompt, ?EventDispatcherInterface $eventDispatcher );
$registry(ProviderRegistry) (required)
The provider registry for finding suitable models.
$prompt(Prompt)
Optional initial prompt content.
Default: null
?EventDispatcherInterface $eventDispatcher
.
Default: null

Changelog

Since 0.1.0 Introduced.

PromptBuilder::__construct() code WP 7.0

public function __construct(ProviderRegistry $registry, $prompt = null, ?EventDispatcherInterface $eventDispatcher = null)
{
    $this->registry = $registry;
    $this->modelConfig = new ModelConfig();
    $this->eventDispatcher = $eventDispatcher;
    if ($prompt === null) {
        return;
    }
    // Check if it's a list of Messages - set as messages
    if ($this->isMessagesList($prompt)) {
        $this->messages = $prompt;
        return;
    }
    // Parse it as a user message
    $userMessage = $this->parseMessage($prompt, MessageRoleEnum::user());
    $this->messages[] = $userMessage;
}