WordPress\AiClient\Results\DTO

GenerativeAiResult::toTextpublicWP 0.1.0

Converts the first candidate to text.

Only text from the content channel is considered. Text within model thought or reasoning is ignored.

Method of the class: GenerativeAiResult{}

No Hooks.

Returns

String. The text content.

Usage

$GenerativeAiResult = new GenerativeAiResult();
$GenerativeAiResult->toText(): string;

Changelog

Since 0.1.0 Introduced.

GenerativeAiResult::toText() code WP 7.0

public function toText(): string
{
    $message = $this->candidates[0]->getMessage();
    foreach ($message->getParts() as $part) {
        $channel = $part->getChannel();
        $text = $part->getText();
        if ($channel->isContent() && $text !== null) {
            return $text;
        }
    }
    throw new RuntimeException('No text content found in first candidate');
}