GenerativeAiResult::toFile(): WordPressAiClientFilesDTOFile

In this article

Converts the first candidate to a file.

Description

Only files from the content channel are considered. Files within model thought or reasoning are ignored.

Return

WordPressAiClientFilesDTOFile The file.

Source

public function toFile(): File
{
    $message = $this->candidates[0]->getMessage();
    foreach ($message->getParts() as $part) {
        $channel = $part->getChannel();
        $file = $part->getFile();
        if ($channel->isContent() && $file !== null) {
            return $file;
        }
    }
    throw new RuntimeException('No file 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.