66
77/**
88 * @phpstan-import-type CreateResponseChoiceAudioType from CreateResponseChoiceAudio
9+ * @phpstan-import-type CreateResponseChoiceImageType from CreateResponseChoiceImage
910 */
1011final class CreateResponseMessage
1112{
1213 /**
1314 * @param array<int, CreateResponseToolCall> $toolCalls
1415 * @param array<int, CreateResponseChoiceAnnotations> $annotations
16+ * @param array<int, CreateResponseChoiceImage>|null $images
1517 */
1618 private function __construct (
1719 public readonly string $ role ,
@@ -20,10 +22,11 @@ private function __construct(
2022 public readonly array $ toolCalls ,
2123 public readonly ?CreateResponseFunctionCall $ functionCall ,
2224 public readonly ?CreateResponseChoiceAudio $ audio = null ,
25+ public readonly ?array $ images = null ,
2326 ) {}
2427
2528 /**
26- * @param array{role: string, content: ?string, annotations?: array<int, array{type: string, 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}}>, audio?: CreateResponseChoiceAudioType} $attributes
29+ * @param array{role: string, content: ?string, annotations?: array<int, array{type: string, 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}}>, audio?: CreateResponseChoiceAudioType, images?: array<int, CreateResponseChoiceImageType> } $attributes
2730 */
2831 public static function from (array $ attributes ): self
2932 {
@@ -35,18 +38,23 @@ public static function from(array $attributes): self
3538 $ result ,
3639 ), $ attributes ['annotations ' ] ?? []);
3740
41+ $ images = isset ($ attributes ['images ' ])
42+ ? array_map (fn (array $ result ): CreateResponseChoiceImage => CreateResponseChoiceImage::from ($ result ), $ attributes ['images ' ])
43+ : null ;
44+
3845 return new self (
39- $ attributes ['role ' ],
40- $ attributes ['content ' ] ?? null ,
41- $ annotations ,
42- $ toolCalls ,
43- isset ($ attributes ['function_call ' ]) ? CreateResponseFunctionCall::from ($ attributes ['function_call ' ]) : null ,
44- isset ($ attributes ['audio ' ]) ? CreateResponseChoiceAudio::from ($ attributes ['audio ' ]) : null ,
46+ role: $ attributes ['role ' ],
47+ content: $ attributes ['content ' ] ?? null ,
48+ annotations: $ annotations ,
49+ toolCalls: $ toolCalls ,
50+ functionCall: isset ($ attributes ['function_call ' ]) ? CreateResponseFunctionCall::from ($ attributes ['function_call ' ]) : null ,
51+ audio: isset ($ attributes ['audio ' ]) ? CreateResponseChoiceAudio::from ($ attributes ['audio ' ]) : null ,
52+ images: $ images ,
4553 );
4654 }
4755
4856 /**
49- * @return array{role: string, content: string|null, annotations?: array<int, array{type: string, 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}}>, audio?: CreateResponseChoiceAudioType}
57+ * @return array{role: string, content: string|null, annotations?: array<int, array{type: string, 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}}>, audio?: CreateResponseChoiceAudioType, images?: array<int, CreateResponseChoiceImageType> }
5058 */
5159 public function toArray (): array
5260 {
@@ -71,6 +79,10 @@ public function toArray(): array
7179 $ data ['audio ' ] = $ this ->audio ->toArray ();
7280 }
7381
82+ if ($ this ->images !== null && $ this ->images !== []) {
83+ $ data ['images ' ] = array_map (fn (CreateResponseChoiceImage $ image ): array => $ image ->toArray (), $ this ->images );
84+ }
85+
7486 return $ data ;
7587 }
7688}
0 commit comments