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
image.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Query_Image extends Meow_MWAI_Query_Base { |
| 4 | public ?string $resolution = '1792x1024'; |
| 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->mode = "generation"; // could be generation, edit, variation |
| 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 | #endregion |
| 21 | |
| 22 | #region Parameters |
| 23 | |
| 24 | public function set_resolution( string $resolution ) { |
| 25 | $this->resolution = $resolution; |
| 26 | } |
| 27 | |
| 28 | public function set_style( string $style ) { |
| 29 | $this->style = $style; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Set how the image will be treated locally, if it will be downloaded or not, etc. |
| 34 | * @param string $localDownload The local download method. Could be 'uploads', 'library' or null. |
| 35 | */ |
| 36 | public function set_local_download( ?string $localDownload ) { |
| 37 | $this->localDownload = $localDownload; |
| 38 | } |
| 39 | |
| 40 | // Based on the params of the query, update the attributes |
| 41 | public function inject_params( array $params ): void { |
| 42 | parent::inject_params( $params ); |
| 43 | $params = $this->convert_keys( $params ); |
| 44 | |
| 45 | if ( !empty( $params['resolution'] ) ) { |
| 46 | $this->set_resolution( $params['resolution'] ); |
| 47 | } |
| 48 | if ( !empty( $params['style'] ) ) { |
| 49 | $this->set_style( $params['style'] ); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | #endregion |
| 54 | |
| 55 | #region Final Checks |
| 56 | |
| 57 | public function final_checks() { |
| 58 | parent::final_checks(); |
| 59 | // Since DALL-E 3 only support 1 image, we force it. I guess it will be the same for other models. |
| 60 | $this->maxResults = 1; |
| 61 | } |
| 62 | |
| 63 | #endregion |
| 64 | } |
| 65 |