@@ -744,9 +744,13 @@ pub mod gemini_api_types {
744744 message:: UserContent :: Document ( message:: Document {
745745 data, media_type, ..
746746 } ) => {
747- if let Some ( ref media_type) = media_type
748- && !media_type. is_code ( )
749- {
747+ let Some ( media_type) = media_type else {
748+ return Err ( MessageError :: ConversionError (
749+ "A mime type is required for document inputs to Gemini" . to_string ( ) ,
750+ ) ) ;
751+ } ;
752+
753+ if !media_type. is_code ( ) {
750754 let mime_type = media_type. to_mime_type ( ) . to_string ( ) ;
751755
752756 let part = match data {
@@ -784,19 +788,20 @@ pub mod gemini_api_types {
784788 message:: UserContent :: Audio ( message:: Audio {
785789 data, media_type, ..
786790 } ) => {
787- let mime_type = media_type. map ( |x| x. to_mime_type ( ) . to_string ( ) ) ;
791+ let Some ( media_type) = media_type else {
792+ return Err ( MessageError :: ConversionError (
793+ "A mime type is required for audio inputs to Gemini" . to_string ( ) ,
794+ ) ) ;
795+ } ;
796+
797+ let mime_type = media_type. to_mime_type ( ) . to_string ( ) ;
788798
789799 let part = match data {
790800 DocumentSourceKind :: Base64 ( data) => {
791- let Some ( mime_type) = mime_type else {
792- return Err ( MessageError :: ConversionError (
793- "Mime type is required for Base64 encoded strings" . to_string ( ) ,
794- ) ) ;
795- } ;
796801 PartKind :: InlineData ( Blob { data, mime_type } )
797802 }
798803 DocumentSourceKind :: Url ( file_uri) => PartKind :: FileData ( FileData {
799- mime_type,
804+ mime_type : Some ( mime_type ) ,
800805 file_uri,
801806 } ) ,
802807 DocumentSourceKind :: Raw ( _) => {
@@ -826,10 +831,26 @@ pub mod gemini_api_types {
826831 let mime_type = media_type. map ( |media_ty| media_ty. to_mime_type ( ) . to_string ( ) ) ;
827832
828833 let part = match data {
829- DocumentSourceKind :: Url ( file_uri) => PartKind :: FileData ( FileData {
830- mime_type,
831- file_uri,
832- } ) ,
834+ DocumentSourceKind :: Url ( file_uri) => {
835+ if file_uri. starts_with ( "https://www.youtube.com" ) {
836+ PartKind :: FileData ( FileData {
837+ mime_type,
838+ file_uri,
839+ } )
840+ } else {
841+ if mime_type. is_none ( ) {
842+ return Err ( MessageError :: ConversionError (
843+ "A mime type is required for non-Youtube video file inputs to Gemini"
844+ . to_string ( ) ,
845+ ) ) ;
846+ }
847+
848+ PartKind :: FileData ( FileData {
849+ mime_type,
850+ file_uri,
851+ } )
852+ }
853+ }
833854 DocumentSourceKind :: Base64 ( data) => {
834855 let Some ( mime_type) = mime_type else {
835856 return Err ( MessageError :: ConversionError (
0 commit comments