Malina Claude Opus 4.8 commited on
Commit
961d1cd
·
1 Parent(s): 9cdca50

brain: force reply language to match user's last message (was defaulting to Polish on English)

Browse files

Add _lang(ctx) (last user message) and append an explicit per-turn directive
('Reply in ENGLISH' / 'Odpowiedz po polsku'); reuse it for signoffs. Verified:
EN in -> EN reply, PL in -> PL reply.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Files changed (1) hide show
  1. brain/orchestrator.py +22 -8
brain/orchestrator.py CHANGED
@@ -46,17 +46,25 @@ _BYE_EN = ["catch you later", "see you", "talk soon", "take care", "bye for now"
46
  "later", "cya", "see ya", "peace", "ttyl", "see you around"]
47
 
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  def _signoff_bubbles(ctx: dict):
50
  """When inference fails, ARIA bails like a person — two casual bubbles, randomized,
51
- language-matched (Polish by default)."""
52
  import random
53
- users = [h.get("text", "") for h in ctx.get("history", []) if h.get("role") == "user"]
54
- txt = (users[-1] if users else "").lower() # language of the LAST user message
55
- has_pl = any(c in txt for c in "ąćęłńóśźż") or any(
56
- w in txt for w in [" nie", "cześć", "jesteś", " co ", " tak", "dzię", " jak"])
57
- has_en = any(w in txt for w in [" the ", " you", " do ", "speak", "what",
58
- "hello", "hi ", " are ", " can "])
59
- leave, bye = (_LEAVE_EN, _BYE_EN) if (has_en and not has_pl) else (_LEAVE_PL, _BYE_PL)
60
  return [
61
  {"bubble": random.choice(leave), "target_event_id": None, "type": "proactive"},
62
  {"bubble": random.choice(bye), "target_event_id": None, "type": "proactive"},
@@ -93,6 +101,12 @@ def respond(context_json: str) -> str:
93
  messages = _history_to_messages(ctx)
94
  # Final steering frame: which events to handle + JSON-only reminder.
95
  messages.append({"role": "user", "content": build_user_frame(ctx)})
 
 
 
 
 
 
96
 
97
  try:
98
  completion = _client.chat_completion(
 
46
  "later", "cya", "see ya", "peace", "ttyl", "see you around"]
47
 
48
 
49
+ def _lang(ctx: dict) -> str:
50
+ """'en' or 'pl', based on the user's LAST message. Polish by default."""
51
+ users = [h.get("text", "") for h in ctx.get("history", []) if h.get("role") == "user"]
52
+ t = (users[-1] if users else "").lower()
53
+ if any(c in t for c in "ąćęłńóśźż"):
54
+ return "pl"
55
+ has_pl = any(w in t for w in [" nie", "cześć", "jesteś", " co ", " tak", "dzię",
56
+ " jak", "jestem", "mam", "robisz", "siema", "dobra", "spoko"])
57
+ has_en = any(w in t for w in [" the ", " you", " do ", "speak", "what", "hello",
58
+ "hi ", " are ", " can ", "yeah", "how", "hey", "your",
59
+ "with", " me ", "good", "thanks", "help"])
60
+ return "en" if (has_en and not has_pl) else "pl"
61
+
62
+
63
  def _signoff_bubbles(ctx: dict):
64
  """When inference fails, ARIA bails like a person — two casual bubbles, randomized,
65
+ language-matched to the user's last message (Polish by default)."""
66
  import random
67
+ leave, bye = (_LEAVE_EN, _BYE_EN) if _lang(ctx) == "en" else (_LEAVE_PL, _BYE_PL)
 
 
 
 
 
 
68
  return [
69
  {"bubble": random.choice(leave), "target_event_id": None, "type": "proactive"},
70
  {"bubble": random.choice(bye), "target_event_id": None, "type": "proactive"},
 
101
  messages = _history_to_messages(ctx)
102
  # Final steering frame: which events to handle + JSON-only reminder.
103
  messages.append({"role": "user", "content": build_user_frame(ctx)})
104
+ # Force the reply language to match the user's LAST message (the model otherwise
105
+ # tends to default to Polish even on English input).
106
+ lang = _lang(ctx)
107
+ messages.append({"role": "user", "content":
108
+ "Reply in ENGLISH (the user just wrote in English)." if lang == "en"
109
+ else "Odpowiedz PO POLSKU (user napisał po polsku)."})
110
 
111
  try:
112
  completion = _client.chat_completion(