使generator能够自定义是否切句或者生成错字
跨越了三份文件的参数传递((
This commit is contained in:
@@ -162,6 +162,8 @@ class DefaultReplyer:
|
|||||||
async def generate_reply_with_context(
|
async def generate_reply_with_context(
|
||||||
self,
|
self,
|
||||||
reply_data: Dict[str, Any],
|
reply_data: Dict[str, Any],
|
||||||
|
enable_splitter: bool=True,
|
||||||
|
enable_chinese_typo: bool=True
|
||||||
) -> Tuple[bool, Optional[List[str]]]:
|
) -> Tuple[bool, Optional[List[str]]]:
|
||||||
"""
|
"""
|
||||||
回复器 (Replier): 核心逻辑,负责生成回复文本。
|
回复器 (Replier): 核心逻辑,负责生成回复文本。
|
||||||
@@ -191,7 +193,7 @@ class DefaultReplyer:
|
|||||||
logger.error(f"{self.log_prefix}LLM 生成失败: {llm_e}")
|
logger.error(f"{self.log_prefix}LLM 生成失败: {llm_e}")
|
||||||
return False, None # LLM 调用失败则无法生成回复
|
return False, None # LLM 调用失败则无法生成回复
|
||||||
|
|
||||||
processed_response = process_llm_response(content)
|
processed_response = process_llm_response(content,enable_splitter,enable_chinese_typo)
|
||||||
|
|
||||||
# 5. 处理 LLM 响应
|
# 5. 处理 LLM 响应
|
||||||
if not content:
|
if not content:
|
||||||
@@ -216,6 +218,8 @@ class DefaultReplyer:
|
|||||||
async def rewrite_reply_with_context(
|
async def rewrite_reply_with_context(
|
||||||
self,
|
self,
|
||||||
reply_data: Dict[str, Any],
|
reply_data: Dict[str, Any],
|
||||||
|
enable_splitter: bool=True,
|
||||||
|
enable_chinese_typo: bool=True
|
||||||
) -> Tuple[bool, Optional[List[str]]]:
|
) -> Tuple[bool, Optional[List[str]]]:
|
||||||
"""
|
"""
|
||||||
表达器 (Expressor): 核心逻辑,负责生成回复文本。
|
表达器 (Expressor): 核心逻辑,负责生成回复文本。
|
||||||
@@ -252,7 +256,7 @@ class DefaultReplyer:
|
|||||||
logger.error(f"{self.log_prefix}LLM 生成失败: {llm_e}")
|
logger.error(f"{self.log_prefix}LLM 生成失败: {llm_e}")
|
||||||
return False, None # LLM 调用失败则无法生成回复
|
return False, None # LLM 调用失败则无法生成回复
|
||||||
|
|
||||||
processed_response = process_llm_response(content)
|
processed_response = process_llm_response(content,enable_splitter,enable_chinese_typo)
|
||||||
|
|
||||||
# 5. 处理 LLM 响应
|
# 5. 处理 LLM 响应
|
||||||
if not content:
|
if not content:
|
||||||
|
|||||||
@@ -321,7 +321,7 @@ def random_remove_punctuation(text: str) -> str:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def process_llm_response(text: str) -> list[str]:
|
def process_llm_response(text: str, enable_splitter: bool=True, enable_chinese_typo: bool=True) -> list[str]:
|
||||||
if not global_config.response_post_process.enable_response_post_process:
|
if not global_config.response_post_process.enable_response_post_process:
|
||||||
return [text]
|
return [text]
|
||||||
|
|
||||||
@@ -359,14 +359,14 @@ def process_llm_response(text: str) -> list[str]:
|
|||||||
word_replace_rate=global_config.chinese_typo.word_replace_rate,
|
word_replace_rate=global_config.chinese_typo.word_replace_rate,
|
||||||
)
|
)
|
||||||
|
|
||||||
if global_config.response_splitter.enable:
|
if global_config.response_splitter.enable and enable_splitter:
|
||||||
split_sentences = split_into_sentences_w_remove_punctuation(cleaned_text)
|
split_sentences = split_into_sentences_w_remove_punctuation(cleaned_text)
|
||||||
else:
|
else:
|
||||||
split_sentences = [cleaned_text]
|
split_sentences = [cleaned_text]
|
||||||
|
|
||||||
sentences = []
|
sentences = []
|
||||||
for sentence in split_sentences:
|
for sentence in split_sentences:
|
||||||
if global_config.chinese_typo.enable:
|
if global_config.chinese_typo.enable and enable_chinese_typo:
|
||||||
typoed_text, typo_corrections = typo_generator.create_typo_sentence(sentence)
|
typoed_text, typo_corrections = typo_generator.create_typo_sentence(sentence)
|
||||||
sentences.append(typoed_text)
|
sentences.append(typoed_text)
|
||||||
if typo_corrections:
|
if typo_corrections:
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ async def generate_reply(
|
|||||||
chat_stream=None,
|
chat_stream=None,
|
||||||
action_data: Dict[str, Any] = None,
|
action_data: Dict[str, Any] = None,
|
||||||
chat_id: str = None,
|
chat_id: str = None,
|
||||||
|
enable_splitter: bool=True,
|
||||||
|
enable_chinese_typo: bool=True
|
||||||
) -> Tuple[bool, List[Tuple[str, Any]]]:
|
) -> Tuple[bool, List[Tuple[str, Any]]]:
|
||||||
"""生成回复
|
"""生成回复
|
||||||
|
|
||||||
@@ -80,6 +82,8 @@ async def generate_reply(
|
|||||||
chat_stream: 聊天流对象(优先)
|
chat_stream: 聊天流对象(优先)
|
||||||
action_data: 动作数据
|
action_data: 动作数据
|
||||||
chat_id: 聊天ID(备用)
|
chat_id: 聊天ID(备用)
|
||||||
|
enable_splitter: 是否启用消息分割器
|
||||||
|
enable_chinese_typo: 是否启用错字生成器
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Tuple[bool, List[Tuple[str, Any]]]: (是否成功, 回复集合)
|
Tuple[bool, List[Tuple[str, Any]]]: (是否成功, 回复集合)
|
||||||
@@ -96,6 +100,8 @@ async def generate_reply(
|
|||||||
# 调用回复器生成回复
|
# 调用回复器生成回复
|
||||||
success, reply_set = await replyer.generate_reply_with_context(
|
success, reply_set = await replyer.generate_reply_with_context(
|
||||||
reply_data=action_data or {},
|
reply_data=action_data or {},
|
||||||
|
enable_splitter=enable_splitter,
|
||||||
|
enable_chinese_typo=enable_chinese_typo
|
||||||
)
|
)
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
@@ -114,6 +120,8 @@ async def rewrite_reply(
|
|||||||
chat_stream=None,
|
chat_stream=None,
|
||||||
reply_data: Dict[str, Any] = None,
|
reply_data: Dict[str, Any] = None,
|
||||||
chat_id: str = None,
|
chat_id: str = None,
|
||||||
|
enable_splitter: bool=True,
|
||||||
|
enable_chinese_typo: bool=True
|
||||||
) -> Tuple[bool, List[Tuple[str, Any]]]:
|
) -> Tuple[bool, List[Tuple[str, Any]]]:
|
||||||
"""重写回复
|
"""重写回复
|
||||||
|
|
||||||
@@ -121,6 +129,8 @@ async def rewrite_reply(
|
|||||||
chat_stream: 聊天流对象(优先)
|
chat_stream: 聊天流对象(优先)
|
||||||
reply_data: 回复数据
|
reply_data: 回复数据
|
||||||
chat_id: 聊天ID(备用)
|
chat_id: 聊天ID(备用)
|
||||||
|
enable_splitter: 是否启用消息分割器
|
||||||
|
enable_chinese_typo: 是否启用错字生成器
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Tuple[bool, List[Tuple[str, Any]]]: (是否成功, 回复集合)
|
Tuple[bool, List[Tuple[str, Any]]]: (是否成功, 回复集合)
|
||||||
@@ -137,6 +147,8 @@ async def rewrite_reply(
|
|||||||
# 调用回复器重写回复
|
# 调用回复器重写回复
|
||||||
success, reply_set = await replyer.rewrite_reply_with_context(
|
success, reply_set = await replyer.rewrite_reply_with_context(
|
||||||
reply_data=reply_data or {},
|
reply_data=reply_data or {},
|
||||||
|
enable_splitter=enable_splitter,
|
||||||
|
enable_chinese_typo=enable_chinese_typo
|
||||||
)
|
)
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
|
|||||||
Reference in New Issue
Block a user