feat(translator): add code_execution and url_context tool passthrough
Unified · Split
| @@ -305,12 +305,14 @@ func ConvertOpenAIRequestToAntigravity(modelName string, inputRawJSON []byte, _ · 304 unmodified lines | |||
| 305 | } | 305 | } |
| 306 | } | 306 | } |
| 307 | 307 | ||
| 308 | // tools -> request.tools[].functionDeclarations + request.tools[].googleSearch passthrough | 308 | // tools -> request.tools[].functionDeclarations + request.tools[].googleSearch/codeExecution/urlContext passthrough |
| 309 | tools := gjson.GetBytes(rawJSON, "tools") | 309 | tools := gjson.GetBytes(rawJSON, "tools") |
| 310 | if tools.IsArray() && len(tools.Array()) > 0 { | 310 | if tools.IsArray() && len(tools.Array()) > 0 { |
| 311 | functionToolNode := []byte(`{}`) | 311 | functionToolNode := []byte(`{}`) |
| 312 | hasFunction := false | 312 | hasFunction := false |
| 313 | googleSearchNodes := make([][]byte, 0) | 313 | googleSearchNodes := make([][]byte, 0) |
| 314 | codeExecutionNodes := make([][]byte, 0) | ||
| 315 | urlContextNodes := make([][]byte, 0) | ||
| 314 | for _, t := range tools.Array() { | 316 | for _, t := range tools.Array() { |
| 315 | if t.Get("type").String() == "function" { | 317 | if t.Get("type").String() == "function" { |
| 316 | fn := t.Get("function") | 318 | fn := t.Get("function") |
| @@ -370,8 +372,28 @@ func ConvertOpenAIRequestToAntigravity(modelName string, inputRawJSON []byte, _ · 53 unmodified lines | |||
| 370 | } | 372 | } |
| 371 | googleSearchNodes = append(googleSearchNodes, googleToolNode) | 373 | googleSearchNodes = append(googleSearchNodes, googleToolNode) |
| 372 | } | 374 | } |
| 375 | if ce := t.Get("code_execution"); ce.Exists() { | ||
| 376 | codeToolNode := []byte(`{}`) | ||
| 377 | var errSet error | ||
| 378 | codeToolNode, errSet = sjson.SetRawBytes(codeToolNode, "codeExecution", []byte(ce.Raw)) | ||
| 379 | if errSet != nil { | ||
| 380 | log.Warnf("Failed to set codeExecution tool: %v", errSet) | ||
| 381 | continue | ||
| 382 | } | ||
| 383 | codeExecutionNodes = append(codeExecutionNodes, codeToolNode) | ||
| 384 | } | ||
| 385 | if uc := t.Get("url_context"); uc.Exists() { | ||
| 386 | urlToolNode := []byte(`{}`) | ||
| 387 | var errSet error | ||
| 388 | urlToolNode, errSet = sjson.SetRawBytes(urlToolNode, "urlContext", []byte(uc.Raw)) | ||
| 389 | if errSet != nil { | ||
| 390 | log.Warnf("Failed to set urlContext tool: %v", errSet) | ||
| 391 | continue | ||
| 392 | } | ||
| 393 | urlContextNodes = append(urlContextNodes, urlToolNode) | ||
| 394 | } | ||
| 373 | } | 395 | } |
| 374 | if hasFunction || len(googleSearchNodes) > 0 { | 396 | if hasFunction || len(googleSearchNodes) > 0 || len(codeExecutionNodes) > 0 || len(urlContextNodes) > 0 { |
| 375 | toolsNode := []byte("[]") | 397 | toolsNode := []byte("[]") |
| 376 | if hasFunction { | 398 | if hasFunction { |
| 377 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", functionToolNode) | 399 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", functionToolNode) |
| @@ -379,6 +401,12 @@ func ConvertOpenAIRequestToAntigravity(modelName string, inputRawJSON []byte, _ · 1 unmodified line | |||
| 379 | for _, googleNode := range googleSearchNodes { | 401 | for _, googleNode := range googleSearchNodes { |
| 380 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", googleNode) | 402 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", googleNode) |
| 381 | } | 403 | } |
| 404 | for _, codeNode := range codeExecutionNodes { | ||
| 405 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", codeNode) | ||
| 406 | } | ||
| 407 | for _, urlNode := range urlContextNodes { | ||
| 408 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", urlNode) | ||
| 409 | } | ||
| 382 | out, _ = sjson.SetRawBytes(out, "request.tools", toolsNode) | 410 | out, _ = sjson.SetRawBytes(out, "request.tools", toolsNode) |
| 383 | } | 411 | } |
| 384 | } | 412 | } |
| @@ -283,12 +283,14 @@ func ConvertOpenAIRequestToGeminiCLI(modelName string, inputRawJSON []byte, _ bo · 282 unmodified lines | |||
| 283 | } | 283 | } |
| 284 | } | 284 | } |
| 285 | 285 | ||
| 286 | // tools -> request.tools[].functionDeclarations + request.tools[].googleSearch passthrough | 286 | // tools -> request.tools[].functionDeclarations + request.tools[].googleSearch/codeExecution/urlContext passthrough |
| 287 | tools := gjson.GetBytes(rawJSON, "tools") | 287 | tools := gjson.GetBytes(rawJSON, "tools") |
| 288 | if tools.IsArray() && len(tools.Array()) > 0 { | 288 | if tools.IsArray() && len(tools.Array()) > 0 { |
| 289 | functionToolNode := []byte(`{}`) | 289 | functionToolNode := []byte(`{}`) |
| 290 | hasFunction := false | 290 | hasFunction := false |
| 291 | googleSearchNodes := make([][]byte, 0) | 291 | googleSearchNodes := make([][]byte, 0) |
| 292 | codeExecutionNodes := make([][]byte, 0) | ||
| 293 | urlContextNodes := make([][]byte, 0) | ||
| 292 | for _, t := range tools.Array() { | 294 | for _, t := range tools.Array() { |
| 293 | if t.Get("type").String() == "function" { | 295 | if t.Get("type").String() == "function" { |
| 294 | fn := t.Get("function") | 296 | fn := t.Get("function") |
| @@ -348,8 +350,28 @@ func ConvertOpenAIRequestToGeminiCLI(modelName string, inputRawJSON []byte, _ bo · 53 unmodified lines | |||
| 348 | } | 350 | } |
| 349 | googleSearchNodes = append(googleSearchNodes, googleToolNode) | 351 | googleSearchNodes = append(googleSearchNodes, googleToolNode) |
| 350 | } | 352 | } |
| 353 | if ce := t.Get("code_execution"); ce.Exists() { | ||
| 354 | codeToolNode := []byte(`{}`) | ||
| 355 | var errSet error | ||
| 356 | codeToolNode, errSet = sjson.SetRawBytes(codeToolNode, "codeExecution", []byte(ce.Raw)) | ||
| 357 | if errSet != nil { | ||
| 358 | log.Warnf("Failed to set codeExecution tool: %v", errSet) | ||
| 359 | continue | ||
| 360 | } | ||
| 361 | codeExecutionNodes = append(codeExecutionNodes, codeToolNode) | ||
| 362 | } | ||
| 363 | if uc := t.Get("url_context"); uc.Exists() { | ||
| 364 | urlToolNode := []byte(`{}`) | ||
| 365 | var errSet error | ||
| 366 | urlToolNode, errSet = sjson.SetRawBytes(urlToolNode, "urlContext", []byte(uc.Raw)) | ||
| 367 | if errSet != nil { | ||
| 368 | log.Warnf("Failed to set urlContext tool: %v", errSet) | ||
| 369 | continue | ||
| 370 | } | ||
| 371 | urlContextNodes = append(urlContextNodes, urlToolNode) | ||
| 372 | } | ||
| 351 | } | 373 | } |
| 352 | if hasFunction || len(googleSearchNodes) > 0 { | 374 | if hasFunction || len(googleSearchNodes) > 0 || len(codeExecutionNodes) > 0 || len(urlContextNodes) > 0 { |
| 353 | toolsNode := []byte("[]") | 375 | toolsNode := []byte("[]") |
| 354 | if hasFunction { | 376 | if hasFunction { |
| 355 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", functionToolNode) | 377 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", functionToolNode) |
| @@ -357,6 +379,12 @@ func ConvertOpenAIRequestToGeminiCLI(modelName string, inputRawJSON []byte, _ bo · 1 unmodified line | |||
| 357 | for _, googleNode := range googleSearchNodes { | 379 | for _, googleNode := range googleSearchNodes { |
| 358 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", googleNode) | 380 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", googleNode) |
| 359 | } | 381 | } |
| 382 | for _, codeNode := range codeExecutionNodes { | ||
| 383 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", codeNode) | ||
| 384 | } | ||
| 385 | for _, urlNode := range urlContextNodes { | ||
| 386 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", urlNode) | ||
| 387 | } | ||
| 360 | out, _ = sjson.SetRawBytes(out, "request.tools", toolsNode) | 388 | out, _ = sjson.SetRawBytes(out, "request.tools", toolsNode) |
| 361 | } | 389 | } |
| 362 | } | 390 | } |
| @@ -289,12 +289,14 @@ func ConvertOpenAIRequestToGemini(modelName string, inputRawJSON []byte, _ bool) · 288 unmodified lines | |||
| 289 | } | 289 | } |
| 290 | } | 290 | } |
| 291 | 291 | ||
| 292 | // tools -> tools[].functionDeclarations + tools[].googleSearch passthrough | 292 | // tools -> tools[].functionDeclarations + tools[].googleSearch/codeExecution/urlContext passthrough |
| 293 | tools := gjson.GetBytes(rawJSON, "tools") | 293 | tools := gjson.GetBytes(rawJSON, "tools") |
| 294 | if tools.IsArray() && len(tools.Array()) > 0 { | 294 | if tools.IsArray() && len(tools.Array()) > 0 { |
| 295 | functionToolNode := []byte(`{}`) | 295 | functionToolNode := []byte(`{}`) |
| 296 | hasFunction := false | 296 | hasFunction := false |
| 297 | googleSearchNodes := make([][]byte, 0) | 297 | googleSearchNodes := make([][]byte, 0) |
| 298 | codeExecutionNodes := make([][]byte, 0) | ||
| 299 | urlContextNodes := make([][]byte, 0) | ||
| 298 | for _, t := range tools.Array() { | 300 | for _, t := range tools.Array() { |
| 299 | if t.Get("type").String() == "function" { | 301 | if t.Get("type").String() == "function" { |
| 300 | fn := t.Get("function") | 302 | fn := t.Get("function") |
| @@ -354,8 +356,28 @@ func ConvertOpenAIRequestToGemini(modelName string, inputRawJSON []byte, _ bool) · 53 unmodified lines | |||
| 354 | } | 356 | } |
| 355 | googleSearchNodes = append(googleSearchNodes, googleToolNode) | 357 | googleSearchNodes = append(googleSearchNodes, googleToolNode) |
| 356 | } | 358 | } |
| 359 | if ce := t.Get("code_execution"); ce.Exists() { | ||
| 360 | codeToolNode := []byte(`{}`) | ||
| 361 | var errSet error | ||
| 362 | codeToolNode, errSet = sjson.SetRawBytes(codeToolNode, "codeExecution", []byte(ce.Raw)) | ||
| 363 | if errSet != nil { | ||
| 364 | log.Warnf("Failed to set codeExecution tool: %v", errSet) | ||
| 365 | continue | ||
| 366 | } | ||
| 367 | codeExecutionNodes = append(codeExecutionNodes, codeToolNode) | ||
| 368 | } | ||
| 369 | if uc := t.Get("url_context"); uc.Exists() { | ||
| 370 | urlToolNode := []byte(`{}`) | ||
| 371 | var errSet error | ||
| 372 | urlToolNode, errSet = sjson.SetRawBytes(urlToolNode, "urlContext", []byte(uc.Raw)) | ||
| 373 | if errSet != nil { | ||
| 374 | log.Warnf("Failed to set urlContext tool: %v", errSet) | ||
| 375 | continue | ||
| 376 | } | ||
| 377 | urlContextNodes = append(urlContextNodes, urlToolNode) | ||
| 378 | } | ||
| 357 | } | 379 | } |
| 358 | if hasFunction || len(googleSearchNodes) > 0 { | 380 | if hasFunction || len(googleSearchNodes) > 0 || len(codeExecutionNodes) > 0 || len(urlContextNodes) > 0 { |
| 359 | toolsNode := []byte("[]") | 381 | toolsNode := []byte("[]") |
| 360 | if hasFunction { | 382 | if hasFunction { |
| 361 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", functionToolNode) | 383 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", functionToolNode) |
| @@ -363,6 +385,12 @@ func ConvertOpenAIRequestToGemini(modelName string, inputRawJSON []byte, _ bool) · 1 unmodified line | |||
| 363 | for _, googleNode := range googleSearchNodes { | 385 | for _, googleNode := range googleSearchNodes { |
| 364 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", googleNode) | 386 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", googleNode) |
| 365 | } | 387 | } |
| 388 | for _, codeNode := range codeExecutionNodes { | ||
| 389 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", codeNode) | ||
| 390 | } | ||
| 391 | for _, urlNode := range urlContextNodes { | ||
| 392 | toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", urlNode) | ||
| 393 | } | ||
| 366 | out, _ = sjson.SetRawBytes(out, "tools", toolsNode) | 394 | out, _ = sjson.SetRawBytes(out, "tools", toolsNode) |
| 367 | } | 395 | } |
| 368 | } | 396 | } |