Skip to content

Commit f7dfdcd

Browse files
committed
set tools if tools is exists
1 parent 4b1fa59 commit f7dfdcd

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

internal/llm/provider/gemini.go

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,16 @@ func (g *geminiClient) send(ctx context.Context, messages []message.Message, too
175175

176176
history := geminiMessages[:len(geminiMessages)-1] // All but last message
177177
lastMsg := geminiMessages[len(geminiMessages)-1]
178-
chat, _ := g.client.Chats.Create(ctx, g.providerOptions.model.APIModel, &genai.GenerateContentConfig{
178+
config := &genai.GenerateContentConfig{
179179
MaxOutputTokens: int32(g.providerOptions.maxTokens),
180180
SystemInstruction: &genai.Content{
181181
Parts: []*genai.Part{{Text: g.providerOptions.systemMessage}},
182182
},
183-
Tools: g.convertTools(tools),
184-
}, history)
183+
}
184+
if len(tools) > 0 {
185+
config.Tools = g.convertTools(tools)
186+
}
187+
chat, _ := g.client.Chats.Create(ctx, g.providerOptions.model.APIModel, config, history)
185188

186189
attempts := 0
187190
for {
@@ -260,13 +263,16 @@ func (g *geminiClient) stream(ctx context.Context, messages []message.Message, t
260263

261264
history := geminiMessages[:len(geminiMessages)-1] // All but last message
262265
lastMsg := geminiMessages[len(geminiMessages)-1]
263-
chat, _ := g.client.Chats.Create(ctx, g.providerOptions.model.APIModel, &genai.GenerateContentConfig{
266+
config := &genai.GenerateContentConfig{
264267
MaxOutputTokens: int32(g.providerOptions.maxTokens),
265268
SystemInstruction: &genai.Content{
266269
Parts: []*genai.Part{{Text: g.providerOptions.systemMessage}},
267270
},
268-
Tools: g.convertTools(tools),
269-
}, history)
271+
}
272+
if len(tools) > 0 {
273+
config.Tools = g.convertTools(tools)
274+
}
275+
chat, _ := g.client.Chats.Create(ctx, g.providerOptions.model.APIModel, config, history)
270276

271277
attempts := 0
272278
eventChan := make(chan ProviderEvent)
@@ -415,26 +421,26 @@ func (g *geminiClient) shouldRetry(attempts int, err error) (bool, int64, error)
415421
return true, int64(retryMs), nil
416422
}
417423

418-
func (g *geminiClient) toolCalls(resp *genai.GenerateContentResponse) []message.ToolCall {
419-
var toolCalls []message.ToolCall
420-
421-
if len(resp.Candidates) > 0 && resp.Candidates[0].Content != nil {
422-
for _, part := range resp.Candidates[0].Content.Parts {
423-
if part.FunctionCall != nil {
424-
id := "call_" + uuid.New().String()
425-
args, _ := json.Marshal(part.FunctionCall.Args)
426-
toolCalls = append(toolCalls, message.ToolCall{
427-
ID: id,
428-
Name: part.FunctionCall.Name,
429-
Input: string(args),
430-
Type: "function",
431-
})
432-
}
433-
}
434-
}
435-
436-
return toolCalls
437-
}
424+
// func (g *geminiClient) toolCalls(resp *genai.GenerateContentResponse) []message.ToolCall {
425+
// var toolCalls []message.ToolCall
426+
//
427+
// if len(resp.Candidates) > 0 && resp.Candidates[0].Content != nil {
428+
// for _, part := range resp.Candidates[0].Content.Parts {
429+
// if part.FunctionCall != nil {
430+
// id := "call_" + uuid.New().String()
431+
// args, _ := json.Marshal(part.FunctionCall.Args)
432+
// toolCalls = append(toolCalls, message.ToolCall{
433+
// ID: id,
434+
// Name: part.FunctionCall.Name,
435+
// Input: string(args),
436+
// Type: "function",
437+
// })
438+
// }
439+
// }
440+
// }
441+
//
442+
// return toolCalls
443+
// }
438444

439445
func (g *geminiClient) usage(resp *genai.GenerateContentResponse) TokenUsage {
440446
if resp == nil || resp.UsageMetadata == nil {

0 commit comments

Comments
 (0)