-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathToolChoiceMap.php
More file actions
38 lines (30 loc) · 854 Bytes
/
ToolChoiceMap.php
File metadata and controls
38 lines (30 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace Prism\Bedrock\Schemas\Anthropic\Maps;
use InvalidArgumentException;
use Prism\Prism\Enums\ToolChoice;
class ToolChoiceMap
{
/**
* @return array<string, mixed>|null
*/
public static function map(string|ToolChoice|null $toolChoice): ?array
{
if (is_null($toolChoice)) {
return null;
}
if (is_string($toolChoice)) {
return [
'type' => 'tool',
'name' => $toolChoice,
];
}
if (! in_array($toolChoice, [ToolChoice::Auto, ToolChoice::Any])) {
throw new InvalidArgumentException('Invalid tool choice');
}
return match ($toolChoice) {
ToolChoice::Auto => ['type' => 'auto'],
ToolChoice::Any => ['type' => 'any'],
};
}
}