GenerativeAiResult
- Since
- 0.1.0
- Source
wp-includes/php-ai-client/src/Results/DTO/GenerativeAiResult.php:38
Represents the result of a generative AI operation.
Description
This DTO contains the generated candidates along with usage statistics and metadata from the AI provider.
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 · 6
$idstringprivate$candidatesWordPress\AiClient\Results\DTO\Candidate[]private$tokenUsageWordPress\AiClient\Results\DTO\TokenUsageprivate$providerMetadataWordPress\AiClient\Providers\DTO\ProviderMetadataprivate$modelMetadataWordPress\AiClient\Providers\Models\DTO\ModelMetadataprivate$additionalDataWordPress\AiClient\Results\DTO\array<string,private
Methods · 25
- __construct()Constructor.
- getId(){@inheritDoc}
- getCandidates()Gets the generated candidates.
- getTokenUsage(){@inheritDoc}
- getProviderMetadata()Gets the provider metadata.
- getModelMetadata()Gets the model metadata.
- getAdditionalData(){@inheritDoc}
- getCandidateCount()Gets the total number of candidates.
- hasMultipleCandidates()Checks if the result has multiple candidates.
- toText()Converts the first candidate to text.
- toFile()Converts the first candidate to a file.
- toImageFile()Converts the first candidate to an image file.
- toAudioFile()Converts the first candidate to an audio file.
- toVideoFile()Converts the first candidate to a video file.
- toMessage()Converts the first candidate to a message.
- toTexts()Converts all candidates to text.
- toFiles()Converts all candidates to files.
- toImageFiles()Converts all candidates to image files.
- toAudioFiles()Converts all candidates to audio files.
- toVideoFiles()Converts all candidates to video files.
- toMessages()Converts all candidates to messages.
- getJsonSchema(){@inheritDoc}
- toArray(){@inheritDoc}
- fromArray(){@inheritDoc}
- __clone()Performs a deep clone of the result.
Source code
class GenerativeAiResult extends AbstractDataTransferObject implements ResultInterface{ public const KEY_ID = 'id'; public const KEY_CANDIDATES = 'candidates'; public const KEY_TOKEN_USAGE = 'tokenUsage'; public const KEY_PROVIDER_METADATA = 'providerMetadata'; public const KEY_MODEL_METADATA = 'modelMetadata'; public const KEY_ADDITIONAL_DATA = 'additionalData'; /** * @var string Unique identifier for this result. */ private string $id; /** * @var Candidate[] The generated candidates. */ private array $candidates; /** * @var TokenUsage Token usage statistics. */ private \WordPress\AiClient\Results\DTO\TokenUsage $tokenUsage; /** * @var ProviderMetadata Provider metadata. */ private ProviderMetadata $providerMetadata; /** * @var ModelMetadata Model metadata. */ private ModelMetadata $modelMetadata; /** * @var array<string, mixed> Additional data. */ private array $additionalData; /** * Constructor. * * @since 0.1.0 * * @param string $id Unique identifier for this result. * @param Candidate[] $candidates The generated candidates. * @param TokenUsage $tokenUsage Token usage statistics. * @param ProviderMetadata $providerMetadata Provider metadata. * @param ModelMetadata $modelMetadata Model metadata. * @param array<string, mixed> $additionalData Additional data. * @throws InvalidArgumentException If no candidates provided. */ public function __construct(string $id, array $candidates, \WordPress\AiClient\Results\DTO\TokenUsage $tokenUsage, ProviderMetadata $providerMetadata, ModelMetadata $modelMetadata, array $additionalData = []) { if (empty($candidates)) { throw new InvalidArgumentException('At least one candidate must be provided'); } $this->id = $id; $this->candidates = $candidates; $this->tokenUsage = $tokenUsage; $this->providerMetadata = $providerMetadata; $this->modelMetadata = $modelMetadata; $this->additionalData = $additionalData; } /** * {@inheritDoc} * * @since 0.1.0 */ public function getId(): string { return $this->id; } /** * Gets the generated candidates. * * @since 0.1.0 * * @return Candidate[] The candidates. */ public function getCandidates(): array { return $this->candidates; } /** * {@inheritDoc} *Changelog
Introduced in 0.1.0. Unchanged from 7.0.4 through 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/GenerativeAiResult.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.