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"