forked from prism-php/bedrock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtractsToolCalls.php
More file actions
33 lines (25 loc) · 839 Bytes
/
ExtractsToolCalls.php
File metadata and controls
33 lines (25 loc) · 839 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
<?php
namespace Prism\Bedrock\Schemas\Converse\Concerns;
use Prism\Prism\ValueObjects\ToolCall;
trait ExtractsToolCalls
{
/**
* @param array<string, mixed> $data
* @return ToolCall[]
*/
protected function extractToolCalls(array $data): array
{
$toolCalls = array_map(function ($content) {
if (! $use = data_get($content, 'toolUse')) {
return;
}
$input = data_get($use, 'input');
return new ToolCall(
id: data_get($use, 'toolUseId'),
name: data_get($use, 'name'),
arguments: is_string($input) ? (json_decode($input, true) ?? []) : ($input ?? [])
);
}, data_get($data, 'output.message.content', []));
return array_values(array_filter($toolCalls));
}
}