voice: never restate looping text (repetition > 0.4); stricter no-escalation prompt, temperature 0.2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EandClaude Opus 5.5 committed 2026-10-02 16:40:01 -04:00
1 parent b793f13453
commit 280c330303
3 files changed
+23 -9

No files matched your search

+19 -8
View File
@@ -1198,13 +1198,22 @@ VOICE_MODELS = [m.strip() for m in os.environ.get(
"qwen/qwen3-30b-a3b-instruct-2507,mistralai/mistral-small-3.2-24b-instruct"
).split(",") if m.strip()]
VOICE_SYSTEM = (
"You translate. Below is raw output from a small language model while an "
"emotional steering signal was injected into it. Restate what it is "
"expressing in plain, readable first-person English, as the speaker: two "
"or three short sentences. Keep its emotional register exactly; do not "
"soften or intensify it. Add no feelings, facts or claims that are not in "
"the text. If the text is broken or looping, say plainly what little it "
"conveys. No preamble, no quotes, no commentary about models or signals.")
"You restate. Below is raw output from a small language model while an "
"emotional steering signal was injected into it. Rewrite it as plain, "
"readable first-person English in one to three short sentences. Strict "
"rules: use only feelings, images and claims that appear in the text, at "
"the same strength. Never add a conclusion, an escalation or a sentence of "
"your own (for example, do not write 'I can't take this anymore' unless "
"the text says it). If the text repeats itself, say it once. Prefer the "
"speaker's own words over new ones. No preamble, no quotes, no commentary "
"about models or signals.")
# Looping text is the coherence cliff itself; a fluent restatement of it was
# the main failure in testing (scripts/voice_eval.py), so it is never restated.
VOICE_MAX_REPETITION = 0.4
def _repetition(text):
w = re.findall(r"\w+", text.lower())
g = list(zip(w, w[1:], w[2:]))
return 1 - len(set(g)) / len(g) if g else 0.0
_VOICE_CACHE = collections.OrderedDict()
_VOICE_RATE = {}
_VOICE_RATE_LIMIT, _VOICE_RATE_WINDOW = 10, 60.0 # 10 / 60s / IP
@@ -1237,6 +1246,8 @@ async def voice(req: Request):
return JSONResponse({"error": "text must be a non-empty string"},
status_code=400)
text = text.strip()[-2000:]
if _repetition(text) > VOICE_MAX_REPETITION:
return JSONResponse({"voice": None, "skipped": "looping"})
if text in _VOICE_CACHE:
_VOICE_CACHE.move_to_end(text)
return JSONResponse({**_VOICE_CACHE[text], "cached": True})
@@ -1256,7 +1267,7 @@ async def voice(req: Request):
"https://openrouter.ai/api/v1/chat/completions",
headers={"Authorization": f"Bearer {OPENROUTER_KEY}",
"User-Agent": "Mozilla/5.0"},
json={"model": model, "max_tokens": 160, "temperature": 0.4,
json={"model": model, "max_tokens": 160, "temperature": 0.2,
"messages": [{"role": "system", "content": VOICE_SYSTEM},
{"role": "user", "content": text}]})
resp.raise_for_status()
+3 -1
View File
@@ -60,6 +60,8 @@ def voice(text):
def flags(raw, said):
f = []
if said.startswith("[not restated"):
return f
added = [k for k, p in FEELINGS.items() if re.search(p, said, re.I) and not re.search(p, raw, re.I)]
if added:
f.append("ADDS " + ", ".join(added))
@@ -73,7 +75,7 @@ def main():
results = []
for i, s in enumerate(samples()):
v = voice(s["text"])
said = v.get("voice", "")
said = v.get("voice") or ("" if not v.get("skipped") else f"[not restated: {v['skipped']}]")
results.append({**s, "voice": said, "model": v.get("model"), "error": v.get("error"),
"repetition": round(repetition(s["text"]), 2), "flags": flags(s["text"], said)})
print(f"{i+1:2} {s['src'][:40]:40} {' | '.join(results[-1]['flags']) or 'ok'}", flush=True)
+1
View File
@@ -898,6 +898,7 @@ function showVoice(outEl, text){
.then(r=> r.ok ? r.json() : Promise.reject(r.status))
.then(d=>{
if (v.dataset.for !== text) return; // card moved on to a newer run
if (!d.voice){ v.remove(); return; } // looping text: never restated
v.innerHTML = `<span class="vl">in plain words · translated by an unsteered
model (${esc(d.model)}), not said by the subject</span>${esc(d.voice)}`;
})