Update src/utils.py
Browse files- src/utils.py +7 -7
src/utils.py
CHANGED
@@ -34,14 +34,13 @@ def has_meaningful_content(text):
|
|
34 |
|
35 |
def remove_reasoning_and_sources(text):
|
36 |
"""
|
37 |
-
Remove reasoning and sources sections from the main response text.
|
38 |
-
Follow-up questions are no longer removed as they're now displayed separately.
|
39 |
|
40 |
Args:
|
41 |
text (str): The text to clean
|
42 |
|
43 |
Returns:
|
44 |
-
str: Text without reasoning and sources sections
|
45 |
"""
|
46 |
if not text:
|
47 |
return text
|
@@ -50,8 +49,9 @@ def remove_reasoning_and_sources(text):
|
|
50 |
pattern_reasoning = r'(?i)(\n+\s*reasoning:|\n+\s*\*{0,2}reasoning\*{0,2}:?|\n+\s*#{1,3}\s*reasoning).*?(?=\n+\s*(?:#{1,3}|follow[ -]?up questions:|sources:|references:|\Z))'
|
51 |
cleaned_text = re.sub(pattern_reasoning, '', text, flags=re.DOTALL)
|
52 |
|
53 |
-
#
|
54 |
-
|
|
|
55 |
|
56 |
# Then, remove any sources/references sections
|
57 |
pattern_sources = r'(?i)(\n+\s*sources:|\n+\s*references:|\n+\s*\*{0,2}sources\*{0,2}:?|\n+\s*\*{0,2}references\*{0,2}:?|\n+\s*#{1,3}\s*sources|\n+\s*#{1,3}\s*references).*?(?=\n+\s*(?:#{1,3}|\Z))'
|
@@ -66,8 +66,8 @@ def remove_reasoning_and_sources(text):
|
|
66 |
skip_section = False
|
67 |
|
68 |
for line in lines:
|
69 |
-
# Check if we should skip this line (part of reasoning or sources
|
70 |
-
if re.search(r'(?i)^(\s*reasoning:|\s*sources:|\s*references:|\s*\*{0,2}reasoning\*{0,2}:?|\s*\*{0,2}sources\*{0,2}:?|\s*\*{0,2}references\*{0,2}:?|\s*#{1,3}\s*reasoning|\s*#{1,3}\s*sources|\s*#{1,3}\s*references)', line):
|
71 |
skip_section = True
|
72 |
continue
|
73 |
# Check if we're entering a new section
|
|
|
34 |
|
35 |
def remove_reasoning_and_sources(text):
|
36 |
"""
|
37 |
+
Remove reasoning, follow-up questions, and sources sections from the main response text.
|
|
|
38 |
|
39 |
Args:
|
40 |
text (str): The text to clean
|
41 |
|
42 |
Returns:
|
43 |
+
str: Text without reasoning, follow-up questions, and sources sections
|
44 |
"""
|
45 |
if not text:
|
46 |
return text
|
|
|
49 |
pattern_reasoning = r'(?i)(\n+\s*reasoning:|\n+\s*\*{0,2}reasoning\*{0,2}:?|\n+\s*#{1,3}\s*reasoning).*?(?=\n+\s*(?:#{1,3}|follow[ -]?up questions:|sources:|references:|\Z))'
|
50 |
cleaned_text = re.sub(pattern_reasoning, '', text, flags=re.DOTALL)
|
51 |
|
52 |
+
# Remove follow-up questions sections
|
53 |
+
pattern_followup = r'(?i)(\n+\s*follow[ -]?up questions:|\n+\s*additional questions:|\n+\s*\*{0,2}follow[ -]?up questions\*{0,2}:?|\n+\s*#{1,3}\s*follow[ -]?up questions).*?(?=\n+\s*(?:#{1,3}|reasoning:|sources:|references:|\Z))'
|
54 |
+
cleaned_text = re.sub(pattern_followup, '', cleaned_text, flags=re.DOTALL)
|
55 |
|
56 |
# Then, remove any sources/references sections
|
57 |
pattern_sources = r'(?i)(\n+\s*sources:|\n+\s*references:|\n+\s*\*{0,2}sources\*{0,2}:?|\n+\s*\*{0,2}references\*{0,2}:?|\n+\s*#{1,3}\s*sources|\n+\s*#{1,3}\s*references).*?(?=\n+\s*(?:#{1,3}|\Z))'
|
|
|
66 |
skip_section = False
|
67 |
|
68 |
for line in lines:
|
69 |
+
# Check if we should skip this line (part of reasoning, follow-up questions, or sources section)
|
70 |
+
if re.search(r'(?i)^(\s*reasoning:|\s*follow[ -]?up questions:|\s*additional questions:|\s*sources:|\s*references:|\s*\*{0,2}reasoning\*{0,2}:?|\s*\*{0,2}follow[ -]?up questions\*{0,2}:?|\s*\*{0,2}sources\*{0,2}:?|\s*\*{0,2}references\*{0,2}:?|\s*#{1,3}\s*reasoning|\s*#{1,3}\s*follow[ -]?up questions|\s*#{1,3}\s*sources|\s*#{1,3}\s*references)', line):
|
71 |
skip_section = True
|
72 |
continue
|
73 |
# Check if we're entering a new section
|