mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
Suppress debug logs for model routing and ignore empty tools arrays
- Comment out verbose routing logs in the API server to reduce noise. - Remove the `tools` field from Qwen client requests when it is an empty array. - Add guards in Claude, Codex, Gemini‑CLI, and Gemini translators to skip tool conversion when the `tools` array is empty, preventing unnecessary payload modifications.
This commit is contained in:
@@ -140,10 +140,10 @@ func (s *Server) unifiedModelsHandler(openaiHandler *openai.OpenAIAPIHandler, cl
|
||||
|
||||
// Route to Claude handler if User-Agent starts with "claude-cli"
|
||||
if strings.HasPrefix(userAgent, "claude-cli") {
|
||||
log.Debugf("Routing /v1/models to Claude handler for User-Agent: %s", userAgent)
|
||||
// log.Debugf("Routing /v1/models to Claude handler for User-Agent: %s", userAgent)
|
||||
claudeHandler.ClaudeModels(c)
|
||||
} else {
|
||||
log.Debugf("Routing /v1/models to OpenAI handler for User-Agent: %s", userAgent)
|
||||
// log.Debugf("Routing /v1/models to OpenAI handler for User-Agent: %s", userAgent)
|
||||
openaiHandler.OpenAIModels(c)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,6 +329,11 @@ func (c *QwenClient) APIRequest(ctx context.Context, modelName, endpoint string,
|
||||
}
|
||||
}
|
||||
|
||||
toolsResult := gjson.GetBytes(jsonBody, "tools")
|
||||
if toolsResult.IsArray() && len(toolsResult.Array()) == 0 {
|
||||
jsonBody, _ = sjson.DeleteBytes(jsonBody, "tools")
|
||||
}
|
||||
|
||||
streamResult := gjson.GetBytes(jsonBody, "stream")
|
||||
if streamResult.Exists() && streamResult.Type == gjson.True {
|
||||
jsonBody, _ = sjson.SetBytes(jsonBody, "stream_options.include_usage", true)
|
||||
|
||||
@@ -244,7 +244,7 @@ func ConvertOpenAIRequestToClaude(modelName string, rawJSON []byte, stream bool)
|
||||
}
|
||||
|
||||
// Tools mapping: OpenAI tools -> Claude Code tools
|
||||
if tools := root.Get("tools"); tools.Exists() && tools.IsArray() {
|
||||
if tools := root.Get("tools"); tools.Exists() && tools.IsArray() && len(tools.Array()) > 0 {
|
||||
var anthropicTools []interface{}
|
||||
tools.ForEach(func(_, tool gjson.Result) bool {
|
||||
if tool.Get("type").String() == "function" {
|
||||
|
||||
@@ -231,7 +231,7 @@ func ConvertOpenAIRequestToCodex(modelName string, rawJSON []byte, stream bool)
|
||||
|
||||
// Map tools (flatten function fields)
|
||||
tools := gjson.GetBytes(rawJSON, "tools")
|
||||
if tools.IsArray() {
|
||||
if tools.IsArray() && len(tools.Array()) > 0 {
|
||||
out, _ = sjson.SetRaw(out, "tools", `[]`)
|
||||
arr := tools.Array()
|
||||
for i := 0; i < len(arr); i++ {
|
||||
|
||||
@@ -215,7 +215,7 @@ func ConvertOpenAIRequestToGeminiCLI(modelName string, rawJSON []byte, _ bool) [
|
||||
|
||||
// tools -> request.tools[0].functionDeclarations
|
||||
tools := gjson.GetBytes(rawJSON, "tools")
|
||||
if tools.IsArray() {
|
||||
if tools.IsArray() && len(tools.Array()) > 0 {
|
||||
out, _ = sjson.SetRawBytes(out, "request.tools", []byte(`[{"functionDeclarations":[]}]`))
|
||||
fdPath := "request.tools.0.functionDeclarations"
|
||||
for _, t := range tools.Array() {
|
||||
|
||||
@@ -215,7 +215,7 @@ func ConvertOpenAIRequestToGemini(modelName string, rawJSON []byte, _ bool) []by
|
||||
|
||||
// tools -> tools[0].functionDeclarations
|
||||
tools := gjson.GetBytes(rawJSON, "tools")
|
||||
if tools.IsArray() {
|
||||
if tools.IsArray() && len(tools.Array()) > 0 {
|
||||
out, _ = sjson.SetRawBytes(out, "tools", []byte(`[{"functionDeclarations":[]}]`))
|
||||
fdPath := "tools.0.functionDeclarations"
|
||||
for _, t := range tools.Array() {
|
||||
|
||||
Reference in New Issue
Block a user