@@ -98,9 +98,19 @@ public async Task<ChatCompletion> CompleteAsync(
98
98
result . Contents . Add ( new TextContent ( text ) ) ;
99
99
}
100
100
101
- if ( content . Image is { Source . Bytes : { } bytes , Format . Value : { } formatValue } )
101
+ if ( content . Image is { Source . Bytes : { } imageBytes , Format : { } imageFormat } )
102
102
{
103
- result . Contents . Add ( new ImageContent ( bytes . ToArray ( ) , $ "image/{ formatValue } ") ) ;
103
+ result . Contents . Add ( new ImageContent ( imageBytes . ToArray ( ) , GetMimeType ( imageFormat ) ) ) ;
104
+ }
105
+
106
+ if ( content . Video is { Source . Bytes : { } videoBytes , Format : { } videoFormat } )
107
+ {
108
+ result . Contents . Add ( new DataContent ( videoBytes . ToArray ( ) , GetMimeType ( videoFormat ) ) ) ;
109
+ }
110
+
111
+ if ( content . Document is { Source . Bytes : { } documentBytes , Format : { } documentFormat } )
112
+ {
113
+ result . Contents . Add ( new DataContent ( documentBytes . ToArray ( ) , GetMimeType ( documentFormat ) ) ) ;
104
114
}
105
115
106
116
if ( content . ToolUse is { } toolUse )
@@ -344,11 +354,22 @@ private static List<ContentBlock> CreateContents(ChatMessage message)
344
354
}
345
355
} ) ;
346
356
}
357
+ else if ( GetVideoFormat ( dc . MediaType ) is VideoFormat videoFormat )
358
+ {
359
+ contents . Add ( new ( )
360
+ {
361
+ Video = new ( )
362
+ {
363
+ Source = new ( ) { Bytes = new ( dc . Data ! . Value . ToArray ( ) ) } ,
364
+ Format = videoFormat ,
365
+ }
366
+ } ) ;
367
+ }
347
368
else if ( GetDocumentFormat ( dc . MediaType ) is DocumentFormat docFormat )
348
369
{
349
370
contents . Add ( new ( )
350
371
{
351
- Document = new DocumentBlock ( )
372
+ Document = new ( )
352
373
{
353
374
Source = new ( ) { Bytes = new ( dc . Data ! . Value . ToArray ( ) ) } ,
354
375
Format = docFormat ,
@@ -414,6 +435,22 @@ private static List<ContentBlock> CreateContents(ChatMessage message)
414
435
_ => null ,
415
436
} ;
416
437
438
+ /// <summary>Gets the MIME type for a <see cref="DocumentFormat"/>.</summary>
439
+ private static string ? GetMimeType ( DocumentFormat ? format ) =>
440
+ format ? . Value switch
441
+ {
442
+ "csv" => "text/csv" ,
443
+ "html" => "text/html" ,
444
+ "md" => "text/markdown" ,
445
+ "txt" => "text/plain" ,
446
+ "pdf" => "application/pdf" ,
447
+ "doc" => "application/msword" ,
448
+ "docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ,
449
+ "xls" => "application/vnd.ms-excel" ,
450
+ "xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ,
451
+ _ => null ,
452
+ } ;
453
+
417
454
/// <summary>Gets the <see cref="ImageFormat"/> for the specified MIME type.</summary>
418
455
private static ImageFormat ? GetImageFormat ( string ? mediaType ) =>
419
456
mediaType switch
@@ -425,6 +462,47 @@ private static List<ContentBlock> CreateContents(ChatMessage message)
425
462
_ => null ,
426
463
} ;
427
464
465
+ /// <summary>Gets the MIME type for a <see cref="ImageFormat"/>.</summary>
466
+ private static string ? GetMimeType ( ImageFormat ? format ) =>
467
+ format ? . Value switch
468
+ {
469
+ "jpeg" => "image/jpeg" ,
470
+ "png" => "image/png" ,
471
+ "gif" => "image/gif" ,
472
+ "webp" => "image/webp" ,
473
+ _ => null ,
474
+ } ;
475
+
476
+ /// <summary>Gets the <see cref="VideoFormat"/> for the specified MIME type.</summary>
477
+ private static VideoFormat ? GetVideoFormat ( string ? mediaType ) =>
478
+ mediaType switch
479
+ {
480
+ "video/x-flv" => VideoFormat . Flv ,
481
+ "video/x-matroska" => VideoFormat . Mkv ,
482
+ "video/quicktime" => VideoFormat . Mov ,
483
+ "video/mp4" => VideoFormat . Mp4 ,
484
+ "video/mpeg" => VideoFormat . Mpeg ,
485
+ "video/3gpp" => VideoFormat . Three_gp ,
486
+ "video/webm" => VideoFormat . Webm ,
487
+ "video/x-ms-wmv" => VideoFormat . Wmv ,
488
+ _ => null ,
489
+ } ;
490
+
491
+ /// <summary>Gets the MIME type for a <see cref="VideoFormat"/>.</summary>
492
+ private static string ? GetMimeType ( VideoFormat ? format ) =>
493
+ format ? . Value switch
494
+ {
495
+ "flv" => "video/x-flv" ,
496
+ "mkv" => "video/x-matroska" ,
497
+ "mov" => "video/quicktime" ,
498
+ "mp4" => "video/mp4" ,
499
+ "mpeg" or "mpg" => "video/mpeg" ,
500
+ "three_gp" => "video/3gpp" ,
501
+ "webm" => "video/webm" ,
502
+ "wmv" => "video/x-ms-wmv" ,
503
+ _ => null ,
504
+ } ;
505
+
428
506
/// <summary>Converts a <see cref="Dictionary{String, Object}"/> to a <see cref="Document"/>.</summary>
429
507
private static Document DictionaryToDocument ( IDictionary < string , object ? > ? arguments )
430
508
{
0 commit comments