@@ -12,31 +12,35 @@ final class CreateResponseMessage
1212 private function __construct (
1313 public readonly string $ role ,
1414 public readonly ?string $ content ,
15- public readonly ? CreateResponseChoiceAnnotations $ annotations ,
15+ public readonly array $ annotations ,
1616 public readonly array $ toolCalls ,
1717 public readonly ?CreateResponseFunctionCall $ functionCall ,
1818 ) {}
1919
2020 /**
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
2222 */
2323 public static function from (array $ attributes ): self
2424 {
2525 $ toolCalls = array_map (fn (array $ result ): CreateResponseToolCall => CreateResponseToolCall::from (
2626 $ result
2727 ), $ attributes ['tool_calls ' ] ?? []);
2828
29+ $ annotations = array_map (fn (array $ result ): CreateResponseChoiceAnnotations => CreateResponseChoiceAnnotations::from (
30+ $ result ,
31+ ), $ attributes ['annotations ' ] ?? []);
32+
2933 return new self (
3034 $ attributes ['role ' ],
3135 $ attributes ['content ' ] ?? null ,
32- isset ( $ attributes [ ' annotations ' ]) ? CreateResponseChoiceAnnotations:: from ( $ attributes [ ' annotations ' ]) : null ,
36+ $ annotations ,
3337 $ toolCalls ,
3438 isset ($ attributes ['function_call ' ]) ? CreateResponseFunctionCall::from ($ attributes ['function_call ' ]) : null ,
3539 );
3640 }
3741
3842 /**
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}}>}
4044 */
4145 public function toArray (): array
4246 {
@@ -45,8 +49,8 @@ public function toArray(): array
4549 'content ' => $ this ->content ,
4650 ];
4751
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 );
5054 }
5155
5256 if ($ this ->functionCall instanceof CreateResponseFunctionCall) {
0 commit comments