WordPress\AiClient\Builders

MessageBuilder::__constructpublicWP 0.2.0

Constructor.

Method of the class: MessageBuilder{}

No Hooks.

Returns

null. Nothing (null).

Usage

$MessageBuilder = new MessageBuilder();
$MessageBuilder->__construct( $input, ?MessageRoleEnum $role );
$input(Input)
Optional initial content.
Default: null
?MessageRoleEnum $role
.
Default: null

Changelog

Since 0.2.0 Introduced.

MessageBuilder::__construct() code WP 7.0

public function __construct($input = null, ?MessageRoleEnum $role = null)
{
    $this->role = $role;
    if ($input === null) {
        return;
    }
    // Handle different input types
    if ($input instanceof MessagePart) {
        $this->parts[] = $input;
    } elseif (is_string($input)) {
        $this->withText($input);
    } elseif ($input instanceof File) {
        $this->withFile($input);
    } elseif ($input instanceof FunctionCall) {
        $this->withFunctionCall($input);
    } elseif ($input instanceof FunctionResponse) {
        $this->withFunctionResponse($input);
    } elseif (is_array($input) && MessagePart::isArrayShape($input)) {
        $this->parts[] = MessagePart::fromArray($input);
    } else {
        throw new InvalidArgumentException('Input must be a string, MessagePart, MessagePartArrayShape, File, FunctionCall, or FunctionResponse.');
    }
}