Skip to content

Commit a27cdd1

Browse files
committed
❇️ 冒泡意愿累计逻辑
1 parent 75e6001 commit a27cdd1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/nonebot_plugin_nyaturingtest/session.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class _ChattingState(Enum):
4040
"""
4141
潜水状态
4242
"""
43-
POP_ACTIVE = 1
43+
BUBBLE = 1
4444
"""
4545
冒泡状态
4646
"""
@@ -53,7 +53,7 @@ def __str__(self):
5353
match self:
5454
case _ChattingState.ILDE:
5555
return "潜水状态"
56-
case _ChattingState.POP_ACTIVE:
56+
case _ChattingState.BUBBLE:
5757
return "冒泡状态"
5858
case _ChattingState.ACTIVE:
5959
return "对话状态"
@@ -118,6 +118,10 @@ def __init__(self, siliconflow_api_key: str, id: str = "global", name: str = "te
118118
"""
119119
对话状态
120120
"""
121+
self.__bubble_willing_sum = 0.0
122+
"""
123+
冒泡意愿总和(冒泡意愿会累积)
124+
"""
121125

122126
# 从文件加载会话状态(如果存在)
123127
self.load_session()
@@ -692,7 +696,9 @@ def __feedback_stage(
692696
logger.debug(f"nyabot潜水意愿:{idle_chance}")
693697
# 评估转换到状态1的概率
694698
bubble_chance = response_dict["willing"]["1"]
695-
logger.debug(f"nyabot冒泡意愿:{bubble_chance}")
699+
self.__bubble_willing_sum += bubble_chance
700+
logger.debug(f"nyabot本次冒泡意愿:{bubble_chance}")
701+
logger.debug(f"nyabot冒泡意愿累计:{self.__bubble_willing_sum}")
696702
# 评估转换到状态2的概率
697703
chat_chance = response_dict["willing"]["2"]
698704
logger.debug(f"nyabot对话意愿:{chat_chance}")
@@ -704,9 +710,11 @@ def __feedback_stage(
704710
case _ChattingState.ILDE:
705711
if chat_chance >= random_value:
706712
self.__chatting_state = _ChattingState.ACTIVE
707-
elif bubble_chance >= random_value:
708-
self.__chatting_state = _ChattingState.POP_ACTIVE
709-
case _ChattingState.POP_ACTIVE:
713+
self.__bubble_willing_sum = 0.0
714+
elif self.__bubble_willing_sum >= random_value:
715+
self.__chatting_state = _ChattingState.BUBBLE
716+
self.__bubble_willing_sum = 0.0
717+
case _ChattingState.BUBBLE:
710718
if chat_chance >= random_value:
711719
self.__chatting_state = _ChattingState.ACTIVE
712720
elif idle_chance >= random_value:
@@ -888,7 +896,7 @@ def update(self, messages_chunk: list[Message], llm: Callable[[str], str]) -> li
888896
case _ChattingState.ILDE:
889897
logger.debug("nyabot潜水中...")
890898
reply_messages = None
891-
case _ChattingState.POP_ACTIVE:
899+
case _ChattingState.BUBBLE:
892900
logger.debug("nyabot冒泡中...")
893901
reply_messages = self.__chat_stage(
894902
search_stage_result=search_stage_result,

0 commit comments

Comments
 (0)