fix(llm): 协议匹配端点存在时只选匹配项(排除未标注)——防同账号多端点按序选到compatible-mode再404(自查发现)

This commit is contained in:
yumoqing 2026-09-05 23:11:56 +08:00
parent 51d1e4ccdd
commit 9f0691f0b7

View File

@ -295,8 +295,14 @@ async def _pick_candidate(sor, model: dict, pref: str):
matched = {i for i, e in tagged if (e.get('protocol') or '').strip() == mproto}
untagged = {i for i, e in enumerate(endpoints)
if not (e.get('protocol') or '').strip()}
usable = matched | untagged
if not matched:
# 有协议匹配端点 → 只选匹配的(同账号多端点余额同分,按序会选到
# 第一个即 compatible-mode → 404必须排除不匹配项而非并集
# 无匹配但有未标注(历史)端点 → 兜底用未标注;全无 → 报错
if matched:
usable = matched
elif untagged:
usable = untagged
else:
return False, ('供应商端点均为其他协议(模型模板协议 %s,端点协议 %s)——'
'原生异步(openai_compat 之外)与兼容模式端点 base_url 不同,'
'混用必 404。请在供应商端点目录添加协议 %s 的端点'