MessageBuilder::get(): WordPressAiClientMessagesDTOMessage

In this article

Builds and returns the Message object.

Return

WordPressAiClientMessagesDTOMessage The built message.

Source

public function get(): Message
{
    if (empty($this->parts)) {
        throw new InvalidArgumentException('Cannot build an empty message. Add content using withText() or similar methods.');
    }
    if ($this->role === null) {
        throw new InvalidArgumentException('Cannot build a message with no role. Set a role using usingRole() or similar methods.');
    }
    // At this point, we've validated that $this->role is not null
    /** @var MessageRoleEnum $role */
    $role = $this->role;
    return new Message($role, $this->parts);
}

Changelog

VersionDescription
0.2.0Introduced.

User Contributed Notes

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