9
9
use WordPress \AiClient \Files \Enums \FileTypeEnum ;
10
10
use WordPress \AiClient \Files \Enums \MediaOrientationEnum ;
11
11
use WordPress \AiClient \Messages \Enums \ModalityEnum ;
12
- use WordPress \AiClient \Tools \DTO \Tool ;
12
+ use WordPress \AiClient \Tools \DTO \FunctionDeclaration ;
13
+ use WordPress \AiClient \Tools \DTO \WebSearch ;
13
14
14
15
/**
15
16
* Represents configuration for an AI model.
20
21
*
21
22
* @since n.e.x.t
22
23
*
23
- * @phpstan-import-type ToolArrayShape from Tool
24
+ * @phpstan-import-type FunctionDeclarationArrayShape from FunctionDeclaration
25
+ * @phpstan-import-type WebSearchArrayShape from WebSearch
24
26
*
25
27
* @phpstan-type ModelConfigArrayShape array{
26
28
* outputModalities?: list<string>,
35
37
* frequencyPenalty?: float,
36
38
* logprobs?: bool,
37
39
* topLogprobs?: int,
38
- * tools?: list<ToolArrayShape>,
40
+ * functionDeclarations?: list<FunctionDeclarationArrayShape>,
41
+ * webSearch?: WebSearchArrayShape,
39
42
* outputFileType?: string,
40
43
* outputMimeType?: string,
41
44
* outputSchema?: array<string, mixed>,
@@ -60,7 +63,8 @@ class ModelConfig extends AbstractDataTransferObject
60
63
public const KEY_FREQUENCY_PENALTY = 'frequencyPenalty ' ;
61
64
public const KEY_LOGPROBS = 'logprobs ' ;
62
65
public const KEY_TOP_LOGPROBS = 'topLogprobs ' ;
63
- public const KEY_TOOLS = 'tools ' ;
66
+ public const KEY_FUNCTION_DECLARATIONS = 'functionDeclarations ' ;
67
+ public const KEY_WEB_SEARCH = 'webSearch ' ;
64
68
public const KEY_OUTPUT_FILE_TYPE = 'outputFileType ' ;
65
69
public const KEY_OUTPUT_MIME_TYPE = 'outputMimeType ' ;
66
70
public const KEY_OUTPUT_SCHEMA = 'outputSchema ' ;
@@ -129,9 +133,14 @@ class ModelConfig extends AbstractDataTransferObject
129
133
protected ?int $ topLogprobs = null ;
130
134
131
135
/**
132
- * @var list<Tool >|null Tools available to the model.
136
+ * @var list<FunctionDeclaration >|null Function declarations available to the model.
133
137
*/
134
- protected ?array $ tools = null ;
138
+ protected ?array $ functionDeclarations = null ;
139
+
140
+ /**
141
+ * @var WebSearch|null Web search configuration for the model.
142
+ */
143
+ protected ?WebSearch $ webSearch = null ;
135
144
136
145
/**
137
146
* @var FileTypeEnum|null Output file type.
@@ -464,33 +473,57 @@ public function getTopLogprobs(): ?int
464
473
}
465
474
466
475
/**
467
- * Sets the tools .
476
+ * Sets the function declarations .
468
477
*
469
478
* @since n.e.x.t
470
479
*
471
- * @param list<Tool > $tools The tools .
480
+ * @param list<FunctionDeclaration > $function_declarations The function declarations .
472
481
*
473
482
* @throws InvalidArgumentException If the array is not a list.
474
483
*/
475
- public function setTools (array $ tools ): void
484
+ public function setFunctionDeclarations (array $ function_declarations ): void
476
485
{
477
- if (!array_is_list ($ tools )) {
478
- throw new InvalidArgumentException ('Tools must be a list array. ' );
486
+ if (!array_is_list ($ function_declarations )) {
487
+ throw new InvalidArgumentException ('Function declarations must be a list array. ' );
479
488
}
480
489
481
- $ this ->tools = $ tools ;
490
+ $ this ->functionDeclarations = $ function_declarations ;
491
+ }
492
+
493
+ /**
494
+ * Gets the function declarations.
495
+ *
496
+ * @since n.e.x.t
497
+ *
498
+ * @return list<FunctionDeclaration>|null The function declarations.
499
+ */
500
+ public function getFunctionDeclarations (): ?array
501
+ {
502
+ return $ this ->functionDeclarations ;
482
503
}
483
504
484
505
/**
485
- * Gets the tools .
506
+ * Sets the web search configuration .
486
507
*
487
508
* @since n.e.x.t
488
509
*
489
- * @return list<Tool>|null The tools .
510
+ * @param WebSearch $web_search The web search configuration .
490
511
*/
491
- public function getTools ( ): ? array
512
+ public function setWebSearch ( WebSearch $ web_search ): void
492
513
{
493
- return $ this ->tools ;
514
+ $ this ->webSearch = $ web_search ;
515
+ }
516
+
517
+ /**
518
+ * Gets the web search configuration.
519
+ *
520
+ * @since n.e.x.t
521
+ *
522
+ * @return WebSearch|null The web search configuration.
523
+ */
524
+ public function getWebSearch (): ?WebSearch
525
+ {
526
+ return $ this ->webSearch ;
494
527
}
495
528
496
529
/**
@@ -738,11 +771,12 @@ public static function getJsonSchema(): array
738
771
'minimum ' => 1 ,
739
772
'description ' => 'Number of top log probabilities to return. ' ,
740
773
],
741
- self ::KEY_TOOLS => [
774
+ self ::KEY_FUNCTION_DECLARATIONS => [
742
775
'type ' => 'array ' ,
743
- 'items ' => Tool ::getJsonSchema (),
744
- 'description ' => 'Tools available to the model. ' ,
776
+ 'items ' => FunctionDeclaration ::getJsonSchema (),
777
+ 'description ' => 'Function declarations available to the model. ' ,
745
778
],
779
+ self ::KEY_WEB_SEARCH => WebSearch::getJsonSchema (),
746
780
self ::KEY_OUTPUT_FILE_TYPE => [
747
781
'type ' => 'string ' ,
748
782
'enum ' => FileTypeEnum::getValues (),
@@ -841,10 +875,17 @@ static function (ModalityEnum $modality): string {
841
875
$ data [self ::KEY_TOP_LOGPROBS ] = $ this ->topLogprobs ;
842
876
}
843
877
844
- if ($ this ->tools !== null ) {
845
- $ data [self ::KEY_TOOLS ] = array_map (static function (Tool $ tool ): array {
846
- return $ tool ->toArray ();
847
- }, $ this ->tools );
878
+ if ($ this ->functionDeclarations !== null ) {
879
+ $ data [self ::KEY_FUNCTION_DECLARATIONS ] = array_map (
880
+ static function (FunctionDeclaration $ function_declaration ): array {
881
+ return $ function_declaration ->toArray ();
882
+ },
883
+ $ this ->functionDeclarations
884
+ );
885
+ }
886
+
887
+ if ($ this ->webSearch !== null ) {
888
+ $ data [self ::KEY_WEB_SEARCH ] = $ this ->webSearch ->toArray ();
848
889
}
849
890
850
891
if ($ this ->outputFileType !== null ) {
@@ -932,10 +973,17 @@ public static function fromArray(array $array): self
932
973
$ config ->setTopLogprobs ($ array [self ::KEY_TOP_LOGPROBS ]);
933
974
}
934
975
935
- if (isset ($ array [self ::KEY_TOOLS ])) {
936
- $ config ->setTools (array_map (static function (array $ toolData ): Tool {
937
- return Tool::fromArray ($ toolData );
938
- }, $ array [self ::KEY_TOOLS ]));
976
+ if (isset ($ array [self ::KEY_FUNCTION_DECLARATIONS ])) {
977
+ $ config ->setFunctionDeclarations (array_map (
978
+ static function (array $ function_declaration_data ): FunctionDeclaration {
979
+ return FunctionDeclaration::fromArray ($ function_declaration_data );
980
+ },
981
+ $ array [self ::KEY_FUNCTION_DECLARATIONS ]
982
+ ));
983
+ }
984
+
985
+ if (isset ($ array [self ::KEY_WEB_SEARCH ])) {
986
+ $ config ->setWebSearch (WebSearch::fromArray ($ array [self ::KEY_WEB_SEARCH ]));
939
987
}
940
988
941
989
if (isset ($ array [self ::KEY_OUTPUT_FILE_TYPE ])) {
0 commit comments