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:
javis-bot
2026-11-12 10:34:12 +09:00
parent cefe9b9253
commit 7623d6d002
9 changed files with 170 additions and 25 deletions

View File

@@ -24,6 +24,9 @@ def main() -> int:
ap.add_argument("--history", default=None, help="conversation history SQLite file; no history without it")
ap.add_argument("--brain", action="store_true",
help="answer reply requests with the jarvis reply engine (needs --history)")
ap.add_argument("--reply-language", default="Korean",
help="answers come in this language unless the asker asks for another; '' for the asker's")
ap.add_argument("--tool-language", default="ko", help="ISO code tools get (e.g. the Wikipedia host)")
args = ap.parse_args()
if args.brain and not args.history:
print("--brain needs --history", file=sys.stderr)
@@ -56,7 +59,7 @@ def main() -> int:
history = HistoryStore(args.history)
if args.brain:
from .brain import JarvisBrain
brain = JarvisBrain()
brain = JarvisBrain(language=args.tool_language or None, reply_language=args.reply_language or None)
async def run() -> None:
worker = VoiceWorker(token, transcriber, vad.stream, tts, history=history, brain=brain)

View File

@@ -118,16 +118,19 @@ class JarvisBrain:
tool carry-over follows the person who asked.
"""
def __init__(self, language: Optional[str] = None):
def __init__(self, language: Optional[str] = "ko", reply_language: Optional[str] = "Korean"):
from jarvis.config import load_settings
from jarvis.memory.db import Database
# v1's tts_engine names the v1 desktop voice (English-only Piper by default), which makes the
# engine lock replies to English. v2 speaks through the worker's TTS and chat answers are
# not spoken, so the brain answers in the asker's language (an OUTPUT_LANGUAGE lock still wins).
# not spoken; the brain answers in ``reply_language`` (an OUTPUT_LANGUAGE lock still wins).
self.cfg = dataclasses.replace(load_settings(), tts_engine="melo")
self.db = Database(self.cfg.db_path, self.cfg.sqlite_vss_path)
# ``language``: the ISO code tools get (e.g. the Wikipedia host); ``reply_language``: replies
# come in it unless the asker explicitly asks for another language (None: the asker's).
self.language = language
self.reply_language = reply_language
self._memories: dict = {}
self._lock = threading.Lock()
debug_log(f"brain ready: llm={self.cfg.ollama_base_url} model={self.cfg.ollama_chat_model}", "voice_worker")
@@ -156,7 +159,8 @@ class JarvisBrain:
turn_state.set_chat(chat)
try:
return run_reply_engine(self.db, self.cfg, None, text, self._memory(user),
language=self.language, history=history, legacy_memory=False)
language=self.language, history=history, legacy_memory=False,
default_language=self.reply_language)
finally:
turn_state.reset()

View File

@@ -233,10 +233,14 @@ which carry Discord's own time.
`cancelled: true` and no audio. Each user keeps their own short-term dialogue
memory (tool carry-over) across replies. The brain runs the reply engine with v1's single-user
memory off (`legacy_memory=False`: no warm profile, diary or graph), because several people share
this assistant and only the asker's scoped history may reach the prompt. It answers in the
asker's language: v1's `tts_engine` setting (an English-only Piper voice by default) does not
lock replies to English, because v2 speaks through the worker's TTS and chat answers are not
spoken. An `output_language` lock in the jarvis settings still wins.
this assistant and only the asker's scoped history may reach the prompt. It answers in Korean
by default (`--reply-language`, default `Korean`; `''` answers in the asker's language), whatever
language the question was heard or written in, and in another language only when the asker
explicitly asks for it (just that answer, or from then on, as they said). Tools get the ISO code
`--tool-language` (default `ko`). v1's `tts_engine` setting (an English-only Piper voice by
default) does not lock replies to English, because v2 speaks through the worker's TTS. An
`output_language` lock in the jarvis settings still wins. Eval: `evals/test_reply_language_default.py`.
STT (`language` `"ko"`) and TTS (`--melo-language KR`) are Korean by default too.
The asker is set in `jarvis.reply.turn_state` for the turn, so tools that keep personal data
(meals) store and read it under that person only.
- `addressed` and `rank` are the conversation's questions (`app/src/conversation.spec.md`), answered