mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-01 04:02:02 +08:00
fix(model-fetch): support /models for Anthropic-compat subpath providers
Providers like DeepSeek, Kimi, Zhipu GLM and MiniMax expose the Anthropic-compatible API on a subpath (e.g. /anthropic) while the OpenAI-style /models endpoint lives at the API root. The previous heuristic blindly appended /v1/models to the Base URL, so every such provider returned 404 and the UI mislabeled it as "provider does not support fetching models". Backend now generates a candidate list and tries them in order: preset override -> baseURL /v1/models -> stripped-subpath /v1/models -> stripped-subpath /models. Non-404/405 responses (auth, network) stop immediately so we never retry against hostile status codes. Known compat suffixes are kept in a length-descending constant so the longest match wins; response bodies are truncated to 512 chars to avoid HTML 404 pages bloating the error string. Preset type gains an optional modelsUrl (DeepSeek points at https://api.deepseek.com/models). Frontend threads the override through fetchModelsForConfig when the current Base URL still matches the preset default. A new fetchModelsEndpointNotFound i18n key replaces the misleading "not supported" toast for exhausted-candidate and 404/405 cases (zh/en/ja).
This commit is contained in:
@@ -66,6 +66,10 @@ export interface ProviderPreset {
|
||||
|
||||
// 是否在 UI 中隐藏该预设(预设仍存在,仅不在列表中显示)
|
||||
hidden?: boolean;
|
||||
|
||||
// 获取模型列表使用的完整 URL(覆写自动候选逻辑)
|
||||
// 缺省时后端基于 baseURL 自动尝试 /v1/models、/models 以及剥离已知兼容子路径后的变体。
|
||||
modelsUrl?: string;
|
||||
}
|
||||
|
||||
export const providerPresets: ProviderPreset[] = [
|
||||
@@ -136,6 +140,8 @@ export const providerPresets: ProviderPreset[] = [
|
||||
},
|
||||
},
|
||||
category: "cn_official",
|
||||
// Anthropic 兼容层挂在 /anthropic 子路径;/models 是根上独立端点
|
||||
modelsUrl: "https://api.deepseek.com/models",
|
||||
icon: "deepseek",
|
||||
iconColor: "#1E88E5",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user