File tree Expand file tree Collapse file tree 4 files changed +44
-15
lines changed
Expand file tree Collapse file tree 4 files changed +44
-15
lines changed Original file line number Diff line number Diff line change 1010class ToolChoiceMap
1111{
1212 /**
13- * @return array<string, mixed>|string| null
13+ * @return array<string, mixed>|null
1414 */
15- public static function map (string |ToolChoice |null $ toolChoice ): string | array | null
15+ public static function map (string |ToolChoice |null $ toolChoice ): ? array
1616 {
1717 if (is_null ($ toolChoice )) {
1818 return null ;
@@ -30,8 +30,8 @@ public static function map(string|ToolChoice|null $toolChoice): string|array|nul
3030 }
3131
3232 return match ($ toolChoice ) {
33- ToolChoice::Auto => ' auto ' ,
34- ToolChoice::Any => ' any ' ,
33+ ToolChoice::Auto => [ ' type ' => ' auto '] ,
34+ ToolChoice::Any => [ ' type ' => ' any '] ,
3535 };
3636
3737 }
Original file line number Diff line number Diff line change @@ -31,9 +31,7 @@ public static function map(string|ToolChoice|null $toolChoice): string|array|nul
3131 }
3232
3333 return [
34- 'tool ' => [
35- ($ toolChoice === ToolChoice::Auto ? 'auto ' : 'any ' ) => [],
36- ],
34+ ($ toolChoice === ToolChoice::Auto ? 'auto ' : 'any ' ) => new \stdClass ,
3735 ];
3836 }
3937}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Tests \Schemas \Anthropic \Maps ;
6+
7+ use InvalidArgumentException ;
8+ use Prism \Bedrock \Schemas \Anthropic \Maps \ToolChoiceMap ;
9+ use Prism \Prism \Enums \ToolChoice ;
10+
11+ it ('returns null when tool choice is null ' , function (): void {
12+ expect (ToolChoiceMap::map (null ))->toBeNull ();
13+ });
14+
15+ it ('maps a specific tool correctly ' , function (): void {
16+ expect (ToolChoiceMap::map ('search ' ))
17+ ->toBe ([
18+ 'type ' => 'tool ' ,
19+ 'name ' => 'search ' ,
20+ ]);
21+ });
22+
23+ it ('maps auto tool correctly ' , function (): void {
24+ expect (ToolChoiceMap::map (ToolChoice::Auto))
25+ ->toBe (['type ' => 'auto ' ]);
26+ });
27+
28+ it ('maps any tool correctly ' , function (): void {
29+ expect (ToolChoiceMap::map (ToolChoice::Any))
30+ ->toBe (['type ' => 'any ' ]);
31+ });
32+
33+ it ('throws exception for invalid tool choice ' , function (): void {
34+ ToolChoiceMap::map (ToolChoice::None);
35+ })->throws (InvalidArgumentException::class, 'Invalid tool choice ' );
Original file line number Diff line number Diff line change 1818
1919it ('maps any tool correctly ' , function (): void {
2020 expect (ToolChoiceMap::map (ToolChoice::Any))
21- ->toBe ([
22- 'tool ' => [
23- 'any ' => [],
24- ],
21+ ->toEqual ([
22+ 'any ' => new \stdClass ,
2523 ]);
2624});
2725
2826it ('maps auto tool correctly ' , function (): void {
2927 expect (ToolChoiceMap::map (ToolChoice::Auto))
30- ->toBe ([
31- 'tool ' => [
32- 'auto ' => [],
33- ],
28+ ->toEqual ([
29+ 'auto ' => new \stdClass ,
3430 ]);
3531});
You can’t perform that action at this time.
0 commit comments