assistant.php
1 year ago
assistfeedback.php
1 year ago
base.php
1 year ago
droppedfile.php
2 years ago
embed.php
1 year ago
feedback.php
1 year ago
function.php
1 year ago
image.php
1 year ago
parameter.php
2 years ago
text.php
1 year ago
transcribe.php
1 year ago
image.php
91 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Query_Image extends Meow_MWAI_Query_Base { |
| 4 | public ?string $resolution = null; |
| 5 | public ?string $style = null; |
| 6 | public ?string $localDownload = 'uploads'; |
| 7 | public ?string $localDownloadExpiry = 'uploads'; |
| 8 | |
| 9 | #region Constructors, Serialization |
| 10 | |
| 11 | public function __construct( ?string $message = "", ?string $model = "dall-e-3" ) { |
| 12 | parent::__construct( $message ); |
| 13 | $this->model = $model; |
| 14 | $this->feature = "text-to-image"; // image-to-image, inpainting, etc |
| 15 | global $mwai_core; |
| 16 | $this->localDownload = $mwai_core->get_option( 'image_local_download' ); |
| 17 | $this->localDownloadExpiry = $mwai_core->get_option( 'image_expires_download' ); |
| 18 | } |
| 19 | |
| 20 | #[\ReturnTypeWillChange] |
| 21 | public function jsonSerialize(): array { |
| 22 | $json = [ |
| 23 | 'message' => $this->message, |
| 24 | |
| 25 | 'ai' => [ |
| 26 | 'model' => $this->model, |
| 27 | 'feature' => $this->feature, |
| 28 | 'resolution' => $this->resolution |
| 29 | ], |
| 30 | |
| 31 | 'system' => [ |
| 32 | 'class' => get_class( $this ), |
| 33 | 'envId' => $this->envId, |
| 34 | 'scope' => $this->scope, |
| 35 | 'session' => $this->session |
| 36 | ] |
| 37 | ]; |
| 38 | |
| 39 | if ( !empty( $this->context ) ) { |
| 40 | $json['context']['content'] = $this->context; |
| 41 | } |
| 42 | |
| 43 | return $json; |
| 44 | } |
| 45 | |
| 46 | #endregion |
| 47 | |
| 48 | #region Parameters |
| 49 | |
| 50 | public function set_resolution( string $resolution ) { |
| 51 | $this->resolution = $resolution; |
| 52 | } |
| 53 | |
| 54 | public function set_style( string $style ) { |
| 55 | $this->style = $style; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Set how the image will be treated locally, if it will be downloaded or not, etc. |
| 60 | * @param string $localDownload The local download method. Could be 'uploads', 'library' or null. |
| 61 | */ |
| 62 | public function set_local_download( ?string $localDownload ) { |
| 63 | $this->localDownload = $localDownload; |
| 64 | } |
| 65 | |
| 66 | // Based on the params of the query, update the attributes |
| 67 | public function inject_params( array $params ): void { |
| 68 | parent::inject_params( $params ); |
| 69 | $params = $this->convert_keys( $params ); |
| 70 | |
| 71 | if ( !empty( $params['resolution'] ) ) { |
| 72 | $this->set_resolution( $params['resolution'] ); |
| 73 | } |
| 74 | if ( !empty( $params['style'] ) ) { |
| 75 | $this->set_style( $params['style'] ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | #endregion |
| 80 | |
| 81 | #region Final Checks |
| 82 | |
| 83 | public function final_checks() { |
| 84 | parent::final_checks(); |
| 85 | // Since DALL-E 3 only support 1 image, we force it. I guess it will be the same for other models. |
| 86 | $this->maxResults = 1; |
| 87 | } |
| 88 | |
| 89 | #endregion |
| 90 | } |
| 91 |