You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: force LLM output language from UI locale (#26)
Previously the main chat system prompt was majority-Chinese prose and the
suggestion/title prompts relied on soft "match the anchor's language" rules.
Free-tier summarizer models (llama-3.1-8b etc.) routinely ignored those
directives, so English sessions drifted into Chinese titles/suggestions and
occasionally Chinese assistant replies.
Replace the soft rules with a single shared directive:
- _lang_directive(lang) prepends a one-line demonstration in the target
language (strongest steering signal for small models) plus an English
MUST-directive (strongest signal for larger chat models).
- chat_stream / generate_title_and_suggestions / summarize / merge_summary /
assess_relevance / merge_threads all accept a `lang` param and inject
the directive into their system message.
- Chinese prose removed from the chat_stream system prompt and from
context_builder labels; everything the LLM sees is English except the
single target-language demo line.
The UI locale is the single source of truth. Plumb it through:
ChatRequest.lang → stream.py → stream_manager → chat_stream.
CreateThreadRequest.lang → threads.py → generate_title_and_suggestions.
GET /threads/:id/suggest accepts ?lang=.
Frontend callers pass useLangStore.getState().lang.
Tests:
- New TestLangDirective, TestChatStreamSystemPrompt, TestSummarizerLangDirective
classes assert the directive is injected correctly and guard against
non-Latin prose leaking back into the default prompt.
- Update test_context_builder's _messages_to_text assertions for the new
English "User:/AI:" labels and the English long-text placeholder.
0 commit comments