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()}