fix(chat): 完善LLM分句逻辑,在无分割标记时回退至标点分割

当使用 "llm" 模式进行分句时,如果模型未能按预期生成 `[SPLIT]` 标记,之前的逻辑会直接返回整个未分割的文本。

这可能导致过长的句子被发送到下游模块(如TTS),影响体验。本次修改添加了回退机制,当未检测到 `[SPLIT]` 标记时,会自动切换到基于标点的传统分句方法,以提高分句的鲁棒性。
This commit is contained in:
minecraft1024a
2025-09-27 14:37:06 +08:00
parent 866d50c6dc
commit 3cded7220a

View File

@@ -341,9 +341,9 @@ def process_llm_response(text: str, enable_splitter: bool = True, enable_chinese
split_sentences = [s.strip() for s in split_sentences_raw if s.strip()]
else:
if split_mode == "llm":
logger.debug("未检测到 [SPLIT] 标记,本次不进行分割。")
split_sentences = [cleaned_text]
else: # mode == "punctuation"
logger.debug("未检测到 [SPLIT] 标记,回退到基于标点的传统模式进行分割。")
split_sentences = split_into_sentences_w_remove_punctuation(cleaned_text)
else: # mode == "punctuation"
logger.debug("使用基于标点的传统模式进行分割。")
split_sentences = split_into_sentences_w_remove_punctuation(cleaned_text)
else: