GenerativeAiResult::toTexts(): WordPressAiClientResultsDTOlist<string>

In this article

Converts all candidates to text.

Return

WordPressAiClientResultsDTOlist<string> Array of text content.

Source

public function toTexts(): array
{
    $texts = [];
    foreach ($this->candidates as $candidate) {
        $message = $candidate->getMessage();
        foreach ($message->getParts() as $part) {
            $channel = $part->getChannel();
            $text = $part->getText();
            if ($channel->isContent() && $text !== null) {
                $texts[] = $text;
                break;
            }
        }
    }
    return $texts;
}

Changelog

VersionDescription
0.1.0Introduced.

User Contributed Notes

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