feat(voice_worker): the v2 brain answers in Korean unless asked for another language
The brain passes default_language (worker --reply-language, default Korean) to the reply engine; unlike the output_language lock it gives way when the user explicitly asks for a language. Tools get the ko code (--tool-language). Eval evals/test_reply_language_default.py (Qwen3.6 on Strata): 6/6, English questions answered in Korean, an explicit English request in English, and the control without the default answers English in English. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -180,7 +180,8 @@ def tool_honesty_reminder(tool_names) -> str:
|
||||
|
||||
|
||||
def build_system_prompt(
|
||||
assistant_name: str = "Jarvis", output_language: Optional[str] = None
|
||||
assistant_name: str = "Jarvis", output_language: Optional[str] = None,
|
||||
default_language: Optional[str] = None,
|
||||
) -> str:
|
||||
"""Render the persona prompt with the configured assistant name.
|
||||
|
||||
@@ -198,6 +199,9 @@ def build_system_prompt(
|
||||
lang = (output_language or "").strip()
|
||||
if lang:
|
||||
prompt = prompt.replace("in the user's language", f"in {lang}")
|
||||
elif (default_language or "").strip():
|
||||
# The reply-language directive decides (default, or what the user asked for).
|
||||
prompt = prompt.replace("in the user's language", "in the reply language")
|
||||
return prompt
|
||||
|
||||
|
||||
@@ -240,8 +244,30 @@ ENGLISH_ONLY_DIRECTIVE = (
|
||||
)
|
||||
|
||||
|
||||
def default_language_directive(language: Optional[str]) -> Optional[str]:
|
||||
"""Return a 'reply in <language> unless asked otherwise' instruction, or None when unset.
|
||||
|
||||
Unlike the ``output_language`` lock, a default gives way when the user explicitly asks for
|
||||
another language ("answer in English"). The v2 brain uses it so replies come in the
|
||||
deployment's language (Korean) whatever language the question was heard or written in.
|
||||
Names whatever language it is given, so it works for any default.
|
||||
"""
|
||||
lang = (language or "").strip()
|
||||
if not lang:
|
||||
return None
|
||||
return (
|
||||
f"REPLY LANGUAGE: write your reply in {lang}, whatever language the user's message or "
|
||||
f"any reference text is in. Use another language only when the user explicitly asks you "
|
||||
f"to answer or speak in it; then follow what they asked (just this reply, or from now "
|
||||
f"on in this conversation). Do not mix in other scripts: no Chinese/Hanja characters, "
|
||||
f"Japanese kana or Cyrillic letters inside a {lang} reply. (Numerals and unavoidable "
|
||||
f"proper-noun brand names are fine.)"
|
||||
)
|
||||
|
||||
|
||||
def reply_language_directive(
|
||||
output_language: Optional[str], tts_engine: Optional[str]
|
||||
output_language: Optional[str], tts_engine: Optional[str],
|
||||
default_language: Optional[str] = None,
|
||||
) -> Optional[str]:
|
||||
"""Resolve the reply-language instruction for the chat loop, or None.
|
||||
|
||||
@@ -249,14 +275,19 @@ def reply_language_directive(
|
||||
1. An explicit ``output_language`` lock wins — the deployment serves a
|
||||
single language and owns a TTS voice that can speak it (e.g. Korean
|
||||
MeloTTS). This intentionally overrides the English-only fallback.
|
||||
2. Otherwise, a Piper/Chatterbox TTS engine can only synthesise English,
|
||||
2. Otherwise, a ``default_language`` (the v2 brain: Korean) is used unless
|
||||
the user explicitly asks for another language.
|
||||
3. Otherwise, a Piper/Chatterbox TTS engine can only synthesise English,
|
||||
so force English to avoid garbled audio.
|
||||
3. Otherwise (multilingual TTS, no lock) → None: the assistant replies in
|
||||
4. Otherwise (multilingual TTS, no lock) → None: the assistant replies in
|
||||
the user's own language.
|
||||
"""
|
||||
forced = output_language_directive(output_language)
|
||||
if forced:
|
||||
return forced
|
||||
default = default_language_directive(default_language)
|
||||
if default:
|
||||
return default
|
||||
if (tts_engine or "piper").strip().lower() in _TTS_ENGLISH_ONLY:
|
||||
return ENGLISH_ONLY_DIRECTIVE
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user