| [ 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 use WordPress\AiClient\Results\DTO\GenerativeAiResult; 10 /** 11 * Event dispatched after a prompt has been sent to the AI model and a response received. 12 * 13 * This event allows listeners to inspect the result of the model call for logging, 14 * analytics, or other post-processing purposes. The result object is immutable. 15 * 16 * @since 0.4.0 17 */ 18 class AfterGenerateResultEvent 19 { 20 /** 21 * @var list<Message> The messages that were sent to the model. 22 */ 23 private array $messages; 24 /** 25 * @var ModelInterface The model that processed the prompt. 26 */ 27 private ModelInterface $model; 28 /** 29 * @var CapabilityEnum|null The capability that was used for generation. 30 */ 31 private ?CapabilityEnum $capability; 32 /** 33 * @var GenerativeAiResult The result from the model. 34 */ 35 private GenerativeAiResult $result; 36 /** 37 * Constructor. 38 * 39 * @since 0.4.0 40 * 41 * @param list<Message> $messages The messages that were sent to the model. 42 * @param ModelInterface $model The model that processed the prompt. 43 * @param CapabilityEnum|null $capability The capability that was used for generation. 44 * @param GenerativeAiResult $result The result from the model. 45 */ 46 public function __construct(array $messages, ModelInterface $model, ?CapabilityEnum $capability, GenerativeAiResult $result) 47 { 48 $this->messages = $messages; 49 $this->model = $model; 50 $this->capability = $capability; 51 $this->result = $result; 52 } 53 /** 54 * Gets the messages that were sent to the model. 55 * 56 * @since 0.4.0 57 * 58 * @return list<Message> The messages. 59 */ 60 public function getMessages(): array 61 { 62 return $this->messages; 63 } 64 /** 65 * Gets the model that processed the prompt. 66 * 67 * @since 0.4.0 68 * 69 * @return ModelInterface The model. 70 */ 71 public function getModel(): ModelInterface 72 { 73 return $this->model; 74 } 75 /** 76 * Gets the capability that was used for generation. 77 * 78 * @since 0.4.0 79 * 80 * @return CapabilityEnum|null The capability, or null if not specified. 81 */ 82 public function getCapability(): ?CapabilityEnum 83 { 84 return $this->capability; 85 } 86 /** 87 * Gets the result from the model. 88 * 89 * @since 0.4.0 90 * 91 * @return GenerativeAiResult The result. 92 */ 93 public function getResult(): GenerativeAiResult 94 { 95 return $this->result; 96 } 97 /** 98 * Performs a deep clone of the event. 99 * 100 * This method ensures that message and result objects are cloned to prevent 101 * modifications to the cloned event from affecting the original. 102 * The model object is not cloned as it is a service object. 103 * 104 * @since 0.4.2 105 */ 106 public function __clone() 107 { 108 $clonedMessages = []; 109 foreach ($this->messages as $message) { 110 $clonedMessages[] = clone $message; 111 } 112 $this->messages = $clonedMessages; 113 $this->result = clone $this->result; 114 } 115 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Jun 13 09:38:55 2026 | Cross-referenced by PHPXref |