GenerativeAiResult::toText(): string

In this article

Converts the first candidate to text.

Description

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

Return

string The text content.

Source

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

Changelog

VersionDescription
0.1.0Introduced.

User Contributed Notes

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