6
6
7
7
use InvalidArgumentException ;
8
8
use WordPress \AiClient \Common \AbstractDataTransferObject ;
9
+ use WordPress \AiClient \Files \Enums \FileTypeEnum ;
10
+ use WordPress \AiClient \Files \Enums \MediaOrientationEnum ;
9
11
use WordPress \AiClient \Messages \Enums \ModalityEnum ;
10
12
use WordPress \AiClient \Tools \DTO \Tool ;
11
13
34
36
* logprobs?: bool,
35
37
* topLogprobs?: int,
36
38
* tools?: list<ToolArrayShape>,
39
+ * outputFileType?: string,
37
40
* outputMimeType?: string,
38
41
* outputSchema?: array<string, mixed>,
42
+ * outputMediaOrientation?: string,
43
+ * outputMediaAspectRatio?: string,
39
44
* customOptions?: array<string, mixed>
40
45
* }
41
46
*
@@ -56,8 +61,11 @@ class ModelConfig extends AbstractDataTransferObject
56
61
public const KEY_LOGPROBS = 'logprobs ' ;
57
62
public const KEY_TOP_LOGPROBS = 'topLogprobs ' ;
58
63
public const KEY_TOOLS = 'tools ' ;
64
+ public const KEY_OUTPUT_FILE_TYPE = 'outputFileType ' ;
59
65
public const KEY_OUTPUT_MIME_TYPE = 'outputMimeType ' ;
60
66
public const KEY_OUTPUT_SCHEMA = 'outputSchema ' ;
67
+ public const KEY_OUTPUT_MEDIA_ORIENTATION = 'outputMediaOrientation ' ;
68
+ public const KEY_OUTPUT_MEDIA_ASPECT_RATIO = 'outputMediaAspectRatio ' ;
61
69
public const KEY_CUSTOM_OPTIONS = 'customOptions ' ;
62
70
63
71
/**
@@ -125,6 +133,11 @@ class ModelConfig extends AbstractDataTransferObject
125
133
*/
126
134
protected ?array $ tools = null ;
127
135
136
+ /**
137
+ * @var FileTypeEnum|null Output file type.
138
+ */
139
+ protected ?FileTypeEnum $ outputFileType = null ;
140
+
128
141
/**
129
142
* @var string|null Output MIME type.
130
143
*/
@@ -135,6 +148,16 @@ class ModelConfig extends AbstractDataTransferObject
135
148
*/
136
149
protected ?array $ outputSchema = null ;
137
150
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
+
138
161
/**
139
162
* @var array<string, mixed> Custom provider-specific options.
140
163
*/
@@ -470,6 +493,30 @@ public function getTools(): ?array
470
493
return $ this ->tools ;
471
494
}
472
495
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
+
473
520
/**
474
521
* Sets the output MIME type.
475
522
*
@@ -526,6 +573,61 @@ public function getOutputSchema(): ?array
526
573
return $ this ->outputSchema ;
527
574
}
528
575
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
+
529
631
/**
530
632
* Sets a single custom option.
531
633
*
@@ -641,6 +743,11 @@ public static function getJsonSchema(): array
641
743
'items ' => Tool::getJsonSchema (),
642
744
'description ' => 'Tools available to the model. ' ,
643
745
],
746
+ self ::KEY_OUTPUT_FILE_TYPE => [
747
+ 'type ' => 'string ' ,
748
+ 'enum ' => FileTypeEnum::getValues (),
749
+ 'description ' => 'Output file type. ' ,
750
+ ],
644
751
self ::KEY_OUTPUT_MIME_TYPE => [
645
752
'type ' => 'string ' ,
646
753
'description ' => 'Output MIME type. ' ,
@@ -650,6 +757,16 @@ public static function getJsonSchema(): array
650
757
'additionalProperties ' => true ,
651
758
'description ' => 'Output schema (JSON schema). ' ,
652
759
],
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
+ ],
653
770
self ::KEY_CUSTOM_OPTIONS => [
654
771
'type ' => 'object ' ,
655
772
'additionalProperties ' => true ,
@@ -730,6 +847,10 @@ static function (ModalityEnum $modality): string {
730
847
}, $ this ->tools );
731
848
}
732
849
850
+ if ($ this ->outputFileType !== null ) {
851
+ $ data [self ::KEY_OUTPUT_FILE_TYPE ] = $ this ->outputFileType ->value ;
852
+ }
853
+
733
854
if ($ this ->outputMimeType !== null ) {
734
855
$ data [self ::KEY_OUTPUT_MIME_TYPE ] = $ this ->outputMimeType ;
735
856
}
@@ -738,6 +859,14 @@ static function (ModalityEnum $modality): string {
738
859
$ data [self ::KEY_OUTPUT_SCHEMA ] = $ this ->outputSchema ;
739
860
}
740
861
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
+
741
870
$ data [self ::KEY_CUSTOM_OPTIONS ] = $ this ->customOptions ;
742
871
743
872
return $ data ;
@@ -809,6 +938,10 @@ public static function fromArray(array $array): self
809
938
}, $ array [self ::KEY_TOOLS ]));
810
939
}
811
940
941
+ if (isset ($ array [self ::KEY_OUTPUT_FILE_TYPE ])) {
942
+ $ config ->setOutputFileType (FileTypeEnum::from ($ array [self ::KEY_OUTPUT_FILE_TYPE ]));
943
+ }
944
+
812
945
if (isset ($ array [self ::KEY_OUTPUT_MIME_TYPE ])) {
813
946
$ config ->setOutputMimeType ($ array [self ::KEY_OUTPUT_MIME_TYPE ]);
814
947
}
@@ -817,6 +950,14 @@ public static function fromArray(array $array): self
817
950
$ config ->setOutputSchema ($ array [self ::KEY_OUTPUT_SCHEMA ]);
818
951
}
819
952
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
+
820
961
if (isset ($ array [self ::KEY_CUSTOM_OPTIONS ])) {
821
962
$ config ->setCustomOptions ($ array [self ::KEY_CUSTOM_OPTIONS ]);
822
963
}
0 commit comments