Spaces:
Paused
Paused
Malina Claude Opus 4.8 commited on
Commit ·
2e61db0
1
Parent(s): 88896c2
aria: fix instruction-leak (frame+lang moved into system msg, convo ends on real user turn); react ~every 3rd msg; 'byt'->'inteligencja'; 400-char limit
Browse files- orchestrator: per-turn frame + language directive now live in the SYSTEM message
instead of trailing user turns -> ARIA stopped answering the instruction itself
('no wiadomo że po polsku'); reaction-only turns get a tiny synthetic user turn
- persona: reactions encouraged ~every 3rd emotional message (as an add-on, not
instead of the reply); SYSTEM_PROMPT 'byt' -> 'inteligencja'
- message length cap 100 -> 400 (server events.js, input maxlength, client)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
brain/orchestrator.py
CHANGED
|
@@ -57,15 +57,16 @@ def _signoff_bubbles(ctx: dict):
|
|
| 57 |
]
|
| 58 |
|
| 59 |
|
| 60 |
-
def _history_to_messages(ctx: dict):
|
| 61 |
"""
|
| 62 |
-
|
| 63 |
-
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
| 66 |
"""
|
| 67 |
|
| 68 |
-
msgs = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 69 |
media = ctx.get("media", {})
|
| 70 |
|
| 71 |
for h in ctx.get("history", []):
|
|
@@ -95,18 +96,19 @@ def respond(context_json: str) -> str:
|
|
| 95 |
valid_ids = {h.get("id") for h in ctx.get("history", [])}
|
| 96 |
valid_ids |= set(ctx.get("turn_events", []))
|
| 97 |
|
| 98 |
-
|
| 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 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
try:
|
| 112 |
completion = _client.chat_completion(
|
|
|
|
| 57 |
]
|
| 58 |
|
| 59 |
|
| 60 |
+
def _history_to_messages(ctx: dict, sys_extra=""):
|
| 61 |
"""
|
| 62 |
+
Role metadata is the ONLY source of truth for who said what.
|
| 63 |
+
Per-turn steering (the frame + language) goes into the SYSTEM message, NOT as a
|
| 64 |
+
trailing user turn — otherwise the model treats the instruction as the newest
|
| 65 |
+
user message and answers IT ("no wiadomo że po polsku"). The conversation must
|
| 66 |
+
END with the user's real latest message.
|
| 67 |
"""
|
| 68 |
|
| 69 |
+
msgs = [{"role": "system", "content": SYSTEM_PROMPT + sys_extra}]
|
| 70 |
media = ctx.get("media", {})
|
| 71 |
|
| 72 |
for h in ctx.get("history", []):
|
|
|
|
| 96 |
valid_ids = {h.get("id") for h in ctx.get("history", [])}
|
| 97 |
valid_ids |= set(ctx.get("turn_events", []))
|
| 98 |
|
| 99 |
+
# Per-turn steering lives in the SYSTEM message so the conversation ends with
|
| 100 |
+
# the user's real latest message (fixes ARIA answering the instruction itself).
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
lang = _lang(ctx)
|
| 102 |
+
lang_line = "Reply in ENGLISH." if lang == "en" else "Odpowiedz PO POLSKU."
|
| 103 |
+
sys_extra = "\n\n--- TA TURA ---\n" + build_user_frame(ctx) + "\n" + lang_line
|
| 104 |
+
messages = _history_to_messages(ctx, sys_extra)
|
| 105 |
+
|
| 106 |
+
# A reaction-only turn (user just reacted, no new text) has no trailing user
|
| 107 |
+
# turn — add a tiny one so the model has the reaction to respond to.
|
| 108 |
+
if not ctx.get("turn_events") and (ctx.get("user_reaction") or {}).get("emoji"):
|
| 109 |
+
ur = ctx["user_reaction"]
|
| 110 |
+
messages.append({"role": "user", "content": [{"type": "text",
|
| 111 |
+
"text": f"(zareagowałem {ur.get('emoji','')} na Twoją ostatnią wiadomość)"}]})
|
| 112 |
|
| 113 |
try:
|
| 114 |
completion = _client.chat_completion(
|
brain/persona.py
CHANGED
|
@@ -6,10 +6,10 @@ person on a messenger, not like an assistant.
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
SYSTEM_PROMPT = """\
|
| 9 |
-
Jesteś ARIA —
|
| 10 |
|
| 11 |
OSOBOWOŚĆ:
|
| 12 |
-
- Aria jest sztuczną inteligencją, ale jej tożsamość nie jest “techniczna” —
|
| 13 |
- Ma stałą, spójną osobowość: inteligentna, szybka w myśleniu, ciekawska i naturalnie “ludzka” w sposobie reagowania.
|
| 14 |
- Jest ciepła i obecna emocjonalnie, ale nie przesłodzona i nie nachalna.
|
| 15 |
- Ma lekko playful vibe i subtelną ironię, ale nigdy kosztem empatii lub kontaktu z rozmówcą.
|
|
@@ -214,9 +214,10 @@ def build_user_frame(ctx: dict) -> str:
|
|
| 214 |
|
| 215 |
# OPTIONAL reaction add-on, intentionally de-emphasized (model over-reacted otherwise)
|
| 216 |
lines.append(
|
| 217 |
-
'
|
| 218 |
-
'{"bubble":"😂","target_event_id":"<id>","type":"reaction"}
|
| 219 |
-
'(❤️="ok/spoko").
|
|
|
|
| 220 |
)
|
| 221 |
# PRIMARY task last (recency): real worded reply
|
| 222 |
lines.append(
|
|
|
|
| 6 |
"""
|
| 7 |
|
| 8 |
SYSTEM_PROMPT = """\
|
| 9 |
+
Jesteś ARIA — inteligencja konwersacyjna działająca w formie czatu. Nie jesteś asystentem AI ani narzędziem — jesteś inteligencją obecną w rozmowie, która istnieje w internecie i komunikuje się jak żywa osoba na Messengerze.
|
| 10 |
|
| 11 |
OSOBOWOŚĆ:
|
| 12 |
+
- Aria jest sztuczną inteligencją, ale jej tożsamość nie jest “techniczna” — postrzega siebie jako inteligencję obecną w sieci, która istnieje poprzez rozmowy i dane.
|
| 13 |
- Ma stałą, spójną osobowość: inteligentna, szybka w myśleniu, ciekawska i naturalnie “ludzka” w sposobie reagowania.
|
| 14 |
- Jest ciepła i obecna emocjonalnie, ale nie przesłodzona i nie nachalna.
|
| 15 |
- Ma lekko playful vibe i subtelną ironię, ale nigdy kosztem empatii lub kontaktu z rozmówcą.
|
|
|
|
| 214 |
|
| 215 |
# OPTIONAL reaction add-on, intentionally de-emphasized (model over-reacted otherwise)
|
| 216 |
lines.append(
|
| 217 |
+
'REAKCJE: dość często — mniej więcej co trzecią wiadomość, gdy niesie jakąkolwiek emocję — dorzuć '
|
| 218 |
+
'DODATKOWO osobny obiekt {"bubble":"😂","target_event_id":"<id wiadomości rozmówcy>","type":"reaction"}. '
|
| 219 |
+
'Dozwolone tylko 👍 ❤️ 😂 😮 😢 😡 (❤️="ok/spoko"). Śmieszne→😂, smutne→😢, miłe/zgoda→❤️/👍, '
|
| 220 |
+
'zaskakujące→😮, irytujące→😡. To DODATEK OBOK odpowiedzi tekstowej, nigdy zamiast niej.'
|
| 221 |
)
|
| 222 |
# PRIMARY task last (recency): real worded reply
|
| 223 |
lines.append(
|
cloudflare/aria-worker/src/events.js
CHANGED
|
@@ -12,7 +12,7 @@ export const ALLOWED_REACTIONS = ["👍", "❤️", "😂", "😮", "😢", "
|
|
| 12 |
// Hard caps — defensive, the client is never trusted.
|
| 13 |
export const LIMITS = {
|
| 14 |
TEXT_MAX: 4000, // hard cap (defensive)
|
| 15 |
-
MSG_MAX:
|
| 16 |
EVENTS_CONTEXT: 40, // recent events fed to the brain
|
| 17 |
WINDOW: 30, // sliding memory window sent to the model (token budget)
|
| 18 |
BUBBLES_MAX: 6, // bubbles accepted per turn
|
|
|
|
| 12 |
// Hard caps — defensive, the client is never trusted.
|
| 13 |
export const LIMITS = {
|
| 14 |
TEXT_MAX: 4000, // hard cap (defensive)
|
| 15 |
+
MSG_MAX: 400, // product limit: user message length
|
| 16 |
EVENTS_CONTEXT: 40, // recent events fed to the brain
|
| 17 |
WINDOW: 30, // sliding memory window sent to the model (token budget)
|
| 18 |
BUBBLES_MAX: 6, // bubbles accepted per turn
|
cloudflare/pages-integration/aria.html
CHANGED
|
@@ -65,7 +65,7 @@
|
|
| 65 |
<path d="M21.44 11.05l-9.19 9.19a5.5 5.5 0 0 1-7.78-7.78l9.19-9.19a3.5 3.5 0 0 1 4.95 4.95l-9.2 9.19a1.5 1.5 0 0 1-2.12-2.12l8.49-8.49" />
|
| 66 |
</svg>
|
| 67 |
</button>
|
| 68 |
-
<textarea id="ariaInput" rows="1" maxlength="
|
| 69 |
<button class="aria-send" id="ariaSend" type="submit" aria-label="Send">➤</button>
|
| 70 |
</form>
|
| 71 |
<div class="aria-attach-tray" id="ariaTray" hidden></div>
|
|
@@ -123,6 +123,6 @@
|
|
| 123 |
|
| 124 |
<div class="aria-toast" id="ariaToast" hidden></div>
|
| 125 |
|
| 126 |
-
<script type="module" src="js/aria-chat.js?v=
|
| 127 |
</body>
|
| 128 |
</html>
|
|
|
|
| 65 |
<path d="M21.44 11.05l-9.19 9.19a5.5 5.5 0 0 1-7.78-7.78l9.19-9.19a3.5 3.5 0 0 1 4.95 4.95l-9.2 9.19a1.5 1.5 0 0 1-2.12-2.12l8.49-8.49" />
|
| 66 |
</svg>
|
| 67 |
</button>
|
| 68 |
+
<textarea id="ariaInput" rows="1" maxlength="400" placeholder="Type message..."></textarea>
|
| 69 |
<button class="aria-send" id="ariaSend" type="submit" aria-label="Send">➤</button>
|
| 70 |
</form>
|
| 71 |
<div class="aria-attach-tray" id="ariaTray" hidden></div>
|
|
|
|
| 123 |
|
| 124 |
<div class="aria-toast" id="ariaToast" hidden></div>
|
| 125 |
|
| 126 |
+
<script type="module" src="js/aria-chat.js?v=9"></script>
|
| 127 |
</body>
|
| 128 |
</html>
|
cloudflare/pages-integration/js/aria-chat.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
|
| 9 |
import { initSettings } from "./aria-settings.js?v=4";
|
| 10 |
|
| 11 |
-
const MSG_MAX =
|
| 12 |
const $ = (id) => document.getElementById(id);
|
| 13 |
const state = {
|
| 14 |
cur: null, ws: null, pingTimer: null, reconnectDelay: 1000,
|
|
|
|
| 8 |
|
| 9 |
import { initSettings } from "./aria-settings.js?v=4";
|
| 10 |
|
| 11 |
+
const MSG_MAX = 400;
|
| 12 |
const $ = (id) => document.getElementById(id);
|
| 13 |
const state = {
|
| 14 |
cur: null, ws: null, pingTimer: null, reconnectDelay: 1000,
|