assist-feedback.php
10 months ago
assistant.php
8 months ago
base.php
8 months ago
dropped-file.php
8 months ago
edit-image.php
8 months ago
embed.php
10 months ago
feedback.php
10 months ago
function.php
8 months ago
image.php
8 months ago
parameter.php
1 year ago
text.php
8 months ago
transcribe.php
8 months ago
assistant.php
129 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Query_Assistant extends Meow_MWAI_Query_Base implements JsonSerializable { |
| 4 | // Core Content |
| 5 | public ?Meow_MWAI_Query_DroppedFile $attachedFile = null; |
| 6 | |
| 7 | // Parameters |
| 8 | public ?string $chatId = null; |
| 9 | public ?string $runId = null; |
| 10 | public ?string $assistantId = null; |
| 11 | public ?string $threadId = null; |
| 12 | public ?string $storeId = null; // Vector Store ID (https://platform.openai.com/docs/api-reference/vector-stores) |
| 13 | |
| 14 | #region Constructors, Serialization |
| 15 | |
| 16 | public function __construct( ?string $message = '' ) { |
| 17 | parent::__construct( $message ); |
| 18 | $this->feature = 'assistant'; |
| 19 | } |
| 20 | |
| 21 | #[\ReturnTypeWillChange] |
| 22 | public function jsonSerialize(): array { |
| 23 | $json = [ |
| 24 | 'message' => $this->message, |
| 25 | |
| 26 | 'ai' => [ |
| 27 | 'model' => $this->model, |
| 28 | 'feature' => $this->feature, |
| 29 | 'assistantId' => $this->assistantId, |
| 30 | 'threadId' => $this->threadId, |
| 31 | 'storeId' => $this->storeId, |
| 32 | 'runId' => $this->runId, |
| 33 | ], |
| 34 | |
| 35 | 'system' => [ |
| 36 | 'class' => get_class( $this ), |
| 37 | 'envId' => $this->envId, |
| 38 | 'scope' => $this->scope, |
| 39 | 'session' => $this->session, |
| 40 | 'customId' => $this->customId, |
| 41 | 'chatId' => $this->chatId, |
| 42 | ] |
| 43 | ]; |
| 44 | |
| 45 | if ( !empty( $this->context ) ) { |
| 46 | $json['context']['context'] = $this->context; |
| 47 | } |
| 48 | |
| 49 | if ( !empty( $this->attachedFile ) ) { |
| 50 | $json['context']['hasFile'] = true; |
| 51 | // Assistant only supports URL for now. |
| 52 | if ( $this->attachedFile->get_type() === 'url' ) { |
| 53 | $json['context']['fileUrl'] = $this->attachedFile->get_url(); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return $json; |
| 58 | } |
| 59 | |
| 60 | #endregion |
| 61 | |
| 62 | #region File Handling |
| 63 | |
| 64 | /** |
| 65 | * Get all attached files as a normalized array. |
| 66 | * This method provides backward compatibility by merging both attachedFile (legacy) |
| 67 | * and attachedFiles (current) into a single array. |
| 68 | * |
| 69 | * @return Meow_MWAI_Query_DroppedFile[] Array of attached files |
| 70 | */ |
| 71 | public function getAttachments(): array { |
| 72 | // Assistant queries currently only support single file (attachedFile) |
| 73 | // Return it as an array for consistency |
| 74 | if ( $this->attachedFile ) { |
| 75 | return [ $this->attachedFile ]; |
| 76 | } |
| 77 | return []; |
| 78 | } |
| 79 | |
| 80 | #endregion |
| 81 | |
| 82 | #region Parameters |
| 83 | |
| 84 | public function setAssistantId( string $assistantId ): void { |
| 85 | $this->assistantId = $assistantId; |
| 86 | } |
| 87 | |
| 88 | public function setChatId( string $chatId ): void { |
| 89 | $this->chatId = $chatId; |
| 90 | } |
| 91 | |
| 92 | public function setThreadId( string $threadId ): void { |
| 93 | $this->threadId = $threadId; |
| 94 | } |
| 95 | |
| 96 | public function setStoreId( string $storeId ): void { |
| 97 | $this->storeId = $storeId; |
| 98 | } |
| 99 | |
| 100 | public function setRunId( string $runId ): void { |
| 101 | $this->runId = $runId; |
| 102 | } |
| 103 | |
| 104 | #endregion |
| 105 | |
| 106 | #region Inject Params |
| 107 | |
| 108 | // Based on the params of the query, update the attributes |
| 109 | public function inject_params( array $params ): void { |
| 110 | parent::inject_params( $params ); |
| 111 | |
| 112 | // Those are for the keys passed directly by the shortcode. |
| 113 | $params = $this->convert_keys( $params ); |
| 114 | |
| 115 | // Additional for Assistant. |
| 116 | if ( !empty( $params['chatId'] ) ) { |
| 117 | $this->setChatId( $params['chatId'] ); |
| 118 | } |
| 119 | if ( !empty( $params['assistantId'] ) ) { |
| 120 | $this->setAssistantId( $params['assistantId'] ); |
| 121 | } |
| 122 | if ( !empty( $params['threadId'] ) ) { |
| 123 | $this->setThreadId( $params['threadId'] ); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | #endregion |
| 128 | } |
| 129 |