Skip to content

Commit 5c5515d

Browse files
authored
fix: segmented reply regex error handling (#3771)
* fix: segmented reply regex error handling closes: #3761 * fix: improve regex handling for segmented replies to support multiline input * fix: update regex handling in ResultDecorateStage to use findall for segmented replies * fix: update error logging message for segmented reply regex handling
1 parent 3932b8f commit 5c5515d

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

  • astrbot/core/pipeline/result_decorate

astrbot/core/pipeline/result_decorate/stage.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,21 @@ async def process(
161161
# 不分段回复
162162
new_chain.append(comp)
163163
continue
164-
split_response = re.findall(
165-
self.regex,
166-
comp.text,
167-
re.DOTALL | re.MULTILINE,
168-
)
164+
try:
165+
split_response = re.findall(
166+
self.regex,
167+
comp.text,
168+
re.DOTALL | re.MULTILINE,
169+
)
170+
except re.error:
171+
logger.error(
172+
f"分段回复正则表达式错误,使用默认分段方式: {traceback.format_exc()}",
173+
)
174+
split_response = re.findall(
175+
r".*?[。?!~…]+|.+$",
176+
comp.text,
177+
re.DOTALL | re.MULTILINE,
178+
)
169179
if not split_response:
170180
new_chain.append(comp)
171181
continue

0 commit comments

Comments
 (0)