WordPress\AiClient\Results\DTO

GenerativeAiResult::toTextspublicWP 0.1.0

Converts all candidates to text.

Method of the class: GenerativeAiResult{}

No Hooks.

Returns

list. Array of text content.

Usage

$GenerativeAiResult = new GenerativeAiResult();
$GenerativeAiResult->toTexts(): array;

Changelog

Since 0.1.0 Introduced.

GenerativeAiResult::toTexts() code WP 7.0

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;
}