Skip to content

fix: caption images in the configured output language - #667

Open
b9bt5dp9hg-ship-it wants to merge 1 commit into
nashsu:mainfrom
b9bt5dp9hg-ship-it:fix/caption-output-language
Open

fix: caption images in the configured output language#667
b9bt5dp9hg-ship-it wants to merge 1 commit into
nashsu:mainfrom
b9bt5dp9hg-ship-it:fix/caption-output-language

Conversation

@b9bt5dp9hg-ship-it

Copy link
Copy Markdown

Problem

Image captions are always generated in English, regardless of the wiki's configured output language. The caption prompt (CAPTION_PROMPT / buildCaptionPromptWithContext) never mentions a target language, so on non-English wikis the ingest pipeline produces English alt text inside otherwise localized source summaries. Beyond the visual inconsistency, this hurts retrieval: caption embeddings end up in a different language than the user's queries.

Fix

Thread an optional outputLanguage through the caption pipeline:

  • vision-caption.ts — new captionLanguageInstruction() appends a language line ("Write the description in X. Preserve visible text verbatim in its original language.") to both the no-context and the context-aware prompt. Absent or "auto" values leave the prompts byte-identical to before, so existing caption caches and prompt regression tests are unaffected.
  • image-caption-pipeline.tsCaptionPipelineOptions.outputLanguage is passed through to captionImage.
  • ingest.ts — both caption call sites resolve the configured language with getOutputLanguage() + getLanguagePromptName(), the same resolution buildLanguageDirective already uses for page generation. This means "auto" resolves from the source content (instead of leaking the literal string auto into the prompt), and captions follow the same language rules as the rest of the generated wiki.

Visible text in images (labels, chart axes, OCR content) is still captured verbatim in its original language — only the descriptive prose follows the output language setting.

Tests

  • Language instruction present for both prompt variants (no-context and context-aware)
  • "auto" / absent outputLanguage fall back to the unmodified CAPTION_PROMPT
  • Pipeline forwards outputLanguage to captionImage

npx tsc --noEmit clean, full mock suite green (1808 tests).

🤖 Generated with Claude Code

Image captions were always generated in English, even when the wiki's
output language was set to something else — the caption prompt never
mentioned a target language. On non-English wikis this produced
English alt text inside otherwise localized source summaries, and the
mismatch hurts retrieval (caption embeddings live in a different
language than the queries).

Fix: thread an optional outputLanguage through the caption pipeline.

- vision-caption.ts: append a language instruction to both the
  no-context and context-aware prompts. Visible text in the image is
  still preserved verbatim in its original language. Absent or "auto"
  values leave the prompt untouched.
- image-caption-pipeline.ts: pass options.outputLanguage through to
  captionImage.
- ingest.ts: resolve the configured language at both caption call
  sites via getOutputLanguage() + getLanguagePromptName() — the same
  resolution buildLanguageDirective uses — so "auto" resolves from
  the source content instead of leaking the literal string "auto"
  into the prompt.

Tests: language line present for both prompt variants, "auto"/absent
fall back to the unmodified prompt, and the pipeline forwards the
option.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant