diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 208807717d..8f3b1d9afc 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -2235,7 +2235,7 @@ def sanitize_tool_pairs(messages: list[dict]) -> list[dict]: return sanitized -SKILL_MENTION_RE = re.compile(r'<\$([^|>]+)\|?[^>]*>') +SKILL_MENTION_RE = re.compile(r'<\$([^|>]+)(?:\|[^>]*)?>') def _get_text_parts(message: dict) -> list[str]: @@ -2259,7 +2259,7 @@ def extract_skill_ids_from_messages(messages: list[dict]) -> set[str]: def strip_skill_mentions(messages: list[dict]) -> None: """Replace <$skillId|label> mention tags with the label in message content in-place.""" - strip_re = re.compile(r'<\$[^|>]+\|?([^>]*)>') + strip_re = re.compile(r'<\$[^|>]+(?:\|([^>]*))?>') for message in messages: content = message.get('content') if isinstance(content, str) and strip_re.search(content):