Skip to content
Open
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
14 changes: 3 additions & 11 deletions python/sglang/srt/parser/harmony_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def __init__(self):
"<|call|>",
"<|return|>",
]
self._structural_tokens_set = set(self.guard_tokens)

def parse(self, text: str) -> Tuple[List[Event], str]:
events = []
Expand Down Expand Up @@ -403,17 +404,8 @@ def _is_commentary_filler_between_blocks(

def _is_standalone_structural_token(self, content: str) -> bool:
"""Check if content is just a standalone structural token that should be filtered."""
content_stripped = content.strip()
structural_tokens = [
"<|start|>",
"<|channel|>",
"<|message|>",
"<|constrain|>",
"<|end|>",
"<|call|>",
"<|return|>",
]
return content_stripped in structural_tokens
# Use cached set for O(1) lookup
return content.strip() in self._structural_tokens_set


class TextStrategy:
Expand Down