Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/lingua/engine/maas.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import json
import time
import os
import re

import requests

Expand Down Expand Up @@ -121,6 +122,9 @@ def reset_model_health() -> None:
"हिन्दी": "Hindi (हिन्दी)",
}

#: Reasoning blocks a model may put before its answer, also namespaced ones (<think>...</mm:think>).
_THINK_RE = re.compile(r"<(?:[\w-]+:)?think>.*?</(?:[\w-]+:)?think>\s*", re.DOTALL)

#: Pairs recognised when stripping cosmetic wrapping quotes off model output.
_QUOTE_PAIRS = {'"': '"', "'": "'", "\u201c": "\u201d", "\u2018": "\u2019"}

Expand Down Expand Up @@ -169,6 +173,7 @@ def _clean(text: str) -> str:
"""Strip leading blank lines and cosmetic wrapping quotes from model output."""
if not isinstance(text, str):
return ""
text = _THINK_RE.sub("", text)
lines = text.split("\n")
while lines and not lines[0].strip():
lines.pop(0)
Expand Down
6 changes: 4 additions & 2 deletions apps/lingua/engine/text_desk.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@

URL_RE = re.compile(r"https?://[^\s<>]*[^\s<>.,;:!?)\]}'\"\u3002\uff0c\u3001]")
NUMBER_RE = re.compile(r"\d+(?:[.,:]\d+)*")
THINK_RE = re.compile(r"<think>.*?</think>", re.DOTALL)
# Reasoning blocks, also namespaced or mismatched ones such as <think>...</mm:think> (MiniMax-M3 on the gateway).
THINK_RE = re.compile(r"<(?:[\w-]+:)?think>.*?</(?:[\w-]+:)?think>\s*", re.DOTALL)
THINK_TAG_RE = re.compile(r"</?(?:[\w-]+:)?think>")
_converters: dict = {}


Expand Down Expand Up @@ -180,7 +182,7 @@ def review_warnings(job: TextJob, translated: str) -> list[str]:
if (entry["source"].casefold() in job.text.casefold()
and entry["target"].casefold() not in translated.casefold()):
warnings.append("Check glossary: preferred term '{}' was not used.".format(entry["target"]))
if "<think>" in translated or "</think>" in translated:
if THINK_TAG_RE.search(translated):
warnings.append("The model emitted reasoning tags; prefer qwen3:8b.")
return warnings

Expand Down
4 changes: 4 additions & 0 deletions apps/lingua/tests/test_maas.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def test_translate_strips_leading_blank_lines(self):
result, _ = self._call("Hello", "English", content="\n\nBonjour\n")
self.assertEqual(result, "Bonjour")

def test_translate_strips_reasoning_blocks(self):
result, _ = self._call("Hello", "French", content="<think>the user wants French</mm:think>\nBonjour")
self.assertEqual(result, "Bonjour")


class ErrorHandlingTests(unittest.TestCase):
def test_http_error_raises_maas_error(self):
Expand Down
1 change: 1 addition & 0 deletions apps/lingua/tests/test_text_desk.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_prompt_treats_text_as_data(self):

def test_finish_and_script(self):
self.assertEqual(text_desk.finish("<think>hmm</think>\n\"会议室\"", TW), "會議室")
self.assertEqual(text_desk.finish("<think>let me see\n- meeting room</mm:think>\n会议室", TW), "會議室")
self.assertEqual(text_desk.finish("會議室 https://a.b/會", "Simplified Chinese (简体中文)"),
"会议室 https://a.b/會")
self.assertEqual(text_desk.finish("Hello", "English"), "Hello")
Expand Down
2 changes: 2 additions & 0 deletions apps/lingua/web/assets/lingua-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ function isMatchingQuotePair(open, close) {
// Strip leading blank lines and cosmetic wrapping quotes from model output.
export function clean(text) {
if (typeof text !== "string") return "";
// Reasoning blocks a model may put before its answer, also namespaced ones (<think>...</mm:think>).
text = text.replace(/<(?:[\w-]+:)?think>[\s\S]*?<\/(?:[\w-]+:)?think>\s*/g, "");
let lines = text.split("\n");
while (lines.length > 0 && lines[0].trim() === "") lines.shift();
let out = lines.join("\n").trim();
Expand Down
2 changes: 1 addition & 1 deletion apps/lingua/web/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* or intercepted — every call hits the network so the key in localStorage
* stays usable and any model change on the gateway is picked up immediately.
*/
const CACHE = 'lingua-cache-v6';
const CACHE = 'lingua-cache-v7';

const PRECACHE = [
'./',
Expand Down
Loading