-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathToolChoiceMap.php
More file actions
37 lines (30 loc) · 847 Bytes
/
ToolChoiceMap.php
File metadata and controls
37 lines (30 loc) · 847 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
<?php
declare(strict_types=1);
namespace Prism\Bedrock\Schemas\Converse\Maps;
use InvalidArgumentException;
use Prism\Prism\Enums\ToolChoice;
class ToolChoiceMap
{
/**
* @return array<string, mixed>|string|null
*/
public static function map(string|ToolChoice|null $toolChoice): string|array|null
{
if (is_null($toolChoice)) {
return null;
}
if (is_string($toolChoice)) {
return [
'tool' => [
'name' => $toolChoice,
],
];
}
if (! in_array($toolChoice, [ToolChoice::Auto, ToolChoice::Any])) {
throw new InvalidArgumentException('Invalid tool choice');
}
return [
($toolChoice === ToolChoice::Auto ? 'auto' : 'any') => new \stdClass,
];
}
}