fix(streaming): strip Gemma 4 thinking token delimiter in all paths — closes #607
Fixes <|turn|>thinking delimiter (was wrong as <|turn>thinking) in api/streaming.py, static/messages.js, and static/ui.js. Adds 13 regression tests. Independent review by @nesquena.
This commit is contained in:
@@ -68,6 +68,7 @@ def _strip_thinking_markup(text: str) -> str:
|
||||
s = str(text)
|
||||
s = re.sub(r'<think>.*?</think>', ' ', s, flags=re.IGNORECASE | re.DOTALL)
|
||||
s = re.sub(r'<\|channel\|>thought.*?<channel\|>', ' ', s, flags=re.IGNORECASE | re.DOTALL)
|
||||
s = re.sub(r'<\|turn\|>thinking\n.*?<turn\|>', ' ', s, flags=re.IGNORECASE | re.DOTALL) # Gemma 4
|
||||
s = re.sub(r'^\s*(the|ther)\s+user\s+is\s+asking.*$', ' ', s, flags=re.IGNORECASE | re.MULTILINE)
|
||||
s = re.sub(r'\s+', ' ', s).strip()
|
||||
return s
|
||||
@@ -96,7 +97,7 @@ def _looks_invalid_generated_title(text: str) -> bool:
|
||||
if not s.strip():
|
||||
return True
|
||||
return bool(
|
||||
re.search(r'<think>|<\|channel\|>thought', s, flags=re.IGNORECASE)
|
||||
re.search(r'<think>|<\|channel\|>thought|<\|turn\|>thinking', s, flags=re.IGNORECASE)
|
||||
or re.search(r'^\s*(the|ther)\s+user\s+', s, flags=re.IGNORECASE)
|
||||
or re.search(r'^\s*user\s+\w+\s+', s, flags=re.IGNORECASE)
|
||||
or re.search(r'\b(they|user)\s+want(s)?\s+me\s+to\b', s, flags=re.IGNORECASE)
|
||||
|
||||
Reference in New Issue
Block a user