mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
fix(translator): improve error handling for function parameters schema transformation
- 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.
This commit is contained in:
@@ -250,8 +250,34 @@ func ConvertOpenAIRequestToGeminiCLI(modelName string, inputRawJSON []byte, _ bo
|
|||||||
if t.Get("type").String() == "function" {
|
if t.Get("type").String() == "function" {
|
||||||
fn := t.Get("function")
|
fn := t.Get("function")
|
||||||
if fn.Exists() && fn.IsObject() {
|
if fn.Exists() && fn.IsObject() {
|
||||||
parametersJsonSchema, _ := util.RenameKey(fn.Raw, "parameters", "parametersJsonSchema")
|
fnRaw := fn.Raw
|
||||||
out, _ = sjson.SetRawBytes(out, fdPath+".-1", []byte(parametersJsonSchema))
|
if fn.Get("parameters").Exists() {
|
||||||
|
renamed, errRename := util.RenameKey(fnRaw, "parameters", "parametersJsonSchema")
|
||||||
|
if errRename != nil {
|
||||||
|
log.Warnf("Failed to rename parameters for tool '%s': %v", fn.Get("name").String(), errRename)
|
||||||
|
} else {
|
||||||
|
fnRaw = renamed
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var errSet error
|
||||||
|
fnRaw, errSet = sjson.Set(fnRaw, "parametersJsonSchema.type", "object")
|
||||||
|
if errSet != nil {
|
||||||
|
log.Warnf("Failed to set default schema type for tool '%s': %v", fn.Get("name").String(), errSet)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fnRaw, errSet = sjson.Set(fnRaw, "parametersJsonSchema.properties", map[string]interface{}{})
|
||||||
|
if errSet != nil {
|
||||||
|
log.Warnf("Failed to set default schema properties for tool '%s': %v", fn.Get("name").String(), errSet)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp, errSet := sjson.SetRawBytes(out, fdPath+".-1", []byte(fnRaw))
|
||||||
|
if errSet != nil {
|
||||||
|
log.Warnf("Failed to append tool declaration for '%s': %v", fn.Get("name").String(), errSet)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out = tmp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user