fix: 保证能运行的小修改
This commit is contained in:
@@ -164,7 +164,6 @@ class ChatBot:
|
||||
response,raw_content = await self.gpt.generate_response(message)
|
||||
|
||||
if response:
|
||||
container = message_manager.get_container(chat.stream_id)
|
||||
container = message_manager.get_container(chat.stream_id)
|
||||
thinking_message = None
|
||||
# 找到message,删除
|
||||
@@ -182,12 +181,12 @@ class ChatBot:
|
||||
# 记录开始思考的时间,避免从思考到回复的时间太久
|
||||
thinking_start_time = thinking_message.thinking_start_time
|
||||
message_set = MessageSet(chat, think_id)
|
||||
message_set = MessageSet(chat, think_id)
|
||||
#计算打字时间,1是为了模拟打字,2是避免多条回复乱序
|
||||
accu_typing_time = 0
|
||||
|
||||
mark_head = False
|
||||
for msg in response:
|
||||
print("test")
|
||||
# print(f"\033[1;32m[回复内容]\033[0m {msg}")
|
||||
# 通过时间改变时间戳
|
||||
typing_time = calculate_typing_time(msg)
|
||||
@@ -239,6 +238,7 @@ class ChatBot:
|
||||
is_emoji=True
|
||||
)
|
||||
message_manager.add_message(bot_message)
|
||||
|
||||
emotion = await self.gpt._get_emotion_tags(raw_content)
|
||||
logger.debug(f"为 '{response}' 获取到的情感标签为:{emotion}")
|
||||
valuedict = {
|
||||
|
||||
@@ -259,7 +259,7 @@ class EmojiManager:
|
||||
upsert=True
|
||||
)
|
||||
# 保存描述到image_descriptions集合
|
||||
await image_manager._save_description_to_db(image_hash, description, 'emoji')
|
||||
image_manager._save_description_to_db(image_hash, description, 'emoji')
|
||||
logger.success(f"同步已存在的表情包到images集合: {filename}")
|
||||
continue
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@ class WillingManager:
|
||||
self.chat_reply_willing: Dict[str, float] = {} # 存储每个聊天流的回复意愿
|
||||
self._decay_task = None
|
||||
self._started = False
|
||||
self.min_reply_willing = 0.01
|
||||
self.attenuation_coefficient = 0.75
|
||||
|
||||
async def _decay_reply_willing(self):
|
||||
"""定期衰减回复意愿"""
|
||||
@@ -35,9 +33,12 @@ class WillingManager:
|
||||
return self.chat_reply_willing.get(stream.stream_id, 0)
|
||||
return 0
|
||||
|
||||
def set_willing(self, chat_id: int, willing: float):
|
||||
"""设置指定群组的回复意愿"""
|
||||
self.group_reply_willing[chat_id] = willing
|
||||
def set_willing(self, chat_id: str, willing: float):
|
||||
"""设置指定聊天流的回复意愿"""
|
||||
self.chat_reply_willing[chat_id] = willing
|
||||
def set_willing(self, chat_id: str, willing: float):
|
||||
"""设置指定聊天流的回复意愿"""
|
||||
self.chat_reply_willing[chat_id] = willing
|
||||
|
||||
async def change_reply_willing_received(self,
|
||||
chat_stream:ChatStream,
|
||||
@@ -50,67 +51,47 @@ class WillingManager:
|
||||
# 获取或创建聊天流
|
||||
stream = chat_stream
|
||||
chat_id = stream.stream_id
|
||||
group_id = stream.group_info.group_id
|
||||
|
||||
# 若非目标回复群组,则直接return
|
||||
if group_id not in config.talk_allowed_groups:
|
||||
reply_probability = 0
|
||||
return reply_probability
|
||||
|
||||
|
||||
current_willing = self.chat_reply_willing.get(chat_id, 0)
|
||||
|
||||
logger.debug(f"[{chat_id}]的初始回复意愿: {current_willing}")
|
||||
|
||||
|
||||
# 根据消息类型(被cue/表情包)调控
|
||||
if is_mentioned_bot:
|
||||
current_willing = min(
|
||||
3.0,
|
||||
current_willing + 0.9
|
||||
)
|
||||
logger.debug(f"被提及, 当前意愿: {current_willing}")
|
||||
# print(f"初始意愿: {current_willing}")
|
||||
if is_mentioned_bot and current_willing < 1.0:
|
||||
current_willing += 0.9
|
||||
print(f"被提及, 当前意愿: {current_willing}")
|
||||
elif is_mentioned_bot:
|
||||
current_willing += 0.05
|
||||
print(f"被重复提及, 当前意愿: {current_willing}")
|
||||
|
||||
if is_emoji:
|
||||
current_willing *= 0.1
|
||||
logger.debug(f"表情包, 当前意愿: {current_willing}")
|
||||
print(f"表情包, 当前意愿: {current_willing}")
|
||||
|
||||
# 兴趣放大系数,若兴趣 > 0.4则增加回复概率
|
||||
interested_rate_amplifier = global_config.response_interested_rate_amplifier
|
||||
logger.debug(f"放大系数_interested_rate: {interested_rate_amplifier}")
|
||||
interested_rate *= interested_rate_amplifier
|
||||
print(f"放大系数_interested_rate: {global_config.response_interested_rate_amplifier}")
|
||||
interested_rate *= global_config.response_interested_rate_amplifier #放大回复兴趣度
|
||||
if interested_rate > 0.4:
|
||||
# print(f"兴趣度: {interested_rate}, 当前意愿: {current_willing}")
|
||||
current_willing += interested_rate-0.4
|
||||
|
||||
current_willing += max(
|
||||
0.0,
|
||||
interested_rate - 0.4
|
||||
)
|
||||
current_willing *= global_config.response_willing_amplifier #放大回复意愿
|
||||
# print(f"放大系数_willing: {global_config.response_willing_amplifier}, 当前意愿: {current_willing}")
|
||||
|
||||
# 回复意愿系数调控,独立乘区
|
||||
willing_amplifier = max(
|
||||
global_config.response_willing_amplifier,
|
||||
self.min_reply_willing
|
||||
)
|
||||
current_willing *= willing_amplifier
|
||||
logger.debug(f"放大系数_willing: {global_config.response_willing_amplifier}, 当前意愿: {current_willing}")
|
||||
reply_probability = max((current_willing - 0.45) * 2, 0)
|
||||
|
||||
# 回复概率迭代,保底0.01回复概率
|
||||
reply_probability = max(
|
||||
(current_willing - 0.45) * 2,
|
||||
self.min_reply_willing
|
||||
)
|
||||
# 检查群组权限(如果是群聊)
|
||||
if chat_stream.group_info:
|
||||
if chat_stream.group_info.group_id not in config.talk_allowed_groups:
|
||||
current_willing = 0
|
||||
reply_probability = 0
|
||||
|
||||
# 降低目标低频群组回复概率
|
||||
down_frequency_rate = max(
|
||||
1.0,
|
||||
global_config.down_frequency_rate
|
||||
)
|
||||
if group_id in config.talk_frequency_down_groups:
|
||||
reply_probability = reply_probability / down_frequency_rate
|
||||
if chat_stream.group_info.group_id in config.talk_frequency_down_groups:
|
||||
reply_probability = reply_probability / global_config.down_frequency_rate
|
||||
|
||||
reply_probability = min(reply_probability, 1)
|
||||
if reply_probability < 0:
|
||||
reply_probability = 0
|
||||
|
||||
self.group_reply_willing[group_id] = min(current_willing, 3.0)
|
||||
logger.debug(f"当前群组{group_id}回复概率:{reply_probability}")
|
||||
self.chat_reply_willing[chat_id] = min(current_willing, 3.0)
|
||||
self.chat_reply_willing[chat_id] = min(current_willing, 3.0)
|
||||
return reply_probability
|
||||
|
||||
def change_reply_willing_sent(self, chat_stream:ChatStream):
|
||||
@@ -135,6 +116,5 @@ class WillingManager:
|
||||
self._decay_task = asyncio.create_task(self._decay_reply_willing())
|
||||
self._started = True
|
||||
|
||||
|
||||
# 创建全局实例
|
||||
willing_manager = WillingManager()
|
||||
Reference in New Issue
Block a user