Skip to content

Commit

Permalink
google-common[minor]: Fix single token response issue (#5024)
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul authored Apr 9, 2024
1 parent aec025f commit dad5849
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion libs/langchain-google-common/src/utils/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,21 @@ export function responseToChatGenerations(
response: GoogleLLMResponse
): ChatGeneration[] {
const parts = responseToParts(response);
const ret = parts.map((part) => partToChatGeneration(part));
let ret = parts.map((part) => partToChatGeneration(part));
if (ret.every((item) => typeof item.message.content === "string")) {
const combinedContent = ret.map((item) => item.message.content).join("");
const combinedText = ret.map((item) => item.text).join("");
ret = [
new ChatGenerationChunk({
message: new AIMessageChunk({
content: combinedContent,
additional_kwargs: ret[ret.length - 1].message.additional_kwargs,
}),
text: combinedText,
generationInfo: ret[ret.length - 1].generationInfo,
}),
];
}
return ret;
}

Expand Down

0 comments on commit dad5849

Please sign in to comment.