@@ -98,10 +98,51 @@ pub enum MessageRole {
9898 function,
9999}
100100
101+ #[ derive( Debug , Deserialize , Clone ) ]
102+ pub enum Content {
103+ Text ( String ) ,
104+ ImageUrl ( Vec < ImageUrl > ) ,
105+ }
106+
107+ impl serde:: Serialize for Content {
108+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
109+ where
110+ S : serde:: Serializer ,
111+ {
112+ match * self {
113+ Content :: Text ( ref text) => serializer. serialize_str ( text) ,
114+ Content :: ImageUrl ( ref image_url) => image_url. serialize ( serializer) ,
115+ }
116+ }
117+ }
118+
119+ #[ derive( Debug , Serialize , Deserialize , Clone ) ]
120+ #[ allow( non_camel_case_types) ]
121+ pub enum ContentType {
122+ text,
123+ image_url,
124+ }
125+
126+ #[ derive( Debug , Serialize , Deserialize , Clone ) ]
127+ #[ allow( non_camel_case_types) ]
128+ pub struct ImageUrlType {
129+ pub url : String ,
130+ }
131+
132+ #[ derive( Debug , Serialize , Deserialize , Clone ) ]
133+ #[ allow( non_camel_case_types) ]
134+ pub struct ImageUrl {
135+ pub r#type : ContentType ,
136+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
137+ pub text : Option < String > ,
138+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
139+ pub image_url : Option < ImageUrlType > ,
140+ }
141+
101142#[ derive( Debug , Serialize , Deserialize , Clone ) ]
102143pub struct ChatCompletionMessage {
103144 pub role : MessageRole ,
104- pub content : String ,
145+ pub content : Content ,
105146 #[ serde( skip_serializing_if = "Option::is_none" ) ]
106147 pub name : Option < String > ,
107148}
0 commit comments