diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 6b39e46763..abdfa62f09 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -135,6 +135,7 @@ from open_webui.utils.skills import ( apply_skills_create_prompt, extract_skill_ids_from_messages, has_prior_user_message, + replace_skill_mentions_with_labels, strip_skill_mentions, ) from open_webui.utils.task import ( @@ -3943,7 +3944,7 @@ async def background_tasks_handler(ctx): title = '' if not title: - title = messages[0].get('content', user_message) + title = replace_skill_mentions_with_labels(messages[0].get('content', user_message)) await Chats.update_chat_title_by_id(metadata['chat_id'], title) @@ -3955,7 +3956,7 @@ async def background_tasks_handler(ctx): ) if title == None and len(messages) == 2 and (not messages_map or len(messages_map) <= 2): - title = messages[0].get('content', user_message) + title = replace_skill_mentions_with_labels(messages[0].get('content', user_message)) await Chats.update_chat_title_by_id(metadata['chat_id'], title) diff --git a/backend/open_webui/utils/skills.py b/backend/open_webui/utils/skills.py index 1e7414705d..a895e09107 100644 --- a/backend/open_webui/utils/skills.py +++ b/backend/open_webui/utils/skills.py @@ -32,6 +32,11 @@ def extract_skill_ids_from_messages(messages: list[dict]) -> set[str]: SKILL_MENTION_STRIP_RE = re.compile(rf'<(?:\$({SKILL_ID_RE})(?:\|([^>]*))?|/({SKILL_ID_RE})\|([^>]*))>') +def replace_skill_mentions_with_labels(text: str) -> str: + """Show labelled skill mentions as their label, for plain text such as chat titles.""" + return SKILL_MENTION_STRIP_RE.sub(lambda match: match.group(2) or match.group(4) or match.group(0), text) + + SKILLS_CREATE_RE = re.compile(r'^/skills:create(?:\s+(.*))?$', re.IGNORECASE | re.DOTALL) OPEN_WEBUI_SKILL_AUTHORING_STANDARDS = """\