@@ -10,11 +10,13 @@ import Foundation
10
10
public enum MessageContent : Codable {
11
11
12
12
case imageFile( ImageFile )
13
+ case imageUrl( ImageURL )
13
14
case text( Text )
14
15
15
16
enum CodingKeys : String , CodingKey {
16
17
case type
17
18
case imageFile = " image_file "
19
+ case imageUrl = " image_url "
18
20
case text
19
21
}
20
22
@@ -28,6 +30,9 @@ public enum MessageContent: Codable {
28
30
case . imageFile( let imageFile) :
29
31
try container. encode ( " image_file " , forKey: . type)
30
32
try container. encode ( imageFile, forKey: . imageFile)
33
+ case . imageUrl( let imageUrl) :
34
+ try container. encode ( " image_url " , forKey: . type)
35
+ try container. encode ( imageUrl, forKey: . imageUrl)
31
36
case . text( let text) :
32
37
try container. encode ( " text " , forKey: . type)
33
38
try container. encode ( text, forKey: . text)
@@ -40,8 +45,11 @@ public enum MessageContent: Codable {
40
45
41
46
switch type {
42
47
case " image_file " :
43
- let imageFile = try ImageFile ( from: decoder)
48
+ let imageFile = try ImageFile ( from: decoder)
44
49
self = . imageFile( imageFile)
50
+ case " image_url " :
51
+ let imageUrl = try ImageURL ( from: decoder)
52
+ self = . imageUrl( imageUrl)
45
53
case " text " :
46
54
let text = try Text ( from: decoder)
47
55
self = . text( text)
@@ -76,6 +84,31 @@ public struct ImageFile: Codable {
76
84
}
77
85
}
78
86
87
+ // MARK: Image URl
88
+
89
+ public struct ImageURL : Codable {
90
+ /// Always image_url.
91
+ public let type : String
92
+
93
+ /// References an image [File](https://platform.openai.com/docs/api-reference/files) in the content of a message.
94
+ public let imageUrl : ImageUrlContent
95
+
96
+ public struct ImageUrlContent : Codable {
97
+
98
+ /// The [File](https://platform.openai.com/docs/api-reference/files) URL of the image in the message content.
99
+ public let url : String
100
+
101
+ enum CodingKeys : String , CodingKey {
102
+ case url
103
+ }
104
+ }
105
+
106
+ enum CodingKeys : String , CodingKey {
107
+ case imageUrl = " image_url "
108
+ case type
109
+ }
110
+ }
111
+
79
112
// MARK: Text
80
113
81
114
public struct Text : Codable {
0 commit comments