@@ -12,31 +12,35 @@ final class CreateResponseMessage
12
12
private function __construct (
13
13
public readonly string $ role ,
14
14
public readonly ?string $ content ,
15
- public readonly ? CreateResponseChoiceAnnotations $ annotations ,
15
+ public readonly array $ annotations ,
16
16
public readonly array $ toolCalls ,
17
17
public readonly ?CreateResponseFunctionCall $ functionCall ,
18
18
) {}
19
19
20
20
/**
21
- * @param array{role: string, content: ?string, annotations?: ?array<int, array {type: 'url_citation', url_citation: array{start_index: int, end_index: int, title: string, url: string}}> , function_call: ?array{name: string, arguments: string}, tool_calls: ?array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>} $attributes
21
+ * @param array{role: string, content: ?string, annotations?: ?array{type: 'url_citation', url_citation: array{start_index: int, end_index: int, title: string, url: string}}, function_call: ?array{name: string, arguments: string}, tool_calls: ?array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>} $attributes
22
22
*/
23
23
public static function from (array $ attributes ): self
24
24
{
25
25
$ toolCalls = array_map (fn (array $ result ): CreateResponseToolCall => CreateResponseToolCall::from (
26
26
$ result
27
27
), $ attributes ['tool_calls ' ] ?? []);
28
28
29
+ $ annotations = array_map (fn (array $ result ): CreateResponseChoiceAnnotations => CreateResponseChoiceAnnotations::from (
30
+ $ result ,
31
+ ), $ attributes ['annotations ' ] ?? []);
32
+
29
33
return new self (
30
34
$ attributes ['role ' ],
31
35
$ attributes ['content ' ] ?? null ,
32
- isset ( $ attributes [ ' annotations ' ]) ? CreateResponseChoiceAnnotations:: from ( $ attributes [ ' annotations ' ]) : null ,
36
+ $ annotations ,
33
37
$ toolCalls ,
34
38
isset ($ attributes ['function_call ' ]) ? CreateResponseFunctionCall::from ($ attributes ['function_call ' ]) : null ,
35
39
);
36
40
}
37
41
38
42
/**
39
- * @return array{role: string, content: string|null, annotations?: ?array<int, array {type: 'url_citation', url_citation: array{start_index: int, end_index: int, title: string, url: string}}> , function_call?: array{name: string, arguments: string}, tool_calls?: array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>}
43
+ * @return array{role: string, content: string|null, annotations?: ?array{type: 'url_citation', url_citation: array{start_index: int, end_index: int, title: string, url: string}}, function_call?: array{name: string, arguments: string}, tool_calls?: array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>}
40
44
*/
41
45
public function toArray (): array
42
46
{
@@ -45,8 +49,8 @@ public function toArray(): array
45
49
'content ' => $ this ->content ,
46
50
];
47
51
48
- if ($ this ->annotations ) {
49
- $ data ['annotations ' ] = $ this -> annotations ->toArray ();
52
+ if ($ this ->annotations !== [] ) {
53
+ $ data ['annotations ' ] = array_map ( fn ( CreateResponseChoiceAnnotations $ annotations ): array => $ annotations ->toArray (), $ this -> annotations );
50
54
}
51
55
52
56
if ($ this ->functionCall instanceof CreateResponseFunctionCall) {
0 commit comments