Skip to content

Commit f4ef9a1

Browse files
encodedzhntrl
andauthored
fix(@langchain/google-genai): safe access around custom content parts (#9584)
Co-authored-by: Hunter Lovell <[email protected]>
1 parent f499d2a commit f4ef9a1

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

.changeset/good-pillows-reflect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@langchain/google-genai": patch
3+
---
4+
5+
safe access around custom content parts

libs/providers/langchain-google-genai/src/utils/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ export function mapGenerateContentResultToChatResult(
527527
}
528528
const [candidate] = response.candidates;
529529
const { content: candidateContent, ...generationInfo } = candidate;
530-
const functionCalls = candidateContent.parts.reduce((acc, p) => {
530+
const functionCalls = candidateContent.parts?.reduce((acc, p) => {
531531
if ("functionCall" in p && p.functionCall) {
532532
acc.push({
533533
...p,
@@ -655,7 +655,7 @@ export function convertResponseContentToChatGenerationChunk(
655655
}
656656
const [candidate] = response.candidates;
657657
const { content: candidateContent, ...generationInfo } = candidate;
658-
const functionCalls = candidateContent.parts.reduce((acc, p) => {
658+
const functionCalls = candidateContent.parts?.reduce((acc, p) => {
659659
if ("functionCall" in p && p.functionCall) {
660660
acc.push({
661661
...p,

0 commit comments

Comments
 (0)