feat(chat): 实现由 LLM 控制的自然回复分割
之前基于标点符号的自动分割逻辑较为僵硬,有时会破坏回复的连贯性,导致对话体验不佳。 本次更新引入了一种由 LLM 主导的回复分割机制: 1. 在 Prompt 中增加了明确的分割指令,引导 LLM 在需要模拟人类对话停顿或转折时,使用 `[SPLIT]` 标记。 2. 后端回复处理逻辑相应更新,优先根据 `[SPLIT]` 标记分割消息。 3. 若 LLM 未提供 `[SPLIT]` 标记,则将整段回复作为单条消息发送,避免了不必要的拆分。 此项改动旨在让消息的发送节奏更贴近真实人类的聊天习惯,从而提升交互的自然感和流畅度。
This commit is contained in:
@@ -331,8 +331,17 @@ def process_llm_response(text: str, enable_splitter: bool = True, enable_chinese
|
||||
)
|
||||
|
||||
if global_config.response_splitter.enable and enable_splitter:
|
||||
split_sentences = split_into_sentences_w_remove_punctuation(cleaned_text)
|
||||
logger.info("回复分割器已启用。")
|
||||
if "[SPLIT]" in cleaned_text:
|
||||
split_sentences_raw = cleaned_text.split("[SPLIT]")
|
||||
# 清理每个句子首尾可能由LLM添加的空格或换行符,并移除空句子
|
||||
split_sentences = [s.strip() for s in split_sentences_raw if s.strip()]
|
||||
logger.debug(f"LLM 自定义分割结果: {split_sentences}")
|
||||
else:
|
||||
# 如果没有 [SPLIT] 标记,则不进行任何分割
|
||||
split_sentences = [cleaned_text]
|
||||
else:
|
||||
logger.debug("回复分割器已禁用。")
|
||||
split_sentences = [cleaned_text]
|
||||
|
||||
sentences = []
|
||||
|
||||
Reference in New Issue
Block a user