fix(mistral): honor dataset language in figure prompts (#18021)

### Summary

Refs #17885.

Mistral figure enrichment now receives the dataset language through the
production parsing path. `by_mistral_ocr` forwards `lang` to
`MistralParser.parse_pdf`; the parser stores the normalized language and
passes it to the figure-description prompt. Empty or missing values
still fall back to English.
This commit is contained in:
Ziyang Guo
2026-08-11 20:38:24 +08:00
committed by GitHub
parent ad6fdfd7b4
commit 75363af54b
4 changed files with 38 additions and 3 deletions

View File

@@ -539,8 +539,11 @@ def test_parse_pdf_consumes_vision_model_kwarg(monkeypatch, tmp_path):
_patch_render(m, p, 2)
pdf = tmp_path / "x.pdf"
pdf.write_bytes(b"%PDF-1.4 minimal")
p.parse_pdf(str(pdf), vision_model="VM")
p.parse_pdf(str(pdf), vision_model="VM", lang="Japanese")
assert p.vision_model == "VM" # popped from kwargs into self, not forwarded to _call_ocr
assert p.language == "Japanese"
p.parse_pdf(str(pdf), vision_model="VM", lang="")
assert p.language == "English"
def test_describe_image_passes_pil_image_not_bytes(monkeypatch):
@@ -562,10 +565,11 @@ def test_describe_image_passes_pil_image_not_bytes(monkeypatch):
pic = ModuleType("rag.app.picture")
pic.vision_llm_chunk = lambda binary, vision_model, prompt=None, callback=None: (captured.update(kind=type(binary).__name__), "a white square")[1]
gen = ModuleType("rag.prompts.generator")
gen.vision_llm_figure_describe_prompt = lambda: "describe"
gen.vision_llm_figure_describe_prompt = lambda language: (captured.update(language=language), "describe")[1]
monkeypatch.setitem(_sys.modules, "rag.app.picture", pic)
monkeypatch.setitem(_sys.modules, "rag.prompts.generator", gen)
out = p._describe_image("@@1\t0\t0\t40\t40##")
assert out == "a white square"
assert captured["kind"] == "Image" # PIL Image, not 'bytes'
assert captured["language"] == "English"