File tree 1 file changed +15
-1
lines changed
libs/langchain-google-common/src/utils
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -501,7 +501,21 @@ export function responseToChatGenerations(
501
501
response : GoogleLLMResponse
502
502
) : ChatGeneration [ ] {
503
503
const parts = responseToParts ( response ) ;
504
- const ret = parts . map ( ( part ) => partToChatGeneration ( part ) ) ;
504
+ let ret = parts . map ( ( part ) => partToChatGeneration ( part ) ) ;
505
+ if ( ret . every ( ( item ) => typeof item . message . content === "string" ) ) {
506
+ const combinedContent = ret . map ( ( item ) => item . message . content ) . join ( "" ) ;
507
+ const combinedText = ret . map ( ( item ) => item . text ) . join ( "" ) ;
508
+ ret = [
509
+ new ChatGenerationChunk ( {
510
+ message : new AIMessageChunk ( {
511
+ content : combinedContent ,
512
+ additional_kwargs : ret [ ret . length - 1 ] . message . additional_kwargs ,
513
+ } ) ,
514
+ text : combinedText ,
515
+ generationInfo : ret [ ret . length - 1 ] . generationInfo ,
516
+ } ) ,
517
+ ] ;
518
+ }
505
519
return ret ;
506
520
}
507
521
You can’t perform that action at this time.
0 commit comments