feat(chat): generate conversation titles in the user's language - #597
Open
abdulrafey1 wants to merge 2 commits into
Open
feat(chat): generate conversation titles in the user's language#597abdulrafey1 wants to merge 2 commits into
abdulrafey1 wants to merge 2 commits into
Conversation
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>
hamza-56
approved these changes
Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
generate_conversation_titletakes a resolved BCP 47 tag and names the languagein the title prompt, instructing the model to use it even when the first message is in another
get_or_create_conversationinto the background task
scheduled task
How to Test
uv run pytest sparkth/plugins/chat/tests/test_conversation_title.py sparkth/plugins/chat/tests/test_completion_language.py -vlanguage=languagefrom thebackground_tasks.add_task(...)call insparkth/plugins/chat/routes/utils/__init__.pyandre-run —
test_new_conversation_schedules_title_generation_with_resolved_languagefails. Revert.es, start a new conversation with an English first message, andconfirm 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).