- Added fallback to set default `parametersJsonSchema` when `parameters` key is absent. - Enhanced logging to capture detailed errors during schema transformation. - Refined tool declaration appending logic for robustness.
Unified · Split
| @@ -250,8 +250,34 @@ func ConvertOpenAIRequestToGeminiCLI(modelName string, inputRawJSON []byte, _ bo · 249 unmodified lines | |||
| 250 | if t.Get("type").String() == "function" { | 250 | if t.Get("type").String() == "function" { |
| 251 | fn := t.Get("function") | 251 | fn := t.Get("function") |
| 252 | if fn.Exists() && fn.IsObject() { | 252 | if fn.Exists() && fn.IsObject() { |
| 253 | parametersJsonSchema, _ := util.RenameKey(fn.Raw, "parameters", "parametersJsonSchema") | 253 | fnRaw := fn.Raw |
| 254 | out, _ = sjson.SetRawBytes(out, fdPath+".-1", []byte(parametersJsonSchema)) | 254 | if fn.Get("parameters").Exists() { |
| 255 | renamed, errRename := util.RenameKey(fnRaw, "parameters", "parametersJsonSchema") | ||
| 256 | if errRename != nil { | ||
| 257 | log.Warnf("Failed to rename parameters for tool '%s': %v", fn.Get("name").String(), errRename) | ||
| 258 | } else { | ||
| 259 | fnRaw = renamed | ||
| 260 | } | ||
| 261 | } else { | ||
| 262 | var errSet error | ||
| 263 | fnRaw, errSet = sjson.Set(fnRaw, "parametersJsonSchema.type", "object") | ||
| 264 | if errSet != nil { | ||
| 265 | log.Warnf("Failed to set default schema type for tool '%s': %v", fn.Get("name").String(), errSet) | ||
| 266 | continue | ||
| 267 | } | ||
| 268 | fnRaw, errSet = sjson.Set(fnRaw, "parametersJsonSchema.properties", map[string]interface{}{}) | ||
| 269 | if errSet != nil { | ||
| 270 | log.Warnf("Failed to set default schema properties for tool '%s': %v", fn.Get("name").String(), errSet) | ||
| 271 | continue | ||
| 272 | } | ||
| 273 | } | ||
| 274 | |||
| 275 | tmp, errSet := sjson.SetRawBytes(out, fdPath+".-1", []byte(fnRaw)) | ||
| 276 | if errSet != nil { | ||
| 277 | log.Warnf("Failed to append tool declaration for '%s': %v", fn.Get("name").String(), errSet) | ||
| 278 | continue | ||
| 279 | } | ||
| 280 | out = tmp | ||
| 255 | } | 281 | } |
| 256 | } | 282 | } |
| 257 | } | 283 | } |