fix: 兼容图片模型的网关别名

This commit is contained in:
Benature
2026-11-28 00:00:19 +08:00
parent adb5c67345
commit e34402f980
3 changed files with 29 additions and 3 deletions

View File

@ -181,6 +181,23 @@ def require_efund_model(model: str) -> str:
return model
def require_matching_efund_model(returned_model: str, requested_model: str) -> str:
"""Accept only the gateway's case/auto- alias of the requested EFundGPT model."""
require_efund_model(requested_model)
if not isinstance(returned_model, str):
raise SummaryError("模型名必须是字符串。")
returned = returned_model.rsplit("/", 1)[-1].lower()
requested = requested_model.rsplit("/", 1)[-1].lower()
if returned.startswith("auto-"):
returned = returned[5:]
if returned != requested:
raise SummaryError(
"隐私保护已阻止请求:响应模型与请求的 EFundGPT 模型不一致;"
"不会回退到其他模型。"
)
return returned_model
def clean_model_output(content: str) -> str:
"""Keep only the final answer after a model reasoning block."""
if "<think>" in content and "</think>" not in content:
@ -583,7 +600,7 @@ class MagpieClient:
)
returned_model = data.get("model")
if returned_model is not None:
require_efund_model(returned_model)
require_matching_efund_model(returned_model, self.model)
choices = data.get("choices")
if not isinstance(choices, list) or not choices:
raise SummaryError("Magpie 没有返回图片读取结果。")
@ -616,7 +633,7 @@ class MagpieClient:
)
returned_model = data.get("model")
if returned_model is not None:
require_efund_model(returned_model)
require_matching_efund_model(returned_model, self.model)
choices = data.get("choices")
if not isinstance(choices, list) or not choices:
raise SummaryError("Magpie 没有返回总结内容。")