Skip to content

feat(chat): generate conversation titles in the user's language - #597

Open
abdulrafey1 wants to merge 2 commits into
refey/feat/lang-08-chat-promptfrom
refey/feat/lang-09-title-language
Open

feat(chat): generate conversation titles in the user's language#597
abdulrafey1 wants to merge 2 commits into
refey/feat/lang-08-chat-promptfrom
refey/feat/lang-09-title-language

Conversation

@abdulrafey1

@abdulrafey1 abdulrafey1 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Part of: Sparkth UI, emails, API errors, and AI-generated content are English-only

Third of the phase-2 generation-language stack. Does not close the issue.

What

Makes generated conversation titles follow the user's preferred language, so the sidebar does not
show an English title on a Spanish conversation.

Changes

  • feat(plugins): generate_conversation_title takes a resolved BCP 47 tag and names the language
    in the title prompt, instructing the model to use it even when the first message is in another
  • feat(plugins): thread the tag from the completion handler through get_or_create_conversation
    into the background task
  • test(plugins): the title prompt carries the language, and the tag actually arrives at the
    scheduled task

How to Test

  1. uv run pytest sparkth/plugins/chat/tests/test_conversation_title.py sparkth/plugins/chat/tests/test_completion_language.py -v
  2. Confirm the forwarding is load-bearing: delete language=language from the
    background_tasks.add_task(...) call in sparkth/plugins/chat/routes/utils/__init__.py and
    re-run — test_new_conversation_schedules_title_generation_with_resolved_language fails. Revert.
  3. Set the preference to es, start a new conversation with an English first message, and
    confirm the sidebar title is Spanish.

Notes

No migration, no env var, no dependency.

The tag is passed explicitly down the call chain rather than read from request-scoped state,
because title generation runs as a FastAPI background task.

Titles follow the language of the replies rather than the language of the first message, which may
differ — a user with a Spanish preference who opens with an English message gets a Spanish title.

This description was written with the assistance of an LLM (Claude).

abdulrafey1 and others added 2 commits August 14, 2026 02:04
The title prompt now names the resolved language and tells the model to use it even when
the first message is in another, so a sidebar title matches the language of the replies
instead of the language the user happened to type in.

The tag is passed explicitly from the completion handler through
get_or_create_conversation into the background task. Title generation runs as a FastAPI
background task, so it reads no request-scoped state.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
background_tasks.add_task is typed as a bare Callable, so mypy cannot check its kwargs
against generate_conversation_title's signature, and no existing test called it with a
real function reference — test_conversation_uuid.py patches it with a bare MagicMock and
asserts nothing about the call. The forwarding at
routes/utils/__init__.py's add_task(..., language=language, ...) was therefore verified
only by reading.

Add a test that posts a completion request with no conversation_id, so a new
conversation is created and title generation is actually scheduled, then asserts the
scheduled task received the resolved language. Confirmed it discriminates: removing
language=language from the add_task call fails the new test with the exact missing-kwarg
assertion, restoring it passes again.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@abdulrafey1 abdulrafey1 changed the title refey/feat/lang 09 title language feat(chat): generate conversation titles in the user's language Aug 13, 2026
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.

2 participants