@@ -815,40 +815,51 @@ export class Serialize {
815815 return vec !== undefined && ! Array . isArray ( vec ) && Object . values ( vec ) . some ( ArrayInputGuards . is2DArray ) ;
816816 } ;
817817
818+ private static withImages = async < T extends Record < string , any > > (
819+ config : T ,
820+ imgs ?: ( string | Buffer ) [ ] ,
821+ imgProps ?: string [ ]
822+ ) : Promise < T > => {
823+ if ( imgs == undefined && imgProps == undefined ) {
824+ return config ;
825+ }
826+ return {
827+ ...config ,
828+ images : TextArray . fromPartial ( {
829+ values : imgs ? await Promise . all ( imgs . map ( toBase64FromMedia ) ) : undefined ,
830+ } ) ,
831+ imageProperties : TextArray . fromPartial ( { values : imgProps } ) ,
832+ } ;
833+ } ;
818834 private static generativeQuery = async (
819835 generative : GenerativeConfigRuntime ,
820836 opts ?: { metadata ?: boolean ; images ?: ( string | Buffer ) [ ] ; imageProperties ?: string [ ] }
821837 ) : Promise < GenerativeProvider > => {
822- const withImages = async < T extends Record < string , any > > (
823- config : T ,
824- imgs ?: ( string | Buffer ) [ ] ,
825- imgProps ?: string [ ]
826- ) : Promise < T > => {
827- if ( imgs == undefined && imgProps == undefined ) {
828- return config ;
829- }
830- return {
831- ...config ,
832- images : TextArray . fromPartial ( {
833- values : imgs ? await Promise . all ( imgs . map ( toBase64FromMedia ) ) : undefined ,
834- } ) ,
835- imageProperties : TextArray . fromPartial ( { values : imgProps } ) ,
836- } ;
837- } ;
838-
839838 const provider = GenerativeProvider . fromPartial ( { returnMetadata : opts ?. metadata } ) ;
840839 switch ( generative . name ) {
841840 case 'generative-anthropic' :
842- provider . anthropic = await withImages ( generative . config || { } , opts ?. images , opts ?. imageProperties ) ;
841+ provider . anthropic = await Serialize . withImages (
842+ generative . config || { } ,
843+ opts ?. images ,
844+ opts ?. imageProperties
845+ ) ;
843846 break ;
844847 case 'generative-anyscale' :
845848 provider . anyscale = generative . config || { } ;
846849 break ;
847850 case 'generative-aws' :
848- provider . aws = await withImages ( generative . config || { } , opts ?. images , opts ?. imageProperties ) ;
851+ provider . aws = await Serialize . withImages (
852+ generative . config || { } ,
853+ opts ?. images ,
854+ opts ?. imageProperties
855+ ) ;
849856 break ;
850857 case 'generative-cohere' :
851- provider . cohere = generative . config || { } ;
858+ provider . cohere = await Serialize . withImages (
859+ generative . config || { } ,
860+ opts ?. images ,
861+ opts ?. imageProperties
862+ ) ;
852863 break ;
853864 case 'generative-databricks' :
854865 provider . databricks = generative . config || { } ;
@@ -860,7 +871,11 @@ export class Serialize {
860871 provider . friendliai = generative . config || { } ;
861872 break ;
862873 case 'generative-google' :
863- provider . google = await withImages ( generative . config || { } , opts ?. images , opts ?. imageProperties ) ;
874+ provider . google = await Serialize . withImages (
875+ generative . config || { } ,
876+ opts ?. images ,
877+ opts ?. imageProperties
878+ ) ;
864879 break ;
865880 case 'generative-mistral' :
866881 provider . mistral = generative . config || { } ;
@@ -869,10 +884,18 @@ export class Serialize {
869884 provider . nvidia = generative . config || { } ;
870885 break ;
871886 case 'generative-ollama' :
872- provider . ollama = await withImages ( generative . config || { } , opts ?. images , opts ?. imageProperties ) ;
887+ provider . ollama = await Serialize . withImages (
888+ generative . config || { } ,
889+ opts ?. images ,
890+ opts ?. imageProperties
891+ ) ;
873892 break ;
874893 case 'generative-openai' :
875- provider . openai = await withImages ( generative . config || { } , opts ?. images , opts ?. imageProperties ) ;
894+ provider . openai = await Serialize . withImages (
895+ generative . config || { } ,
896+ opts ?. images ,
897+ opts ?. imageProperties
898+ ) ;
876899 break ;
877900 }
878901 return provider ;
0 commit comments