feature: Improves Gemini JSON schema compatibility

Enhances compatibility with the Gemini API by implementing a schema cleaning process.

This includes:
- Centralizing schema cleaning logic for Gemini in a dedicated utility function.
- Converting unsupported schema keywords to hints within the description field.
- Flattening complex schema structures like `anyOf`, `oneOf`, and type arrays to simplify the schema.
- Handling streaming responses with empty tool names, which can occur in subsequent chunks after the initial tool use.
This commit is contained in:
이대희
2025-12-17 17:10:53 +09:00
parent ffdfad8482
commit 1b8e538a77
5 changed files with 901 additions and 24 deletions

View File

@@ -6,6 +6,7 @@ package util
import (
"bytes"
"fmt"
"strings"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
@@ -28,10 +29,18 @@ func Walk(value gjson.Result, path, field string, paths *[]string) {
// For JSON objects and arrays, iterate through each child
value.ForEach(func(key, val gjson.Result) bool {
var childPath string
// Escape special characters for gjson/sjson path syntax
// . -> \.
// * -> \*
// ? -> \?
safeKey := strings.ReplaceAll(key.String(), ".", "\\.")
safeKey = strings.ReplaceAll(safeKey, "*", "\\*")
safeKey = strings.ReplaceAll(safeKey, "?", "\\?")
if path == "" {
childPath = key.String()
childPath = safeKey
} else {
childPath = path + "." + key.String()
childPath = path + "." + safeKey
}
if key.String() == field {
*paths = append(*paths, childPath)