WordPress\AiClient\Builders

PromptBuilder::appendPartToMessages │ protected │ WP 0.1.0

Appends a MessagePart to the messages array.

If the last message has a user role, the part is added to it. Otherwise, a new UserMessage is created with the part.

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

Хуков нет.

Возвращает

void. Ничего (null).

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->appendPartToMessages( $part ): void;
$part(MessagePart) (обязательный)
The part to append.

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

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

Код PromptBuilder::appendPartToMessages() WP 7.1.2

protected function appendPartToMessages(MessagePart $part): void
{
    $lastMessage = end($this->messages);
    if ($lastMessage instanceof Message && $lastMessage->getRole()->isUser()) {
        // Replace the last message with a new one containing the appended part
        array_pop($this->messages);
        $this->messages[] = $lastMessage->withPart($part);
        return;
    }
    // Create new UserMessage with the part
    $this->messages[] = new UserMessage([$part]);
}