WordPress\AiClient\Results\DTO

GenerativeAiResult::toTexts │ public │ WP 0.1.0

Converts all candidates to text.

Метод класса: GenerativeAiResult{}

Хуков нет.

Возвращает

list<string>. Array of text content.

Использование

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

Список изменений

С версии 0.1.0 Введена.

Код GenerativeAiResult::toTexts() WP 7.1.3

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