QuerryRaspBerry commited on
Commit
113d2e6
·
verified ·
1 Parent(s): 3c17d5f
Files changed (1) hide show
  1. brain/orchestrator.py +13 -11
brain/orchestrator.py CHANGED
@@ -57,26 +57,25 @@ def _signoff_bubbles(ctx: dict):
57
  ]
58
 
59
 
60
- # 🔴 FIX: speaker tagging added here
61
  def _history_to_messages(ctx: dict):
62
- msgs = [{"role": "system", "content": SYSTEM_PROMPT}]
 
 
 
 
 
63
 
 
64
  media = ctx.get("media", {})
65
 
66
  for h in ctx.get("history", []):
67
  role = h.get("role", "user")
68
  text = h.get("text", "")
69
 
70
- # 🔴 IMPORTANT: explicit identity separation
71
- if role == "assistant":
72
- content = f"[ARIA]: {text}"
73
- else:
74
- content = f"[USER]: {text}"
75
 
76
- # multimodal handling
77
- parts = [{"type": "text", "text": content}]
78
  m = media.get(h.get("id"))
79
-
80
  if m and m.get("kind") == "image" and m.get("url"):
81
  parts.append({"type": "image_url", "image_url": {"url": m["url"]}})
82
 
@@ -86,6 +85,8 @@ def _history_to_messages(ctx: dict):
86
 
87
 
88
  def respond(context_json: str) -> str:
 
 
89
  try:
90
  ctx = json.loads(context_json) if isinstance(context_json, str) else (context_json or {})
91
  except Exception:
@@ -96,9 +97,10 @@ def respond(context_json: str) -> str:
96
 
97
  messages = _history_to_messages(ctx)
98
 
99
- # keep your existing framing
100
  messages.append({"role": "user", "content": build_user_frame(ctx)})
101
 
 
102
  lang = _lang(ctx)
103
  messages.append({
104
  "role": "user",
 
57
  ]
58
 
59
 
 
60
  def _history_to_messages(ctx: dict):
61
+ """
62
+ IMPORTANT FIX:
63
+ - NO speaker tagging in text
64
+ - role metadata is the ONLY source of truth
65
+ - prevents HF chat template corruption + response dropout
66
+ """
67
 
68
+ msgs = [{"role": "system", "content": SYSTEM_PROMPT}]
69
  media = ctx.get("media", {})
70
 
71
  for h in ctx.get("history", []):
72
  role = h.get("role", "user")
73
  text = h.get("text", "")
74
 
75
+ # keep raw text ONLY
76
+ parts = [{"type": "text", "text": text}]
 
 
 
77
 
 
 
78
  m = media.get(h.get("id"))
 
79
  if m and m.get("kind") == "image" and m.get("url"):
80
  parts.append({"type": "image_url", "image_url": {"url": m["url"]}})
81
 
 
85
 
86
 
87
  def respond(context_json: str) -> str:
88
+ """Entry called by the Gradio API (api_name='respond')."""
89
+
90
  try:
91
  ctx = json.loads(context_json) if isinstance(context_json, str) else (context_json or {})
92
  except Exception:
 
97
 
98
  messages = _history_to_messages(ctx)
99
 
100
+ # frame that tells model what to do this turn
101
  messages.append({"role": "user", "content": build_user_frame(ctx)})
102
 
103
+ # language steering (kept minimal, avoids confusion)
104
  lang = _lang(ctx)
105
  messages.append({
106
  "role": "user",