MessagePart::toArray(): WordPressAiClientMessagesDTOMessagePartArrayShape

In this article

{@inheritDoc}

Return

WordPressAiClientMessagesDTOMessagePartArrayShape

Source

public function toArray(): array
{
    $data = [self::KEY_CHANNEL => $this->channel->value, self::KEY_TYPE => $this->type->value];
    if ($this->text !== null) {
        $data[self::KEY_TEXT] = $this->text;
    } elseif ($this->file !== null) {
        $data[self::KEY_FILE] = $this->file->toArray();
    } elseif ($this->functionCall !== null) {
        $data[self::KEY_FUNCTION_CALL] = $this->functionCall->toArray();
    } elseif ($this->functionResponse !== null) {
        $data[self::KEY_FUNCTION_RESPONSE] = $this->functionResponse->toArray();
    } else {
        throw new RuntimeException('MessagePart requires one of: text, file, functionCall, or functionResponse. ' . 'This should not be a possible condition.');
    }
    if ($this->thoughtSignature !== null) {
        $data[self::KEY_THOUGHT_SIGNATURE] = $this->thoughtSignature;
    }
    return $data;
}

Changelog

VersionDescription
0.1.0Introduced.

User Contributed Notes

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