From 5d7d00ae5aa89d4509cce901b4adf3105f1ce4e0 Mon Sep 17 00:00:00 2001 From: Pine Date: Sun, 13 Sep 2026 11:14:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(compute):=20/api/opc/compute/base=20?= =?UTF-8?q?=E5=85=AC=E5=BC=80=E8=BF=94=E5=9B=9E=E4=B8=AD=E7=BB=A7=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 鉴权放开为 optional_current_user,未登录也返回 base_url/relay_path/messages_path/models_path - 仅登录附 username --- app/api/routers/rbac_opc.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/api/routers/rbac_opc.py b/app/api/routers/rbac_opc.py index 87cefc1..b2342cd 100644 --- a/app/api/routers/rbac_opc.py +++ b/app/api/routers/rbac_opc.py @@ -354,9 +354,13 @@ async def opc_affairs( @router.get("/compute/base", summary="算力基础 API 地址") async def opc_compute_base( request: Request, - user: dict = Depends(require_roles("opc_member", "operator")), + _u: dict | None = Depends(optional_current_user), ): - """用户接入地址:经 server-core /v1 中继(OpenAI 兼容)。优先用公网配置,回落请求 host。""" + """用户接入地址:经 server-core /v1 中继(OpenAI 兼容 + Anthropic 兼容)。 + + Base URL 与中继路径为公开信息(未登录可见,便于第三方客户端配置); + 仅登录用户返回 username。优先用公网配置,回落请求 host。 + """ base = (config.COMPUTE_PUBLIC_BASE or str(request.base_url)).rstrip("/") # 反代/配置落成 http 时对外一律升级 https(本地回环除外),否则客户端 https 页面/证书校验不可用 if "://" in base: @@ -364,17 +368,21 @@ async def opc_compute_base( host = rest.split("/", 1)[0] if scheme == "http" and not (host.startswith(("localhost", "127.0.0.1", "192.168.", "10.", "172."))): base = f"https://{rest}" - return { + data = { "base_url": f"{base}/v1", "relay_path": "/v1/chat/completions", + "messages_path": "/v1/messages", "models_path": "/v1/models", - "username": user.get("username"), - "hint": "将 base_url 与下方令牌填入 OpenAI 兼容客户端(如 base_url/api_key)即可调用本平台模型", + "hint": "OpenAI 兼容:Authorization: Bearer <令牌>,POST /v1/chat/completions;Anthropic 兼容:x-api-key: <令牌>,POST /v1/messages;均经平台中继计量扣费", } + if _u: + data["username"] = _u.get("username") + return data -@router.get("/compute/models", summary="可用模型(算力中心,admin 新增)") -async def opc_compute_models(_u: dict = Depends(require_roles("opc_member", "operator"))): +@router.get("/compute/models", summary="可用模型(算力中心,无需登录可查看)") +async def opc_compute_models(_u: dict | None = Depends(optional_current_user)): + """可用模型列表:无需登录即可查看(模型目录公开);登录后同样可用。""" return {"items": await compute_catalog.models()}