From da0abd85bbe1a3668fb0cba513d6d78e0cafc47d Mon Sep 17 00:00:00 2001 From: whxn520 Date: Thu, 5 Nov 2026 20:54:06 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BE=9B=E5=BA=94=E5=95=86=E6=96=B0=E5=A2=9E=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=8E=B7=E5=8F=96anthropic=E6=A8=A1=E5=9E=8B=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=8A=9F=E8=83=BD=E3=80=82=202=E3=80=81=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E4=BD=BF=E7=94=A8claude-opus-5-5=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E6=97=B6=E6=8A=A5"=E6=A8=A1=E5=9E=8B=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=EF=BC=9A'dict'=20object=20has=20no=20attribu?= =?UTF-8?q?te=20'model=5Fdump'"=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/src/locales/en.json | 2 +- dashboard/src/locales/zh.json | 2 +- .../components/modals/CustomProviderModal.tsx | 9 +- .../components/modals/PresetProviderModal.tsx | 6 +- .../components/modals/ProviderConfigModal.tsx | 8 +- src/octop/__init__.py | 12 ++ src/octop/api/routers/providers.py | 13 +- src/octop/infra/agents/providers/__init__.py | 5 + .../agents/providers/anthropic_compat.py | 114 ++++++++++++++++++ src/octop/infra/agents/providers/probe.py | 75 ++++++++++++ .../integration/test_provider_fetch_models.py | 36 +++++- tests/unit/agents/test_anthropic_compat.py | 45 +++++++ tests/unit/test_provider_fetch_models.py | 64 ++++++++++ 13 files changed, 372 insertions(+), 19 deletions(-) create mode 100644 src/octop/infra/agents/providers/anthropic_compat.py create mode 100644 tests/unit/agents/test_anthropic_compat.py diff --git a/dashboard/src/locales/en.json b/dashboard/src/locales/en.json index dd0e77426f..18127b666b 100644 --- a/dashboard/src/locales/en.json +++ b/dashboard/src/locales/en.json @@ -3671,7 +3671,7 @@ "fetchModelsMerged": "Added {{count}} new models to list (existing ones unchanged)", "fetchModelsNoNew": "No new models to add", "fetchModelsFailed": "Failed to fetch models: {{error}}", - "fetchModelsUnsupportedKind": "Auto-fetch is only supported for OpenAI-compatible providers", + "fetchModelsUnsupportedKind": "Auto-fetch is only supported for OpenAI and Anthropic providers", "customModelsLabel": "Models", "customModelsHint": "Fetched models are off by default — enable, test, edit, or remove; or add manually", "onnxLocalService": "Local ONNX embedding", diff --git a/dashboard/src/locales/zh.json b/dashboard/src/locales/zh.json index 10a8ac1fb7..512e1dce8c 100644 --- a/dashboard/src/locales/zh.json +++ b/dashboard/src/locales/zh.json @@ -3670,7 +3670,7 @@ "fetchModelsMerged": "已新增 {{count}} 个模型到列表(已有模型保持不变)", "fetchModelsNoNew": "没有可新增的模型", "fetchModelsFailed": "获取模型失败:{{error}}", - "fetchModelsUnsupportedKind": "仅 OpenAI 兼容供应商支持自动获取模型列表", + "fetchModelsUnsupportedKind": "仅 OpenAI 和 Anthropic 供应商支持自动获取模型列表", "customModelsLabel": "模型", "customModelsHint": "获取后默认未启用,可开启开关、测试、编辑或删除;也可手动添加", "onnxLocalService": "本地 ONNX Embedding", diff --git a/dashboard/src/pages/Settings/Models/components/modals/CustomProviderModal.tsx b/dashboard/src/pages/Settings/Models/components/modals/CustomProviderModal.tsx index a0ffc164cf..ee19104996 100644 --- a/dashboard/src/pages/Settings/Models/components/modals/CustomProviderModal.tsx +++ b/dashboard/src/pages/Settings/Models/components/modals/CustomProviderModal.tsx @@ -124,7 +124,8 @@ export function CustomProviderModal({ const handleFetchModels = async () => { try { const values = await form.validateFields(["kind", "api_key", "base_url"]); - if ((values.kind as string) !== "openai") { + const currentKind = String(values.kind || "").toLowerCase(); + if (currentKind !== "openai" && currentKind !== "anthropic") { message.warning(t("models.fetchModelsUnsupportedKind")); return; } @@ -135,7 +136,7 @@ export function CustomProviderModal({ } setFetchingModels(true); const result = await fetchProviderModels({ - kind: "openai", + kind: currentKind, api_key: apiKey, base_url: (values.base_url as string | undefined)?.trim() || null, }); @@ -333,7 +334,7 @@ export function CustomProviderModal({ - {kind === "openai" && ( + {(kind === "openai" || kind === "anthropic") && ( - {kind === "openai" && ( + {(kind === "openai" || kind === "anthropic") && (