Skip to content

Commit 46ce18b

Browse files
justinsbShubyM
authored andcommitted
gollm: tolerate empty streaming parts in Gemini responses (GoogleCloudPlatform#611)
This seems to happen (more?) with gemini-3-pro-preview models.
1 parent 673b594 commit 46ce18b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

gollm/gemini.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,16 @@ func (c *GeminiChat) SendStreaming(ctx context.Context, contents ...any) (ChatRe
465465
}
466466

467467
content := geminiResponse.Candidates[0].Content
468-
if content == nil || content.Parts == nil || len(content.Parts) == 0 {
468+
partsIsEmpty := true
469+
if content != nil {
470+
for _, part := range content.Parts {
471+
if part.Text != "" || part.FunctionCall != nil {
472+
partsIsEmpty = false
473+
break
474+
}
475+
}
476+
}
477+
if partsIsEmpty {
469478
// This happens when there is empty content with the finish reason (STOP) to indicate that streaming response is finished.
470479
// xref: https://github.com/GoogleCloudPlatform/kubectl-ai/issues/306
471480
log.V(1).Info("empty response probably with STOP finishedReason")

0 commit comments

Comments
 (0)