fix: drop unsupported tools for Mimo 2.6 Flash

This commit is contained in:
Jason Xu committed 2026-09-23 10:00:36 +08:00
1 parent 3fb18e1950
commit 7194c49452
1 file changed
+33 -1
+33 -1
View File
@@ -272,7 +272,11 @@ func (g *Gateway) prepareRouteBodies(from wire.Protocol, route models.Route, inp
if tier == config.TierGo {
baseURL = g.cfg.Upstream.Go
}
upstreamPayload, err := wire.PrepareRequest(from, protocol, input, baseURL)
requestInput := input
if from == wire.Responses && protocol != from && isMimo26Flash(route.ID) {
requestInput = dropNonFunctionResponsesTools(input)
}
upstreamPayload, err := wire.PrepareRequest(from, protocol, requestInput, baseURL)
if err != nil {
if tier != route.Tier {
// A fallback tier may use a stricter wire format than the
@@ -295,6 +299,34 @@ func (g *Gateway) prepareRouteBodies(from wire.Protocol, route models.Route, inp
return bodies, nil
}
func isMimo26Flash(model string) bool {
parts := strings.Split(strings.ToLower(strings.TrimSpace(model)), "/")
return parts[len(parts)-1] == "mimo-v2.6-flash"
}
func dropNonFunctionResponsesTools(input map[string]any) map[string]any {
tools, ok := input["tools"].([]any)
if !ok {
return input
}
filtered := make([]any, 0, len(tools))
for _, raw := range tools {
tool, ok := raw.(map[string]any)
if ok && jsonutil.StringAt(tool, "type") == "function" {
filtered = append(filtered, raw)
}
}
if len(filtered) == len(tools) {
return input
}
request := make(map[string]any, len(input))
for key, value := range input {
request[key] = value
}
request["tools"] = filtered
return request
}
func copyErrorResponse(w http.ResponseWriter, protocol wire.Protocol, resp *http.Response, requestID string) {
body, _ := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
if retryAfter := resp.Header.Get("Retry-After"); retryAfter != "" {