assistant.php
2 years ago
base.php
2 years ago
embed.php
2 years ago
function.php
2 years ago
image.php
2 years ago
parameter.php
2 years ago
text.php
2 years ago
transcribe.php
2 years ago
assistant.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Query_Assistant extends Meow_MWAI_Query_Base implements JsonSerializable { |
| 4 | |
| 5 | // Core Content |
| 6 | public ?string $imageUrl = null; |
| 7 | public ?string $imageData = null; |
| 8 | |
| 9 | // Assistant |
| 10 | public ?string $chatId = null; |
| 11 | public ?string $assistantId = null; |
| 12 | public ?string $threadId = null; |
| 13 | |
| 14 | public function __construct( ?string $message = '' ) { |
| 15 | parent::__construct( $message ); |
| 16 | $this->mode = "assistant"; |
| 17 | } |
| 18 | |
| 19 | #[\ReturnTypeWillChange] |
| 20 | public function jsonSerialize() { |
| 21 | return [ |
| 22 | 'class' => get_class( $this ), |
| 23 | 'message' => $this->message, |
| 24 | 'imageUrl' => $this->imageUrl, |
| 25 | 'model' => $this->model, |
| 26 | 'session' => $this->session, |
| 27 | 'scope' => $this->scope, |
| 28 | 'envId' => $this->envId, |
| 29 | 'chatId' => $this->chatId, |
| 30 | 'assistantId' => $this->assistantId, |
| 31 | 'threadId' => $this->threadId |
| 32 | ]; |
| 33 | } |
| 34 | |
| 35 | public function set_image( string $imageUrl ): void { |
| 36 | $this->imageUrl = $imageUrl; |
| 37 | } |
| 38 | |
| 39 | public function set_image_data( string $imageData ): void { |
| 40 | $this->imageData = $imageData; |
| 41 | } |
| 42 | |
| 43 | public function get_image_url() { |
| 44 | if ( !empty( $this->imageUrl ) ) { |
| 45 | return $this->imageUrl; |
| 46 | } |
| 47 | if ( !empty( $this->imageData ) ) { |
| 48 | return "data:image/jpeg;base64,{$this->imageData}"; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | public function setAssistantId( string $assistantId ): void { |
| 53 | $this->assistantId = $assistantId; |
| 54 | } |
| 55 | |
| 56 | public function setChatId( string $chatId ): void { |
| 57 | $this->chatId = $chatId; |
| 58 | } |
| 59 | |
| 60 | public function setThreadId( string $threadId ): void { |
| 61 | $this->threadId = $threadId; |
| 62 | } |
| 63 | |
| 64 | // Based on the params of the query, update the attributes |
| 65 | public function inject_params( array $params ): void |
| 66 | { |
| 67 | parent::inject_params( $params ); |
| 68 | |
| 69 | // Those are for the keys passed directly by the shortcode. |
| 70 | $params = $this->convert_keys( $params ); |
| 71 | |
| 72 | // Additional for Assistant. |
| 73 | if ( !empty( $params['chatId'] ) ) { |
| 74 | $this->setChatId( $params['chatId'] ); |
| 75 | } |
| 76 | if ( !empty( $params['assistantId'] ) ) { |
| 77 | $this->setAssistantId( $params['assistantId'] ); |
| 78 | } |
| 79 | if ( !empty( $params['threadId'] ) ) { |
| 80 | $this->setThreadId( $params['threadId'] ); |
| 81 | } |
| 82 | } |
| 83 | } |