Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit 18f020c

Browse files
monotykamarykujtimiihoxha
authored andcommitted
fix(provider/gemini): prevent empty parts in assistant messages
1 parent d4c8d05 commit 18f020c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

internal/llm/provider/gemini.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,16 @@ func (g *geminiClient) convertMessages(messages []message.Message) []*genai.Cont
6969
Role: "user",
7070
})
7171
case message.Assistant:
72-
content := &genai.Content{
73-
Role: "model",
74-
Parts: []*genai.Part{},
75-
}
72+
var assistantParts []*genai.Part
7673

7774
if msg.Content().String() != "" {
78-
content.Parts = append(content.Parts, &genai.Part{Text: msg.Content().String()})
75+
assistantParts = append(assistantParts, &genai.Part{Text: msg.Content().String()})
7976
}
8077

8178
if len(msg.ToolCalls()) > 0 {
8279
for _, call := range msg.ToolCalls() {
8380
args, _ := parseJsonToMap(call.Input)
84-
content.Parts = append(content.Parts, &genai.Part{
81+
assistantParts = append(assistantParts, &genai.Part{
8582
FunctionCall: &genai.FunctionCall{
8683
Name: call.Name,
8784
Args: args,
@@ -90,7 +87,12 @@ func (g *geminiClient) convertMessages(messages []message.Message) []*genai.Cont
9087
}
9188
}
9289

93-
history = append(history, content)
90+
if len(assistantParts) > 0 {
91+
history = append(history, &genai.Content{
92+
Role: "model",
93+
Parts: assistantParts,
94+
})
95+
}
9496

9597
case message.Tool:
9698
for _, result := range msg.ToolResults() {

0 commit comments

Comments
 (0)