wppaste
WordPress

Candidate

Since
0.1.0
Source
wp-includes/php-ai-client/src/Results/DTO/Candidate.php:24
Represents a candidate response from an AI model.

Description

When generating content, AI models can produce multiple candidates.
Each candidate contains a message and metadata about why generation stopped.

Compatibility

WordPress
since 0.1.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 2 of the 5 tracked releases, added in 0.1.0.

Properties · 2

$messageWordPress\AiClient\Messages\DTO\Messageprivate
$finishReasonWordPress\AiClient\Results\Enums\FinishReasonEnumprivate

Methods · 7

Source code

class Candidate extends AbstractDataTransferObject{    public const KEY_MESSAGE = 'message';    public const KEY_FINISH_REASON = 'finishReason';    /**     * @var Message The generated message.     */    private Message $message;    /**     * @var FinishReasonEnum The reason generation stopped.     */    private FinishReasonEnum $finishReason;    /**     * Constructor.     *     * @since 0.1.0     *     * @param Message $message The generated message.     * @param FinishReasonEnum $finishReason The reason generation stopped.     */    public function __construct(Message $message, FinishReasonEnum $finishReason)    {        if (!$message->getRole()->isModel()) {            throw new InvalidArgumentException('Message must be a model message.');        }        $this->message = $message;        $this->finishReason = $finishReason;    }    /**     * Gets the generated message.     *     * @since 0.1.0     *     * @return Message The message.     */    public function getMessage(): Message    {        return $this->message;    }    /**     * Gets the finish reason.     *     * @since 0.1.0     *     * @return FinishReasonEnum The finish reason.     */    public function getFinishReason(): FinishReasonEnum    {        return $this->finishReason;    }    /**     * {@inheritDoc}     *     * @since 0.1.0     */    public static function getJsonSchema(): array    {        return ['type' => 'object', 'properties' => [self::KEY_MESSAGE => Message::getJsonSchema(), self::KEY_FINISH_REASON => ['type' => 'string', 'enum' => FinishReasonEnum::getValues(), 'description' => 'The reason generation stopped.']], 'required' => [self::KEY_MESSAGE, self::KEY_FINISH_REASON]];    }    /**     * {@inheritDoc}     *     * @since 0.1.0     *     * @return CandidateArrayShape     */    public function toArray(): array    {        return [self::KEY_MESSAGE => $this->message->toArray(), self::KEY_FINISH_REASON => $this->finishReason->value];    }    /**     * {@inheritDoc}     *     * @since 0.1.0     */    public static function fromArray(array $array): self    {        static::validateFromArrayData($array, [self::KEY_MESSAGE, self::KEY_FINISH_REASON]);        $messageData = $array[self::KEY_MESSAGE];        return new self(Message::fromArray($messageData), FinishReasonEnum::from($array[self::KEY_FINISH_REASON]));

Changelog

Introduced in 0.1.0. Unchanged from 7.0.4 through 7.1.0.

  1. 7.0.4
  2. 7.1.0

Signature, return type and hooks compared across 2 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/php-ai-client/src/Results/DTO/Candidate.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.