BeforeGenerateResultEvent
- Since
- 0.4.0
- Source
wp-includes/php-ai-client/src/Events/BeforeGenerateResultEvent.php:18
Event dispatched before a prompt is sent to the AI model.
Description
This event allows listeners to inspect and modify the messages before they are sent to the model. The event is not stoppable, meaning the model call will always proceed regardless of listener actions.
Compatibility
- WordPress
- since 0.4.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.4.0.
Properties · 3
$messagesWordPress\AiClient\Events\list<Message>private$modelWordPress\AiClient\Providers\Models\Contracts\ModelInterfaceprivate$capabilityWordPress\AiClient\Providers\Models\Enums\CapabilityEnum|nullprivate
Methods · 5
- __construct()Constructor.
- getMessages()Gets the messages to be sent to the model.
- getModel()Gets the model that will process the prompt.
- getCapability()Gets the capability being used for generation.
- __clone()Performs a deep clone of the event.
Source code
class BeforeGenerateResultEvent{ /** * @var list<Message> The messages to be sent to the model. */ private array $messages; /** * @var ModelInterface The model that will process the prompt. */ private ModelInterface $model; /** * @var CapabilityEnum|null The capability being used for generation. */ private ?CapabilityEnum $capability; /** * Constructor. * * @since 0.4.0 * * @param list<Message> $messages The messages to be sent to the model. * @param ModelInterface $model The model that will process the prompt. * @param CapabilityEnum|null $capability The capability being used for generation. */ public function __construct(array $messages, ModelInterface $model, ?CapabilityEnum $capability) { $this->messages = $messages; $this->model = $model; $this->capability = $capability; } /** * Gets the messages to be sent to the model. * * @since 0.4.0 * * @return list<Message> The messages. */ public function getMessages(): array { return $this->messages; } /** * Gets the model that will process the prompt. * * @since 0.4.0 * * @return ModelInterface The model. */ public function getModel(): ModelInterface { return $this->model; } /** * Gets the capability being used for generation. * * @since 0.4.0 * * @return CapabilityEnum|null The capability, or null if not specified. */ public function getCapability(): ?CapabilityEnum { return $this->capability; } /** * Performs a deep clone of the event. * * This method ensures that message objects are cloned to prevent * modifications to the cloned event from affecting the original. * The model object is not cloned as it is a service object. * * @since 0.4.2 */ public function __clone() { $clonedMessages = []; foreach ($this->messages as $message) { $clonedMessages[] = clone $message; } $this->messages = $clonedMessages; }}Changelog
Introduced in 0.4.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/Events/BeforeGenerateResultEvent.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.