Skip to content

Commit f7718ae

Browse files
yyyu-googlecopybara-github
authored andcommitted
fix: check optional field in aggregate response
PiperOrigin-RevId: 619246627
1 parent 4cab5fd commit f7718ae

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/functions/post_fetch_processing.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,11 @@ export function aggregateResponses(
232232
if (safetyRatingsOfChunk) {
233233
aggregatedResponse.candidates[i].safetyRatings = safetyRatingsOfChunk;
234234
}
235-
if ('parts' in response.candidates[i].content) {
235+
if (
236+
response.candidates[i].content &&
237+
response.candidates[i].content.parts &&
238+
response.candidates[i].content.parts.length > 0
239+
) {
236240
for (const part of response.candidates[i].content.parts) {
237241
if (part.text) {
238242
aggregatedResponse.candidates[i].content.parts[0].text += part.text;

0 commit comments

Comments
 (0)