6
6
7
7
/**
8
8
* @phpstan-import-type CreateResponseChoiceAudioType from CreateResponseChoiceAudio
9
+ * @phpstan-import-type CreateResponseChoiceImageType from CreateResponseChoiceImage
9
10
*/
10
11
final class CreateResponseMessage
11
12
{
12
13
/**
13
14
* @param array<int, CreateResponseToolCall> $toolCalls
14
15
* @param array<int, CreateResponseChoiceAnnotations> $annotations
16
+ * @param array<int, CreateResponseChoiceImage>|null $images
15
17
*/
16
18
private function __construct (
17
19
public readonly string $ role ,
@@ -20,10 +22,11 @@ private function __construct(
20
22
public readonly array $ toolCalls ,
21
23
public readonly ?CreateResponseFunctionCall $ functionCall ,
22
24
public readonly ?CreateResponseChoiceAudio $ audio = null ,
25
+ public readonly ?array $ images = null ,
23
26
) {}
24
27
25
28
/**
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
27
30
*/
28
31
public static function from (array $ attributes ): self
29
32
{
@@ -35,18 +38,23 @@ public static function from(array $attributes): self
35
38
$ result ,
36
39
), $ attributes ['annotations ' ] ?? []);
37
40
41
+ $ images = isset ($ attributes ['images ' ])
42
+ ? array_map (fn (array $ result ): CreateResponseChoiceImage => CreateResponseChoiceImage::from ($ result ), $ attributes ['images ' ])
43
+ : null ;
44
+
38
45
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 ,
45
53
);
46
54
}
47
55
48
56
/**
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> }
50
58
*/
51
59
public function toArray (): array
52
60
{
@@ -71,6 +79,10 @@ public function toArray(): array
71
79
$ data ['audio ' ] = $ this ->audio ->toArray ();
72
80
}
73
81
82
+ if ($ this ->images !== null && $ this ->images !== []) {
83
+ $ data ['images ' ] = array_map (fn (CreateResponseChoiceImage $ image ): array => $ image ->toArray (), $ this ->images );
84
+ }
85
+
74
86
return $ data ;
75
87
}
76
88
}
0 commit comments