From 453287b06b33de8dbead7b6a67b0014a79b941e5 Mon Sep 17 00:00:00 2001 From: Yongteng Lei Date: Fri, 23 May 2025 09:46:38 +0800 Subject: [PATCH] Feat: more robust fallbacks for citations (#7801) ### What problem does this PR solve? Add more robust fallbacks for citations ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) --- api/db/services/dialog_service.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/db/services/dialog_service.py b/api/db/services/dialog_service.py index 79fcfcad3..c498b924a 100644 --- a/api/db/services/dialog_service.py +++ b/api/db/services/dialog_service.py @@ -327,8 +327,8 @@ def chat(dialog, messages, stream=True, **kwargs): find_and_replace(r"\$\[(\d+)\]\$") # $[12]$ find_and_replace(r"\$\$(\d+)\${2,}") # $$12$$$$ find_and_replace(r"\$(\d+)\$") # $12$ - find_and_replace(r"#(\d+)\$\$") # #12$$ - find_and_replace(r"##(\d+)\$") # ##12$ + find_and_replace(r"(#{2,})(\d+)(\${2,})", group_index=2) # 2+ # and 2+ $ + find_and_replace(r"(#{2,})(\d+)(#{1,})", group_index=2) # 2+ # and 1+ # find_and_replace(r"##(\d+)#{2,}") # ##12### find_and_replace(r"【(\d+)】") # 【12】 find_and_replace(r"ref\s*(\d+)", flags=re.IGNORECASE) # ref12, ref 12, REF 12