From 028a08703493dbd6d3d9c92bebd9b4d516ea4358 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Sat, 5 Apr 2025 18:57:41 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=BD=BB=E5=BA=95=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E8=A1=A8=E6=83=85=E5=8C=85=E6=89=93=E5=AD=97=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E7=82=B8=E8=A3=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/chat/message_sender.py | 10 ++++++- src/plugins/chat/utils.py | 26 +++++++++---------- .../think_flow_chat/think_flow_chat.py | 6 +++-- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/plugins/chat/message_sender.py b/src/plugins/chat/message_sender.py index 9621819cc..566fe295e 100644 --- a/src/plugins/chat/message_sender.py +++ b/src/plugins/chat/message_sender.py @@ -64,8 +64,14 @@ class Message_Sender: logger.warning(f"消息“{message.processed_plain_text}”已被撤回,不发送") break if not is_recalled: - typing_time = calculate_typing_time(message.processed_plain_text,message.is_emoji) + # print(message.processed_plain_text + str(message.is_emoji)) + typing_time = calculate_typing_time( + input_string=message.processed_plain_text, + thinking_start_time=message.thinking_start_time, + is_emoji=message.is_emoji) + logger.debug(f"{message.processed_plain_text},{typing_time},计算输入时间结束") await asyncio.sleep(typing_time) + logger.debug(f"{message.processed_plain_text},{typing_time},等待输入时间结束") message_json = message.to_dict() @@ -220,6 +226,8 @@ class MessageManager: await message_earliest.process() + # print(f"message_earliest.thinking_start_tim22222e:{message_earliest.thinking_start_time}") + await message_sender.send_message(message_earliest) await self.storage.store_message(message_earliest, message_earliest.chat_stream) diff --git a/src/plugins/chat/utils.py b/src/plugins/chat/utils.py index 028335640..26bd3a171 100644 --- a/src/plugins/chat/utils.py +++ b/src/plugins/chat/utils.py @@ -334,7 +334,7 @@ def process_llm_response(text: str) -> List[str]: return sentences -def calculate_typing_time(input_string: str, chinese_time: float = 0.2, english_time: float = 0.1, is_emoji: bool = False) -> float: +def calculate_typing_time(input_string: str, thinking_start_time: float, chinese_time: float = 0.2, english_time: float = 0.1, is_emoji: bool = False) -> float: """ 计算输入字符串所需的时间,中文和英文字符有不同的输入时间 input_string (str): 输入的字符串 @@ -347,15 +347,6 @@ def calculate_typing_time(input_string: str, chinese_time: float = 0.2, english_ - 在所有输入结束后,额外加上回车时间0.3秒 - 如果is_emoji为True,将使用固定1秒的输入时间 """ - - # 如果输入是列表,将其连接成字符串 - if isinstance(input_string, list): - input_string = ''.join(input_string) - - # 确保现在是字符串类型 - if not isinstance(input_string, str): - input_string = str(input_string) - mood_manager = MoodManager.get_instance() # 将0-1的唤醒度映射到-1到1 mood_arousal = mood_manager.current_mood.arousal @@ -378,10 +369,19 @@ def calculate_typing_time(input_string: str, chinese_time: float = 0.2, english_ else: # 其他字符(如英文) total_time += english_time - if is_emoji: - total_time = 0.7 - return total_time + 0.3 # 加上回车时间 + if is_emoji: + total_time = 1 + + if time.time() - thinking_start_time > 10: + total_time = 1 + + # print(f"thinking_start_time:{thinking_start_time}") + # print(f"nowtime:{time.time()}") + # print(f"nowtime - thinking_start_time:{time.time() - thinking_start_time}") + # print(f"{total_time}") + + return total_time # 加上回车时间 def cosine_similarity(v1, v2): diff --git a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py index c5ab77b6d..5bb11b53a 100644 --- a/src/plugins/chat_module/think_flow_chat/think_flow_chat.py +++ b/src/plugins/chat_module/think_flow_chat/think_flow_chat.py @@ -95,6 +95,8 @@ class ThinkFlowChat: ) if not mark_head: mark_head = True + + # print(f"thinking_start_time:{bot_message.thinking_start_time}") message_set.add_message(bot_message) message_manager.add_message(message_set) @@ -272,11 +274,11 @@ class ThinkFlowChat: timer2 = time.time() timing_results["发送消息"] = timer2 - timer1 - # 处理表情包 + # 发送表情包 timer1 = time.time() await self._handle_emoji(message, chat, response_set) timer2 = time.time() - timing_results["处理表情包"] = timer2 - timer1 + timing_results["发送表情包"] = timer2 - timer1 # 更新心流 timer1 = time.time()