Skip to content

Commit 2b26813

Browse files
committed
fix tool bug, needed thought_signature
1 parent 9dbe9b9 commit 2b26813

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ storybook-static/
3535
test-results.xml
3636

3737
docsite/
38-
testai

cmd/testai/main-testai.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
DefaultAnthropicModel = "claude-sonnet-4-5"
2828
DefaultOpenAIModel = "gpt-5.1"
2929
DefaultOpenRouterModel = "mistralai/mistral-small-3.2-24b-instruct"
30-
DefaultGeminiModel = "gemini-2.0-flash-exp"
30+
DefaultGeminiModel = "gemini-3-pro-preview"
3131
)
3232

3333
// TestResponseWriter implements http.ResponseWriter and additional interfaces for testing
@@ -374,6 +374,12 @@ func testT3(ctx context.Context) {
374374
testOpenAIComp(ctx, "gpt-4o", "what is 2+2? please be brief", nil)
375375
}
376376

377+
func testT4(ctx context.Context) {
378+
tool := aiusechat.GetAdderToolDefinition()
379+
tools := []uctypes.ToolDefinition{tool}
380+
testGemini(ctx, DefaultGeminiModel, "what is 2+2+8, use the provider adder tool", tools)
381+
}
382+
377383
func printUsage() {
378384
fmt.Println("Usage: go run main-testai.go [--anthropic|--openaicomp|--openrouter|--gemini] [--tools] [--model <model>] [message]")
379385
fmt.Println("Examples:")
@@ -403,7 +409,7 @@ func printUsage() {
403409
}
404410

405411
func main() {
406-
var anthropic, openaicomp, openrouter, gemini, tools, help, t1, t2, t3 bool
412+
var anthropic, openaicomp, openrouter, gemini, tools, help, t1, t2, t3, t4 bool
407413
var model string
408414
flag.BoolVar(&anthropic, "anthropic", false, "Use Anthropic API instead of OpenAI")
409415
flag.BoolVar(&openaicomp, "openaicomp", false, "Use OpenAI Completions API")
@@ -414,7 +420,8 @@ func main() {
414420
flag.BoolVar(&help, "help", false, "Show usage information")
415421
flag.BoolVar(&t1, "t1", false, fmt.Sprintf("Run preset T1 test (%s with 'what is 2+2')", DefaultAnthropicModel))
416422
flag.BoolVar(&t2, "t2", false, fmt.Sprintf("Run preset T2 test (%s with 'what is 2+2')", DefaultOpenAIModel))
417-
flag.BoolVar(&t3, "t3", false, "Run preset T3 test (OpenAI Completions API with gpt-4o)")
423+
flag.BoolVar(&t3, "t3", false, "Run preset T3 test (OpenAI Completions API with gpt-5.1)")
424+
flag.BoolVar(&t4, "t4", false, "Run preset T4 test (OpenAI Completions API with gemini-3-pro-preview)")
418425
flag.Parse()
419426

420427
if help {
@@ -437,6 +444,10 @@ func main() {
437444
testT3(ctx)
438445
return
439446
}
447+
if t4 {
448+
testT4(ctx)
449+
return
450+
}
440451

441452
// Set default model based on API type if not provided
442453
if model == "" {

pkg/aiusechat/gemini/gemini-backend.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,13 @@ func RunGeminiChatStep(
263263

264264
if resp.StatusCode != http.StatusOK {
265265
bodyBytes, _ := io.ReadAll(resp.Body)
266-
266+
267267
// Try to parse as Gemini error
268268
var geminiErr GeminiErrorResponse
269269
if err := json.Unmarshal(bodyBytes, &geminiErr); err == nil && geminiErr.Error != nil {
270270
return nil, nil, nil, fmt.Errorf("Gemini API error (%d): %s", geminiErr.Error.Code, geminiErr.Error.Message)
271271
}
272-
272+
273273
return nil, nil, nil, fmt.Errorf("API returned status %d: %s", resp.StatusCode, utilfn.TruncateString(string(bodyBytes), 120))
274274
}
275275

@@ -365,7 +365,7 @@ func processGeminiStream(
365365
}
366366

367367
candidate := chunk.Candidates[0]
368-
368+
369369
// Store finish reason
370370
if candidate.FinishReason != "" {
371371
finishReason = candidate.FinishReason
@@ -389,11 +389,11 @@ func processGeminiStream(
389389
if part.FunctionCall != nil {
390390
// Track function call for tool use
391391
toolCallId := uuid.New().String()
392-
392+
393393
// Send tool progress using aiutil
394394
argsBytes, _ := json.Marshal(part.FunctionCall.Args)
395395
aiutil.SendToolProgress(toolCallId, part.FunctionCall.Name, argsBytes, chatOpts, sseHandler, false)
396-
396+
397397
functionCalls = append(functionCalls, GeminiMessagePart{
398398
FunctionCall: part.FunctionCall,
399399
ToolUseData: &uctypes.UIMessageDataToolUse{

pkg/aiusechat/gemini/gemini-types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ type GeminiFileData struct {
8989

9090
// GeminiFunctionCall represents a function call from the model
9191
type GeminiFunctionCall struct {
92-
Name string `json:"name"`
93-
Args map[string]any `json:"args,omitempty"`
92+
Name string `json:"name"`
93+
Args map[string]any `json:"args,omitempty"`
94+
ThoughtSignature string `json:"thought_signature,omitempty"`
9495
}
9596

9697
// GeminiFunctionResponse represents a function execution result

0 commit comments

Comments
 (0)