Skip to content

Commit f9c202b

Browse files
Merge pull request #45 from WordPress/enhance/additional-model-config-params
2 parents 4f1267a + be95110 commit f9c202b

File tree

3 files changed

+225
-0
lines changed

3 files changed

+225
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WordPress\AiClient\Files\Enums;
6+
7+
use WordPress\AiClient\Common\AbstractEnum;
8+
9+
/**
10+
* Represents the type of file storage.
11+
*
12+
* @method static self square() Returns the square orientation
13+
* @method static self landscape() Returns the landscape orientation.
14+
* @method static self portrait() Returns the portrait orientation.
15+
* @method bool isSquare() Checks if this is an square orientation
16+
* @method bool isLandscape() Checks if this is a landscape orientation.
17+
* @method bool isPortrait() Checks if this is a portrait orientation.
18+
*
19+
* @since n.e.x.t
20+
*/
21+
class MediaOrientationEnum extends AbstractEnum
22+
{
23+
/**
24+
* Square orientation.
25+
*
26+
* @var string
27+
*/
28+
public const SQUARE = 'square';
29+
30+
/**
31+
* Landscape orientation.
32+
*
33+
* @var string
34+
*/
35+
public const LANDSCAPE = 'landscape';
36+
37+
/**
38+
* Portrait orientation.
39+
*
40+
* @var string
41+
*/
42+
public const PORTRAIT = 'portrait';
43+
}

src/Providers/Models/DTO/ModelConfig.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use InvalidArgumentException;
88
use WordPress\AiClient\Common\AbstractDataTransferObject;
9+
use WordPress\AiClient\Files\Enums\FileTypeEnum;
10+
use WordPress\AiClient\Files\Enums\MediaOrientationEnum;
911
use WordPress\AiClient\Messages\Enums\ModalityEnum;
1012
use WordPress\AiClient\Tools\DTO\Tool;
1113

@@ -34,8 +36,11 @@
3436
* logprobs?: bool,
3537
* topLogprobs?: int,
3638
* tools?: list<ToolArrayShape>,
39+
* outputFileType?: string,
3740
* outputMimeType?: string,
3841
* outputSchema?: array<string, mixed>,
42+
* outputMediaOrientation?: string,
43+
* outputMediaAspectRatio?: string,
3944
* customOptions?: array<string, mixed>
4045
* }
4146
*
@@ -56,8 +61,11 @@ class ModelConfig extends AbstractDataTransferObject
5661
public const KEY_LOGPROBS = 'logprobs';
5762
public const KEY_TOP_LOGPROBS = 'topLogprobs';
5863
public const KEY_TOOLS = 'tools';
64+
public const KEY_OUTPUT_FILE_TYPE = 'outputFileType';
5965
public const KEY_OUTPUT_MIME_TYPE = 'outputMimeType';
6066
public const KEY_OUTPUT_SCHEMA = 'outputSchema';
67+
public const KEY_OUTPUT_MEDIA_ORIENTATION = 'outputMediaOrientation';
68+
public const KEY_OUTPUT_MEDIA_ASPECT_RATIO = 'outputMediaAspectRatio';
6169
public const KEY_CUSTOM_OPTIONS = 'customOptions';
6270

6371
/**
@@ -125,6 +133,11 @@ class ModelConfig extends AbstractDataTransferObject
125133
*/
126134
protected ?array $tools = null;
127135

136+
/**
137+
* @var FileTypeEnum|null Output file type.
138+
*/
139+
protected ?FileTypeEnum $outputFileType = null;
140+
128141
/**
129142
* @var string|null Output MIME type.
130143
*/
@@ -135,6 +148,16 @@ class ModelConfig extends AbstractDataTransferObject
135148
*/
136149
protected ?array $outputSchema = null;
137150

151+
/**
152+
* @var MediaOrientationEnum|null Output media orientation.
153+
*/
154+
protected ?MediaOrientationEnum $outputMediaOrientation = null;
155+
156+
/**
157+
* @var string|null Output media aspect ratio (e.g. 3:2, 16:9).
158+
*/
159+
protected ?string $outputMediaAspectRatio = null;
160+
138161
/**
139162
* @var array<string, mixed> Custom provider-specific options.
140163
*/
@@ -470,6 +493,30 @@ public function getTools(): ?array
470493
return $this->tools;
471494
}
472495

