diff --git a/src/chat/replyer/default_generator.py b/src/chat/replyer/default_generator.py index ef9cce84d..3ad209aa4 100644 --- a/src/chat/replyer/default_generator.py +++ b/src/chat/replyer/default_generator.py @@ -136,7 +136,7 @@ def init_prompt(): 4. 不要浮夸,不要夸张修辞,不要输出多余内容(包括前后缀,冒号和引号,括号(),表情包,at或 @等 )。 最终请输出一条简短、完整且口语化的回复。 --------------------------------- + -------------------------------- {time_block} {reply_target_block} @@ -1024,6 +1024,21 @@ class DefaultReplyer: prompt = Prompt(template=template_prompt.template, parameters=prompt_parameters) prompt_text = await prompt.build() + # --- 动态添加分割指令 --- + if global_config.response_splitter.enable: + split_instruction = """ +## 分割指令 +你正在通过一个即时聊天软件发送消息。请模仿一个真实人类的打字和发送习惯: +- **简洁明了**: 如果一句话能说清楚,就一次性发出去,不要添加任何标记。 +- **自然断句**: 当你想表达一个转折、一个停顿,或者想补充说明时,就像正常人会先发一部分再发另一部分一样,请在断句处插入 `[SPLIT]` 标记。 +- **动机**: 使用 `[SPLIT]` 的目的是为了让对话节奏更自然,更有层次感,而不是为了分割而分割。 +示例: "我刚刚看到一个超好笑的视频![SPLIT]等我找找发给你~" +""" + # 在 "现在,你说:" 之前插入 + parts = prompt_text.rsplit("现在,你说:", 1) + if len(parts) == 2: + prompt_text = f"{parts[0]}{split_instruction}\n现在,你说:{parts[1]}" + return prompt_text async def build_prompt_rewrite_context( diff --git a/src/chat/utils/utils.py b/src/chat/utils/utils.py index 501bf382d..19f3ced99 100644 --- a/src/chat/utils/utils.py +++ b/src/chat/utils/utils.py @@ -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 = []