@@ -148,7 +148,7 @@ impl ProviderStrategy {
148148 . map ( |part| match part {
149149 ChatMessagePart :: Text ( text) => {
150150 Ok ( json ! ( {
151- "type" : " input_text",
151+ "type" : if msg . role == "assistant" { "output_text" } else { " input_text" } ,
152152 "text" : text
153153 } ) )
154154 }
@@ -165,7 +165,7 @@ impl ProviderStrategy {
165165 }
166166 } ;
167167 Ok ( json ! ( {
168- "type" : " input_image",
168+ "type" : if msg . role == "assistant" { "output_image" } else { " input_image" } ,
169169 "image_url" : image_url
170170 } ) )
171171 }
@@ -177,7 +177,7 @@ impl ProviderStrategy {
177177 . strip_prefix ( "audio/" )
178178 . unwrap_or ( & mime_type) ;
179179 Ok ( json ! ( {
180- "type" : " input_audio",
180+ "type" : if msg . role == "assistant" { "output_audio" } else { " input_audio" } ,
181181 "input_audio" : {
182182 "data" : b64_media. base64,
183183 "format" : format
@@ -193,7 +193,7 @@ impl ProviderStrategy {
193193 match & media. content {
194194 baml_types:: BamlMediaContent :: Url ( url_content) => {
195195 Ok ( json ! ( {
196- "type" : " input_file",
196+ "type" : if msg . role == "assistant" { "output_file" } else { " input_file" } ,
197197 "file_url" : url_content. url
198198 } ) )
199199 }
@@ -202,7 +202,7 @@ impl ProviderStrategy {
202202 }
203203 baml_types:: BamlMediaContent :: Base64 ( b64_media) => {
204204 Ok ( json ! ( {
205- "type" : " input_file",
205+ "type" : if msg . role == "assistant" { "output_file" } else { " input_file" } ,
206206 "file_url" : format!( "data:{};base64,{}" , media. mime_type_as_ok( ) ?, b64_media. base64)
207207 } ) )
208208 }
@@ -218,7 +218,7 @@ impl ProviderStrategy {
218218 match inner_part. as_ref ( ) {
219219 ChatMessagePart :: Text ( text) => {
220220 Ok ( json ! ( {
221- "type" : " input_text",
221+ "type" : if msg . role == "assistant" { "output_text" } else { " input_text" } ,
222222 "text" : text
223223 } ) )
224224 }
@@ -236,7 +236,7 @@ impl ProviderStrategy {
236236 }
237237 } ;
238238 Ok ( json ! ( {
239- "type" : " input_image",
239+ "type" : if msg . role == "assistant" { "output_image" } else { " input_image" } ,
240240 "image_url" : image_url
241241 } ) )
242242 }
0 commit comments