496+
/**
497+
* Sets the output file type.
498+
*
499+
* @since n.e.x.t
500+
*
501+
* @param FileTypeEnum $outputFileType The output file type.
502+
*/
503+
public function setOutputFileType(FileTypeEnum $outputFileType): void
504+
{
505+
$this->outputFileType = $outputFileType;
506+
}
507+
508+
/**
509+
* Gets the output file type.
510+
*
511+
* @since n.e.x.t
512+
*
513+
* @return FileTypeEnum|null The output file type.
514+
*/
515+
public function getOutputFileType(): ?FileTypeEnum
516+
{
517+
return $this->outputFileType;
518+
}
519+
473520
/**
474521
* Sets the output MIME type.
475522
*
@@ -526,6 +573,61 @@ public function getOutputSchema(): ?array
526573
return $this->outputSchema;
527574
}
528575

576+
/**
577+
* Sets the output media orientation.
578+
*
579+
* @since n.e.x.t
580+
*
581+
* @param MediaOrientationEnum $outputMediaOrientation The output media orientation.
582+
*/
583+
public function setOutputMediaOrientation(MediaOrientationEnum $outputMediaOrientation): void
584+
{
585+
$this->outputMediaOrientation = $outputMediaOrientation;
586+
}
587+
588+
/**
589+
* Gets the output media orientation.
590+
*
591+
* @since n.e.x.t
592+
*
593+
* @return MediaOrientationEnum|null The output media orientation.
594+
*/
595+
public function getOutputMediaOrientation(): ?MediaOrientationEnum
596+
{
597+
return $this->outputMediaOrientation;
598+
}
599+
600+
/**
601+
* Sets the output media aspect ratio.
602+
*
603+
* If set, this supersedes the output media orientation, as it is a more specific configuration.
604+
*
605+
* @since n.e.x.t
606+
*
607+
* @param string $outputMediaAspectRatio The output media aspect ratio (e.g. 3:2, 16:9).
608+
*/
609+
public function setOutputMediaAspectRatio(string $outputMediaAspectRatio): void
610+
{
611+
if (!preg_match('/^\d+:\d+$/', $outputMediaAspectRatio)) {
612+
throw new InvalidArgumentException(
613+
'Output media aspect ratio must be in the format "width:height" (e.g. 3:2, 16:9).'
614+
);
615+
}
616+
$this->outputMediaAspectRatio = $outputMediaAspectRatio;
617+
}
618+
619+
/**
620+
* Gets the output media aspect ratio.
621+
*
622+
* @since n.e.x.t
623+
*
624+
* @return string|null The output media aspect ratio (e.g. 3:2, 16:9).
625+
*/
626+
public function getOutputMediaAspectRatio(): ?string
627+
{
628+
return $this->outputMediaAspectRatio;
629+
}
630+
529631
/**
530632
* Sets a single custom option.
531633
*
@@ -641,6 +743,11 @@ public static function getJsonSchema(): array
641743
'items' => Tool::getJsonSchema(),
642744
'description' => 'Tools available to the model.',
643745
],
746+
self::KEY_OUTPUT_FILE_TYPE => [
747+
'type' => 'string',
748+
'enum' => FileTypeEnum::getValues(),
749+
'description' => 'Output file type.',
750+
],
644751
self::KEY_OUTPUT_MIME_TYPE => [
645752
'type' => 'string',
646753
'description' => 'Output MIME type.',
@@ -650,6 +757,16 @@ public static function getJsonSchema(): array
650757
'additionalProperties' => true,
651758
'description' => 'Output schema (JSON schema).',
652759
],
760+
self::KEY_OUTPUT_MEDIA_ORIENTATION => [
761+
'type' => 'string',
762+
'enum' => MediaOrientationEnum::getValues(),
763+
'description' => 'Output media orientation.',
764+
],
765+
self::KEY_OUTPUT_MEDIA_ASPECT_RATIO => [
766+
'type' => 'string',
767+
'pattern' => '^\d+:\d+$',
768+
'description' => 'Output media aspect ratio.',
769+
],
653770
self::KEY_CUSTOM_OPTIONS => [
654771
'type' => 'object',
655772
'additionalProperties' => true,
@@ -730,6 +847,10 @@ static function (ModalityEnum $modality): string {
730847
}, $this->tools);
731848
}
732849

850+
if ($this->outputFileType !== null) {
851+
$data[self::KEY_OUTPUT_FILE_TYPE] = $this->outputFileType->value;
852+
}
853+
733854
if ($this->outputMimeType !== null) {
734855
$data[self::KEY_OUTPUT_MIME_TYPE] = $this->outputMimeType;
735856
}
@@ -738,6 +859,14 @@ static function (ModalityEnum $modality): string {
738859
$data[self::KEY_OUTPUT_SCHEMA] = $this->outputSchema;
739860
}
740861

862+
if ($this->outputMediaOrientation !== null) {
863+
$data[self::KEY_OUTPUT_MEDIA_ORIENTATION] = $this->outputMediaOrientation->value;
864+
}
865+
866+
if ($this->outputMediaAspectRatio !== null) {
867+
$data[self::KEY_OUTPUT_MEDIA_ASPECT_RATIO] = $this->outputMediaAspectRatio;
868+
}
869+
741870
$data[self::KEY_CUSTOM_OPTIONS] = $this->customOptions;
742871

743872
return $data;
@@ -809,6 +938,10 @@ public static function fromArray(array $array): self
809938
}, $array[self::KEY_TOOLS]));
810939
}
811940

941+
if (isset($array[self::KEY_OUTPUT_FILE_TYPE])) {
942+
$config->setOutputFileType(FileTypeEnum::from($array[self::KEY_OUTPUT_FILE_TYPE]));
943+
}
944+
812945
if (isset($array[self::KEY_OUTPUT_MIME_TYPE])) {
813946
$config->setOutputMimeType($array[self::KEY_OUTPUT_MIME_TYPE]);
814947
}
@@ -817,6 +950,14 @@ public static function fromArray(array $array): self
817950
$config->setOutputSchema($array[self::KEY_OUTPUT_SCHEMA]);
818951
}
819952

953+
if (isset($array[self::KEY_OUTPUT_MEDIA_ORIENTATION])) {
954+
$config->setOutputMediaOrientation(MediaOrientationEnum::from($array[self::KEY_OUTPUT_MEDIA_ORIENTATION]));
955+
}
956+
957+
if (isset($array[self::KEY_OUTPUT_MEDIA_ASPECT_RATIO])) {
958+
$config->setOutputMediaAspectRatio($array[self::KEY_OUTPUT_MEDIA_ASPECT_RATIO]);
959+
}
960+
820961
if (isset($array[self::KEY_CUSTOM_OPTIONS])) {
821962
$config->setCustomOptions($array[self::KEY_CUSTOM_OPTIONS]);
822963
}

0 commit comments

Comments
 (0)