From 4da7b28372d1d088407b8ec8f188f3091823baeb Mon Sep 17 00:00:00 2001 From: cgycorey Date: Fri, 23 Oct 2026 20:20:08 +0100 Subject: [PATCH] fix(settings): accept the caller's image fallback flag on the validated client ImageCaptionBatcher already passes allow_image_fallback=False, and the validated client now sets that argument itself, so the batch path raised TypeError: got multiple values and returned no captions for the whole batch. The caller's flag is dropped before forwarding; the validated verdict is the authority either way. Refs #2037 Signed-off-by: cgycorey --- deeptutor/services/llm/image_description.py | 2 ++ .../llm/test_image_description_vision_gate.py | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/deeptutor/services/llm/image_description.py b/deeptutor/services/llm/image_description.py index 299b2d11e..08fa8cb57 100644 --- a/deeptutor/services/llm/image_description.py +++ b/deeptutor/services/llm/image_description.py @@ -54,6 +54,8 @@ class _ImageDescriptionClient(LLMClient): history: list[dict[str, str]] | None = None, **kwargs: Any, ) -> str: + # The caption batcher passes this flag too; the validated verdict wins. + kwargs.pop("allow_image_fallback", None) # Preserve the full resolved profile (including wire API and endpoint) # rather than rebuilding an override from a subset of its fields. return await complete_with_config( diff --git a/tests/services/llm/test_image_description_vision_gate.py b/tests/services/llm/test_image_description_vision_gate.py index ec5831890..3af10b6fa 100644 --- a/tests/services/llm/test_image_description_vision_gate.py +++ b/tests/services/llm/test_image_description_vision_gate.py @@ -124,3 +124,35 @@ async def test_complete_sends_images_for_the_validated_selection( assert await client.complete("Describe", image_data="synthetic-image") == "a labelled diagram" assert calls[0]["allow_image_fallback"] is False + + +@pytest.mark.asyncio +async def test_complete_tolerates_a_caller_supplied_fallback_flag( + tmp_path: Path, monkeypatch +) -> None: + """The caption batcher passes this flag itself; it must not collide.""" + service = _service(tmp_path, [{"id": "m", "model": "llama3.2-vision"}]) + _patch_catalog(monkeypatch, service) + config = resolve_image_description_config(SELECTION) + calls: list[bool | None] = [] + + async def complete( + *, + config: Any, + prompt: str, + system_prompt: str, + messages: Any, + allow_image_fallback: bool | None = None, + **kwargs: Any, + ) -> str: + calls.append(allow_image_fallback) + return "a labelled diagram" + + monkeypatch.setattr(image_description, "complete_with_config", complete) + client = image_description._ImageDescriptionClient(config, configure_env=False) + + caption = await client.complete( + "Describe", image_data="synthetic-image", max_retries=0, allow_image_fallback=False + ) + assert caption == "a labelled diagram" + assert calls == [False]