From 7576ffd6f8838991c2e50ccbff9da95c83efd1aa Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 5 Sep 2026 13:11:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(gateway):=20=E6=A8=A1=E5=9E=8Baccount=5Fid?= =?UTF-8?q?=E7=94=9F=E6=95=88=E2=80=94=E2=80=94=E5=80=99=E9=80=89=E8=B4=A6?= =?UTF-8?q?=E5=8F=B7=E6=B1=A0=E6=94=B6=E7=AA=84=E4=B8=BA=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E8=B4=A6=E5=8F=B7(=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=94=A8=E7=99=BE=E7=82=BC=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?,=E9=98=B2=E4=BE=9B=E5=BA=94=E5=95=86=E7=BA=A7=E8=BD=AE?= =?UTF-8?q?=E8=BD=AC=E4=B8=B2=E5=8F=B7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pipeline_llm/gateway.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pipeline_llm/gateway.py b/pipeline_llm/gateway.py index f55e9a7..7d2ad33 100644 --- a/pipeline_llm/gateway.py +++ b/pipeline_llm/gateway.py @@ -199,7 +199,7 @@ async def _model_chain(sor, org_id: str, model_name: str, purpose: str = ''): for mid in chain_ids: recs = await sor.sqlExe( "SELECT id, name, vendor_id, vendor_model_id, capability, default_params, " - "ppid, org_id, profile_id, sync_mode, query_profile_ids " + "ppid, org_id, profile_id, sync_mode, query_profile_ids, account_id " "FROM llm_model WHERE id=${i}$ AND status='active' LIMIT 1", {"i": mid}) await sor.sqlExe("COMMIT", {}) if recs: @@ -223,10 +223,20 @@ async def _vendor_endpoints(sor, vendor_id: str): async def _account_candidates(sor, model: dict): - """模型的候选账号池:同供应商、启用中。""" + """模型的候选账号池:同供应商、启用中。 + + 模型配置了 account_id 时(如某模型只允许用某个账号充值/密钥), + 候选池收窄为该账号——模型级账号绑定优先于供应商级轮转。 + """ + where = "vendor_id=${v}$ AND status='active'" + params = {"v": model.get('vendor_id', '')} + bound = (model.get('account_id') or '').strip() + if bound: + where += " AND id=${a}$" + params['a'] = bound recs = await sor.sqlExe( "SELECT id, name, api_key, endpoint_ids, balance, status FROM llm_account " - "WHERE vendor_id=${v}$ AND status='active'", {"v": model.get('vendor_id', '')}) + "WHERE " + where, params) await sor.sqlExe("COMMIT", {}) return [_row_to_dict(r) for r in (recs or [])]