assist-feedback.php
11 months ago
assistant.php
11 months ago
base.php
11 months ago
dropped-file.php
11 months ago
edit-image.php
11 months ago
embed.php
11 months ago
feedback.php
11 months ago
function.php
11 months ago
image.php
11 months ago
parameter.php
11 months ago
text.php
11 months ago
transcribe.php
11 months ago
assistant.php
120 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 | // Dynamic properties that are set by services |
| 15 | public ?object $env = null; |
| 16 | public ?int $_maxDepthConfigured = null; |
| 17 | |
| 18 | #region Constructors, Serialization |
| 19 | |
| 20 | public function __construct( ?string $message = '' ) { |
| 21 | parent::__construct( $message ); |
| 22 | $this->feature = 'assistant'; |
| 23 | } |
| 24 | |
| 25 | #[\ReturnTypeWillChange] |
| 26 | public function jsonSerialize(): array { |
| 27 | $json = [ |
| 28 | 'message' => $this->message, |
| 29 | |
| 30 | 'ai' => [ |
| 31 | 'model' => $this->model, |
| 32 | 'feature' => $this->feature, |
| 33 | 'assistantId' => $this->assistantId, |
| 34 | 'threadId' => $this->threadId, |
| 35 | 'storeId' => $this->storeId, |
| 36 | 'runId' => $this->runId, |
| 37 | ], |
| 38 | |
| 39 | 'system' => [ |
| 40 | 'class' => get_class( $this ), |
| 41 | 'envId' => $this->envId, |
| 42 | 'scope' => $this->scope, |
| 43 | 'session' => $this->session, |
| 44 | 'chatId' => $this->chatId, |
| 45 | ] |
| 46 | ]; |
| 47 | |
| 48 | if ( !empty( $this->context ) ) { |
| 49 | $json['context']['context'] = $this->context; |
| 50 | } |
| 51 | |
| 52 | if ( !empty( $this->attachedFile ) ) { |
| 53 | $json['context']['hasFile'] = true; |
| 54 | // Assistant only supports URL for now. |
| 55 | if ( $this->attachedFile->get_type() === 'url' ) { |
| 56 | $json['context']['fileUrl'] = $this->attachedFile->get_url(); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return $json; |
| 61 | } |
| 62 | |
| 63 | #endregion |
| 64 | |
| 65 | #region File Handling |
| 66 | |
| 67 | public function set_file( Meow_MWAI_Query_DroppedFile $file ): void { |
| 68 | $this->attachedFile = $file; |
| 69 | } |
| 70 | |
| 71 | #endregion |
| 72 | |
| 73 | #region Parameters |
| 74 | |
| 75 | public function setAssistantId( string $assistantId ): void { |
| 76 | $this->assistantId = $assistantId; |
| 77 | } |
| 78 | |
| 79 | public function setChatId( string $chatId ): void { |
| 80 | $this->chatId = $chatId; |
| 81 | } |
| 82 | |
| 83 | public function setThreadId( string $threadId ): void { |
| 84 | $this->threadId = $threadId; |
| 85 | } |
| 86 | |
| 87 | public function setStoreId( string $storeId ): void { |
| 88 | $this->storeId = $storeId; |
| 89 | } |
| 90 | |
| 91 | public function setRunId( string $runId ): void { |
| 92 | $this->runId = $runId; |
| 93 | } |
| 94 | |
| 95 | #endregion |
| 96 | |
| 97 | #region Inject Params |
| 98 | |
| 99 | // Based on the params of the query, update the attributes |
| 100 | public function inject_params( array $params ): void { |
| 101 | parent::inject_params( $params ); |
| 102 | |
| 103 | // Those are for the keys passed directly by the shortcode. |
| 104 | $params = $this->convert_keys( $params ); |
| 105 | |
| 106 | // Additional for Assistant. |
| 107 | if ( !empty( $params['chatId'] ) ) { |
| 108 | $this->setChatId( $params['chatId'] ); |
| 109 | } |
| 110 | if ( !empty( $params['assistantId'] ) ) { |
| 111 | $this->setAssistantId( $params['assistantId'] ); |
| 112 | } |
| 113 | if ( !empty( $params['threadId'] ) ) { |
| 114 | $this->setThreadId( $params['threadId'] ); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | #endregion |
| 119 | } |
| 120 |