-
-
Notifications
You must be signed in to change notification settings - Fork 681
Expand file tree
/
Copy pathCreateResponseToolCall.php
More file actions
43 lines (37 loc) · 1.49 KB
/
CreateResponseToolCall.php
File metadata and controls
43 lines (37 loc) · 1.49 KB
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
39
40
41
42
43
<?php
declare(strict_types=1);
namespace OpenAI\Responses\Chat;
final class CreateResponseToolCall
{
private function __construct(
public readonly string $id,
public readonly string $type,
public readonly CreateResponseToolCallFunction $function,
public readonly ?CreateResponseToolCallExtraContent $extra_content,
) {}
/**
* @param array{id: string, type?: string, function: array{name: string, arguments: string}, extra_content?: array{google?: array{thought_signature: string}}} $attributes
*/
public static function from(array $attributes): self
{
return new self(
$attributes['id'],
$attributes['type'] ?? 'function',
CreateResponseToolCallFunction::from($attributes['function']),
isset($attributes['extra_content']) ? CreateResponseToolCallExtraContent::from($attributes['extra_content']) : null,
);
}
/**
* @return array{id: string, type: string, function: array{name: string, arguments: string}, extra_content?: array{google?: array{thought_signature: string}|null}}
*/
public function toArray(): array
{
$extraContentArray = $this->extra_content?->toArray();
return array_filter([
'id' => $this->id,
'type' => $this->type,
'function' => $this->function->toArray(),
'extra_content' => empty($extraContentArray) ? null : $extraContentArray,
], fn ($value) => $value !== null);
}
}