History

Merge pull request #1317 from yinkev/feat/gemini-tools-passthrough

feat(translator): add code_execution and url_context tool passthrough

Luis Pater committed 9 months ago

Commit c3e94a82 parents 6b6d030 538039f3 files · +90 −6Browse files

Unified · Split

3 files
  1. internal/translator/antigravity/openai/chat-completions/antigravity_openai_request.go +30 −2
  2. internal/translator/gemini-cli/openai/chat-completions/gemini-cli_openai_request.go +30 −2
  3. internal/translator/gemini/openai/chat-completions/gemini_openai_request.go +30 −2
internal/translator/antigravity/openai/chat-completions/antigravity_openai_request.go+30−2
@@ -305,12 +305,14 @@ func ConvertOpenAIRequestToAntigravity(modelName string, inputRawJSON []byte, _ · 304 unmodified lines
305305 }
306306 }
307307
308− // tools -> request.tools[].functionDeclarations + request.tools[].googleSearch passthrough
308+ // tools -> request.tools[].functionDeclarations + request.tools[].googleSearch/codeExecution/urlContext passthrough
309309 tools := gjson.GetBytes(rawJSON, "tools")
310310 if tools.IsArray() && len(tools.Array()) > 0 {
311311 functionToolNode := []byte(`{}`)
312312 hasFunction := false
313313 googleSearchNodes := make([][]byte, 0)
314+ codeExecutionNodes := make([][]byte, 0)
315+ urlContextNodes := make([][]byte, 0)
314316 for _, t := range tools.Array() {
315317 if t.Get("type").String() == "function" {
316318 fn := t.Get("function")
@@ -370,8 +372,28 @@ func ConvertOpenAIRequestToAntigravity(modelName string, inputRawJSON []byte, _ · 53 unmodified lines
370372 }
371373 googleSearchNodes = append(googleSearchNodes, googleToolNode)
372374 }
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+ }
373395 }
374− if hasFunction || len(googleSearchNodes) > 0 {
396+ if hasFunction || len(googleSearchNodes) > 0 || len(codeExecutionNodes) > 0 || len(urlContextNodes) > 0 {
375397 toolsNode := []byte("[]")
376398 if hasFunction {
377399 toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", functionToolNode)
@@ -379,6 +401,12 @@ func ConvertOpenAIRequestToAntigravity(modelName string, inputRawJSON []byte, _ · 1 unmodified line
379401 for _, googleNode := range googleSearchNodes {
380402 toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", googleNode)
381403 }
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+ }
382410 out, _ = sjson.SetRawBytes(out, "request.tools", toolsNode)
383411 }
384412 }
internal/translator/gemini-cli/openai/chat-completions/gemini-cli_openai_request.go+30−2
@@ -283,12 +283,14 @@ func ConvertOpenAIRequestToGeminiCLI(modelName string, inputRawJSON []byte, _ bo · 282 unmodified lines
283283 }
284284 }
285285
286− // tools -> request.tools[].functionDeclarations + request.tools[].googleSearch passthrough
286+ // tools -> request.tools[].functionDeclarations + request.tools[].googleSearch/codeExecution/urlContext passthrough
287287 tools := gjson.GetBytes(rawJSON, "tools")
288288 if tools.IsArray() && len(tools.Array()) > 0 {
289289 functionToolNode := []byte(`{}`)
290290 hasFunction := false
291291 googleSearchNodes := make([][]byte, 0)
292+ codeExecutionNodes := make([][]byte, 0)
293+ urlContextNodes := make([][]byte, 0)
292294 for _, t := range tools.Array() {
293295 if t.Get("type").String() == "function" {
294296 fn := t.Get("function")
@@ -348,8 +350,28 @@ func ConvertOpenAIRequestToGeminiCLI(modelName string, inputRawJSON []byte, _ bo · 53 unmodified lines
348350 }
349351 googleSearchNodes = append(googleSearchNodes, googleToolNode)
350352 }
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+ }
351373 }
352− if hasFunction || len(googleSearchNodes) > 0 {
374+ if hasFunction || len(googleSearchNodes) > 0 || len(codeExecutionNodes) > 0 || len(urlContextNodes) > 0 {
353375 toolsNode := []byte("[]")
354376 if hasFunction {
355377 toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", functionToolNode)
@@ -357,6 +379,12 @@ func ConvertOpenAIRequestToGeminiCLI(modelName string, inputRawJSON []byte, _ bo · 1 unmodified line
357379 for _, googleNode := range googleSearchNodes {
358380 toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", googleNode)
359381 }
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+ }
360388 out, _ = sjson.SetRawBytes(out, "request.tools", toolsNode)
361389 }
362390 }
internal/translator/gemini/openai/chat-completions/gemini_openai_request.go+30−2
@@ -289,12 +289,14 @@ func ConvertOpenAIRequestToGemini(modelName string, inputRawJSON []byte, _ bool) · 288 unmodified lines
289289 }
290290 }
291291
292− // tools -> tools[].functionDeclarations + tools[].googleSearch passthrough
292+ // tools -> tools[].functionDeclarations + tools[].googleSearch/codeExecution/urlContext passthrough
293293 tools := gjson.GetBytes(rawJSON, "tools")
294294 if tools.IsArray() && len(tools.Array()) > 0 {
295295 functionToolNode := []byte(`{}`)
296296 hasFunction := false
297297 googleSearchNodes := make([][]byte, 0)
298+ codeExecutionNodes := make([][]byte, 0)
299+ urlContextNodes := make([][]byte, 0)
298300 for _, t := range tools.Array() {
299301 if t.Get("type").String() == "function" {
300302 fn := t.Get("function")
@@ -354,8 +356,28 @@ func ConvertOpenAIRequestToGemini(modelName string, inputRawJSON []byte, _ bool) · 53 unmodified lines
354356 }
355357 googleSearchNodes = append(googleSearchNodes, googleToolNode)
356358 }
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+ }
357379 }
358− if hasFunction || len(googleSearchNodes) > 0 {
380+ if hasFunction || len(googleSearchNodes) > 0 || len(codeExecutionNodes) > 0 || len(urlContextNodes) > 0 {
359381 toolsNode := []byte("[]")
360382 if hasFunction {
361383 toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", functionToolNode)
@@ -363,6 +385,12 @@ func ConvertOpenAIRequestToGemini(modelName string, inputRawJSON []byte, _ bool) · 1 unmodified line
363385 for _, googleNode := range googleSearchNodes {
364386 toolsNode, _ = sjson.SetRawBytes(toolsNode, "-1", googleNode)
365387 }
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+ }
366394 out, _ = sjson.SetRawBytes(out, "tools", toolsNode)
367395 }
368396 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t