| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare (strict_types=1); 4 namespace WordPress\AiClient\Events; 5 6 use WordPress\AiClient\Messages\DTO\Message; 7 use WordPress\AiClient\Providers\Models\Contracts\ModelInterface; 8 use WordPress\AiClient\Providers\Models\Enums\CapabilityEnum; 9 /** 10 * Event dispatched before a prompt is sent to the AI model. 11 * 12 * This event allows listeners to inspect and modify the messages before they 13 * are sent to the model. The event is not stoppable, meaning the model call 14 * will always proceed regardless of listener actions. 15 * 16 * @since 0.4.0 17 */ 18 class BeforeGenerateResultEvent 19 { 20 /** 21 * @var list<Message> The messages to be sent to the model. 22 */ 23 private array $messages; 24 /** 25 * @var ModelInterface The model that will process the prompt. 26 */ 27 private ModelInterface $model; 28 /** 29 * @var CapabilityEnum|null The capability being used for generation. 30 */ 31 private ?CapabilityEnum $capability; 32 /** 33 * Constructor. 34 * 35 * @since 0.4.0 36 * 37 * @param list<Message> $messages The messages to be sent to the model. 38 * @param ModelInterface $model The model that will process the prompt. 39 * @param CapabilityEnum|null $capability The capability being used for generation. 40 */ 41 public function __construct(array $messages, ModelInterface $model, ?CapabilityEnum $capability) 42 { 43 $this->messages = $messages; 44 $this->model = $model; 45 $this->capability = $capability; 46 } 47 /** 48 * Gets the messages to be sent to the model. 49 * 50 * @since 0.4.0 51 * 52 * @return list<Message> The messages. 53 */ 54 public function getMessages(): array 55 { 56 return $this->messages; 57 } 58 /** 59 * Gets the model that will process the prompt. 60 * 61 * @since 0.4.0 62 * 63 * @return ModelInterface The model. 64 */ 65 public function getModel(): ModelInterface 66 { 67 return $this->model; 68 } 69 /** 70 * Gets the capability being used for generation. 71 * 72 * @since 0.4.0 73 * 74 * @return CapabilityEnum|null The capability, or null if not specified. 75 */ 76 public function getCapability(): ?CapabilityEnum 77 { 78 return $this->capability; 79 } 80 /** 81 * Performs a deep clone of the event. 82 * 83 * This method ensures that message objects are cloned to prevent 84 * modifications to the cloned event from affecting the original. 85 * The model object is not cloned as it is a service object. 86 * 87 * @since 0.4.2 88 */ 89 public function __clone() 90 { 91 $clonedMessages = []; 92 foreach ($this->messages as $message) { 93 $clonedMessages[] = clone $message; 94 } 95 $this->messages = $clonedMessages; 96 } 97 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Jun 13 09:38:55 2026 | Cross-referenced by PHPXref |