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:
@@ -136,6 +136,20 @@ class TestReplyLanguageDirective:
|
||||
directive = reply_language_directive("Korean", "melo")
|
||||
assert directive is not None and "Korean" in directive
|
||||
|
||||
def test_default_language_gives_way_only_to_a_lock(self):
|
||||
from jarvis.system_prompt import default_language_directive
|
||||
directive = reply_language_directive(None, "piper", "Korean")
|
||||
assert directive == default_language_directive("Korean")
|
||||
assert "Korean" in directive and "explicitly asks" in directive
|
||||
assert reply_language_directive("Japanese", "melo", "Korean") == output_language_directive("Japanese")
|
||||
assert default_language_directive(" ") is None
|
||||
assert reply_language_directive(None, "melo", None) is None
|
||||
|
||||
def test_default_language_hands_the_persona_language_clause_to_the_directive(self):
|
||||
prompt = build_system_prompt("Jarvis", None, "Korean")
|
||||
assert "in the user's language" not in prompt
|
||||
assert "in the reply language" in prompt
|
||||
|
||||
def test_edge_is_multilingual(self):
|
||||
# Edge TTS (the default Korean voice) is not English-only: no lock → the
|
||||
# user's own language, and a lock is honoured (not forced to English).
|
||||
|
||||
@@ -311,7 +311,7 @@ def test_the_brain_prints_no_text_from_its_thread(tmp_path, monkeypatch, capfd):
|
||||
cfg.write_text(json.dumps({"db_path": str(tmp_path / "jarvis.db")}))
|
||||
monkeypatch.setenv("JARVIS_CONFIG_PATH", str(cfg))
|
||||
|
||||
def fake_engine(db, cfg, tts, text, mem, language=None, history=None, legacy_memory=True):
|
||||
def fake_engine(db, cfg, tts, text, mem, language=None, history=None, legacy_memory=True, **kw):
|
||||
print(f"answer text {text}")
|
||||
print(f"debug {text}", file=sys.stderr)
|
||||
# Tools print from helper threads too (the web fetch pool).
|
||||
@@ -345,7 +345,7 @@ def test_the_brain_turns_off_the_single_user_memory(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("JARVIS_CONFIG_PATH", str(cfg))
|
||||
seen = {}
|
||||
|
||||
def fake_engine(db, cfg, tts, text, mem, language=None, history=None, legacy_memory=True):
|
||||
def fake_engine(db, cfg, tts, text, mem, language=None, history=None, legacy_memory=True, **kw):
|
||||
seen["legacy_memory"] = legacy_memory
|
||||
return "ok"
|
||||
|
||||
@@ -356,12 +356,13 @@ def test_the_brain_turns_off_the_single_user_memory(tmp_path, monkeypatch):
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_brain_answers_in_the_askers_language_even_with_a_v1_english_voice(tmp_path, monkeypatch):
|
||||
def test_the_brain_answers_in_korean_by_default_even_with_a_v1_english_voice(tmp_path, monkeypatch):
|
||||
"""v1's ``tts_engine`` (an English-only Piper voice by default) must not lock v2 replies to
|
||||
English: v2 speaks through the worker's own TTS, and chat answers are not spoken at all."""
|
||||
English: v2 speaks through the worker's own TTS. Replies come in the default reply language
|
||||
(Korean) unless the asker asks for another, and tools get its ISO code."""
|
||||
pytest.importorskip("mcp") # the real brain needs the jarvis dependencies (--brain)
|
||||
from jarvis.memory.history import HistoryContext
|
||||
from jarvis.system_prompt import reply_language_directive
|
||||
from jarvis.system_prompt import default_language_directive, reply_language_directive
|
||||
from voice_worker import brain as brain_mod
|
||||
|
||||
cfg = tmp_path / "config.json"
|
||||
@@ -370,14 +371,20 @@ def test_the_brain_answers_in_the_askers_language_even_with_a_v1_english_voice(t
|
||||
monkeypatch.delenv("OUTPUT_LANGUAGE", raising=False)
|
||||
seen = {}
|
||||
|
||||
def fake_engine(db, cfg, tts, text, mem, language=None, history=None, legacy_memory=True):
|
||||
seen["directive"] = reply_language_directive(None, cfg.tts_engine)
|
||||
def fake_engine(db, cfg, tts, text, mem, language=None, history=None, legacy_memory=True,
|
||||
default_language=None):
|
||||
seen["directive"] = reply_language_directive(None, cfg.tts_engine, default_language)
|
||||
seen["language"] = language
|
||||
return "ok"
|
||||
|
||||
import jarvis.reply.engine as engine
|
||||
monkeypatch.setattr(engine, "run_reply_engine", fake_engine)
|
||||
brain_mod.JarvisBrain().reply("100", "지금 몇 시야?", HistoryContext())
|
||||
assert seen["directive"] is None
|
||||
brain_mod.JarvisBrain().reply("100", "what time is it?", HistoryContext())
|
||||
assert seen["directive"] == default_language_directive("Korean")
|
||||
assert seen["language"] == "ko"
|
||||
# Without a default the brain answers in the asker's language.
|
||||
brain_mod.JarvisBrain(language=None, reply_language=None).reply("100", "q", HistoryContext())
|
||||
assert seen["directive"] is None and seen["language"] is None
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@@ -392,7 +399,7 @@ def test_the_brain_tells_tools_who_is_asking(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("JARVIS_CONFIG_PATH", str(cfg))
|
||||
seen = []
|
||||
|
||||
def fake_engine(db, cfg, tts, text, mem, language=None, history=None, legacy_memory=True):
|
||||
def fake_engine(db, cfg, tts, text, mem, language=None, history=None, legacy_memory=True, **kw):
|
||||
seen.append(turn_state.get_user())
|
||||
return "ok"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user