From e34402f980a2664c910b60d5dfd433b7ac7bed12 Mon Sep 17 00:00:00 2001 From: Benature Date: Sat, 28 Nov 2026 00:00:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=9A=84=E7=BD=91=E5=85=B3=E5=88=AB=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VERSION | 2 +- snooper_summary.py | 21 +++++++++++++++++++-- tests/test_summary.py | 9 +++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index b003284..a45be46 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2.7 +0.2.8 diff --git a/snooper_summary.py b/snooper_summary.py index 47474d8..733477a 100644 --- a/snooper_summary.py +++ b/snooper_summary.py @@ -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 "" in content and "" 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 没有返回总结内容。") diff --git a/tests/test_summary.py b/tests/test_summary.py index b187930..61006f8 100644 --- a/tests/test_summary.py +++ b/tests/test_summary.py @@ -24,6 +24,7 @@ from snooper_summary import ( normalize_self_name, previous_workday, require_efund_model, + require_matching_efund_model, resolve_day, sanitize_wikilink_pipes, shorten_headings, @@ -145,6 +146,14 @@ def test_system_only_private_chat_does_not_require_a_person_name(): assert session.post_calls == [] +def test_model_response_accepts_only_matching_gateway_alias(): + requested = "auto/EFundGPT-dsv4-flash-code" + returned = "group/auto-efundgpt-dsv4-flash-code" + assert require_matching_efund_model(returned, requested) == returned + with pytest.raises(SummaryError, match="响应模型与请求"): + require_matching_efund_model("group/auto-other-model", requested) + + def test_model_policy_checks_actual_model_after_optional_routing_prefix(): assert require_efund_model(DEFAULT_MODEL) == DEFAULT_MODEL assert require_efund_model("EFundGPT-other") == "EFundGPT-other"