WordPress\AiClient\Messages\DTO

MessagePart::__constructpublicWP 0.1.0

Constructor that accepts various content types and infers the message part type.

Method of the class: MessagePart{}

No Hooks.

Returns

null. Nothing (null).

Usage

$MessagePart = new MessagePart();
$MessagePart->__construct( $content, ?MessagePartChannelEnum $channel, ?string $thoughtSignature );
$content(mixed) (required)
The content of this message part.
?MessagePartChannelEnum $channel
.
Default: null
?string $thoughtSignature
.
Default: null

Changelog

Since 0.1.0 Introduced.

MessagePart::__construct() code WP 7.0

public function __construct($content, ?MessagePartChannelEnum $channel = null, ?string $thoughtSignature = null)
{
    $this->channel = $channel ?? MessagePartChannelEnum::content();
    $this->thoughtSignature = $thoughtSignature;
    if (is_string($content)) {
        $this->type = MessagePartTypeEnum::text();
        $this->text = $content;
    } elseif ($content instanceof File) {
        $this->type = MessagePartTypeEnum::file();
        $this->file = $content;
    } elseif ($content instanceof FunctionCall) {
        $this->type = MessagePartTypeEnum::functionCall();
        $this->functionCall = $content;
    } elseif ($content instanceof FunctionResponse) {
        $this->type = MessagePartTypeEnum::functionResponse();
        $this->functionResponse = $content;
    } else {
        $type = is_object($content) ? get_class($content) : gettype($content);
        throw new InvalidArgumentException(sprintf('Unsupported content type %s. Expected string, File, ' . 'FunctionCall, or FunctionResponse.', $type));
    }
}