mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-11-12 20:27:23 +00:00
fix(gateway): AUTO 被密钥模型范围拦下时报错误导 + 编辑器给出提示
一个密钥的模型范围不含 AUTO 时,它用不了 AUTO —— 范围过滤发生在链之前。 但这两条路径都不说真话: 1. 请求侧:AUTO 走的是通用分支,返回 model_not_found "model \"AUTO\" is not configured",读起来像 AUTO 没配置。非 AUTO 模型早就有 model_not_allowed 的专门提示,AUTO 漏了。补上,并说明修法(把 AUTO 加进该密钥的 models, 或去掉范围限制)。 2. 编辑器侧:per-key AUTO 链编辑器可以正常配链、保存也成功,看起来一切正常, 但该密钥的每个请求都会 403。管理员无从得知。现在弹窗顶部在检测到冲突时 显示警告,并列出当前范围。 刻意不做的事:不自动把 AUTO 加进该密钥的模型范围。那等于悄悄授予运营 没要求的访问权,比一个显眼的警告更糟。 判据 1 条,除确认提示出现外还断言该函数体内没有 PUT/POST/fetch/api —— 它只报告,不得写回。变异(去掉 AUTO 判断)判红。 CDP 实测四种场景:范围含 AUTO → 无提示;范围不含 → 警告并列出范围; 空范围(不受限)→ 无提示;范围含 AUTO → 无提示。 Co-Authored-By: ModelRouter <noreply@modelrouter.dev>
This commit is contained in:
@ -452,6 +452,19 @@ func (g *Gateway) handleChat(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
}
|
||||
// A key whose model scope does not include AUTO cannot use AUTO at all,
|
||||
// even when it has its own AUTO chain configured. That combination is
|
||||
// easy to set up by accident and produced a misleading error: the request
|
||||
// fell through to the generic "model %q is not configured" below, which
|
||||
// claims AUTO does not exist — it does, this key just may not use it. Name
|
||||
// the actual reason so the admin can fix the scope.
|
||||
if isAuto(model) {
|
||||
if allow := g.allowedModels(r.Context()); allow != nil && !g.hasScopeModel(allow, model) {
|
||||
writeError(w, http.StatusForbidden, "model_not_allowed",
|
||||
fmt.Sprintf("model %q is not in this key's model scope, so it cannot use AUTO; add %q to the key's models or remove the scope restriction", model, model))
|
||||
return
|
||||
}
|
||||
}
|
||||
cands, effective := g.resolveCands(r.Context(), &req)
|
||||
if len(cands) == 0 {
|
||||
writeError(w, http.StatusNotFound, "model_not_found", fmt.Sprintf("model %q is not configured", model))
|
||||
|
||||
Reference in New Issue
Block a user