fixruff
This commit is contained in:
@@ -145,7 +145,7 @@ class MaiStateManager:
|
|||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
current_status = current_state_info.mai_status
|
current_status = current_state_info.mai_status
|
||||||
time_in_current_status = current_time - current_state_info.last_status_change_time
|
time_in_current_status = current_time - current_state_info.last_status_change_time
|
||||||
time_since_last_min_check = current_time - current_state_info.last_min_check_time
|
_time_since_last_min_check = current_time - current_state_info.last_min_check_time
|
||||||
next_state: Optional[MaiState] = None
|
next_state: Optional[MaiState] = None
|
||||||
|
|
||||||
# 辅助函数:根据 prevent_offline_state 标志调整目标状态
|
# 辅助函数:根据 prevent_offline_state 标志调整目标状态
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
from typing import List, Dict, Optional, Any, Tuple, Coroutine
|
from typing import List, Dict, Optional, Any, Tuple
|
||||||
from src.common.logger_manager import get_logger
|
from src.common.logger_manager import get_logger
|
||||||
from src.plugins.models.utils_model import LLMRequest
|
from src.plugins.models.utils_model import LLMRequest
|
||||||
from src.config.config import global_config
|
from src.config.config import global_config
|
||||||
@@ -100,7 +100,6 @@ class ExpressionLearner:
|
|||||||
old_data = []
|
old_data = []
|
||||||
# 超过最大数量时,20%概率移除count=1的项
|
# 超过最大数量时,20%概率移除count=1的项
|
||||||
if len(old_data) >= MAX_EXPRESSION_COUNT:
|
if len(old_data) >= MAX_EXPRESSION_COUNT:
|
||||||
delete = True
|
|
||||||
new_old_data = []
|
new_old_data = []
|
||||||
for item in old_data:
|
for item in old_data:
|
||||||
if item.get("count", 1) == 1 and random.random() < 0.2:
|
if item.get("count", 1) == 1 and random.random() < 0.2:
|
||||||
@@ -111,7 +110,9 @@ class ExpressionLearner:
|
|||||||
for new_expr in expr_list:
|
for new_expr in expr_list:
|
||||||
found = False
|
found = False
|
||||||
for old_expr in old_data:
|
for old_expr in old_data:
|
||||||
if self.is_similar(new_expr["situation"], old_expr.get("situation", "")) and self.is_similar(new_expr["style"], old_expr.get("style", "")):
|
if self.is_similar(new_expr["situation"], old_expr.get("situation", "")) and self.is_similar(
|
||||||
|
new_expr["style"], old_expr.get("style", "")
|
||||||
|
):
|
||||||
found = True
|
found = True
|
||||||
# 50%概率替换
|
# 50%概率替换
|
||||||
if random.random() < 0.5:
|
if random.random() < 0.5:
|
||||||
@@ -133,7 +134,9 @@ class ExpressionLearner:
|
|||||||
chat_stream (ChatStream): _description_
|
chat_stream (ChatStream): _description_
|
||||||
"""
|
"""
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
random_msg: Optional[List[Dict[str, Any]]] = get_raw_msg_by_timestamp_random(current_time - 3600 * 24, current_time, limit=10)
|
random_msg: Optional[List[Dict[str, Any]]] = get_raw_msg_by_timestamp_random(
|
||||||
|
current_time - 3600 * 24, current_time, limit=10
|
||||||
|
)
|
||||||
if not random_msg:
|
if not random_msg:
|
||||||
return None
|
return None
|
||||||
# 转化成str
|
# 转化成str
|
||||||
@@ -185,6 +188,7 @@ class ExpressionLearner:
|
|||||||
expressions.append((chat_id, situation, style))
|
expressions.append((chat_id, situation, style))
|
||||||
return expressions
|
return expressions
|
||||||
|
|
||||||
|
|
||||||
init_prompt()
|
init_prompt()
|
||||||
|
|
||||||
expression_learner = ExpressionLearner()
|
expression_learner = ExpressionLearner()
|
||||||
|
|||||||
@@ -46,9 +46,7 @@ logger = get_logger("hfc") # Logger Name Changed
|
|||||||
|
|
||||||
|
|
||||||
# 默认动作定义
|
# 默认动作定义
|
||||||
DEFAULT_ACTIONS = {
|
DEFAULT_ACTIONS = {"no_reply": "不操作,继续浏览", "reply": "表达想法,可以只包含文本、表情或两者都有"}
|
||||||
"no_reply": "不操作,继续浏览",
|
|
||||||
"reply": "表达想法,可以只包含文本、表情或两者都有"}
|
|
||||||
|
|
||||||
|
|
||||||
class ActionManager:
|
class ActionManager:
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ async def _build_prompt_focus(
|
|||||||
language_habits = []
|
language_habits = []
|
||||||
for expr in expressions:
|
for expr in expressions:
|
||||||
# print(f"expr: {expr}")
|
# print(f"expr: {expr}")
|
||||||
if isinstance(expr, dict) and 'situation' in expr and 'style' in expr:
|
if isinstance(expr, dict) and "situation" in expr and "style" in expr:
|
||||||
language_habits.append(f"当{expr['situation']}时,使用 {expr['style']}")
|
language_habits.append(f"当{expr['situation']}时,使用 {expr['style']}")
|
||||||
else:
|
else:
|
||||||
language_habits = [
|
language_habits = [
|
||||||
@@ -845,7 +845,7 @@ class PromptBuilder:
|
|||||||
mind_info_prompt=mind_info_prompt,
|
mind_info_prompt=mind_info_prompt,
|
||||||
cycle_info_block=cycle_info,
|
cycle_info_block=cycle_info,
|
||||||
action_options_text=action_options_text,
|
action_options_text=action_options_text,
|
||||||
moderation_prompt = await global_prompt_manager.get_prompt_async("moderation_prompt"),
|
moderation_prompt=await global_prompt_manager.get_prompt_async("moderation_prompt"),
|
||||||
)
|
)
|
||||||
return prompt
|
return prompt
|
||||||
|
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ class MindProcessor(BaseProcessor):
|
|||||||
relation_prompt += await relationship_manager.build_relationship_info(person, is_id=True)
|
relation_prompt += await relationship_manager.build_relationship_info(person, is_id=True)
|
||||||
|
|
||||||
# 构建个性部分
|
# 构建个性部分
|
||||||
prompt_personality = individuality.get_prompt(x_person=2, level=2)
|
# prompt_personality = individuality.get_prompt(x_person=2, level=2)
|
||||||
|
|
||||||
# 获取当前时间
|
# 获取当前时间
|
||||||
time_now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
time_now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ async def _build_readable_messages_internal(
|
|||||||
new_content = ""
|
new_content = ""
|
||||||
last_end = 0
|
last_end = 0
|
||||||
for m in at_matches:
|
for m in at_matches:
|
||||||
new_content += content[last_end:m.start()]
|
new_content += content[last_end : m.start()]
|
||||||
aaa = m.group(1)
|
aaa = m.group(1)
|
||||||
bbb = m.group(2)
|
bbb = m.group(2)
|
||||||
at_person_id = person_info_manager.get_person_id(platform, bbb)
|
at_person_id = person_info_manager.get_person_id(platform, bbb)
|
||||||
@@ -253,7 +253,6 @@ async def _build_readable_messages_internal(
|
|||||||
if not message_details_raw:
|
if not message_details_raw:
|
||||||
return "", []
|
return "", []
|
||||||
|
|
||||||
|
|
||||||
message_details_raw.sort(key=lambda x: x[0]) # 按时间戳(第一个元素)升序排序,越早的消息排在前面
|
message_details_raw.sort(key=lambda x: x[0]) # 按时间戳(第一个元素)升序排序,越早的消息排在前面
|
||||||
|
|
||||||
# 应用截断逻辑 (如果 truncate 为 True)
|
# 应用截断逻辑 (如果 truncate 为 True)
|
||||||
|
|||||||
Reference in New Issue
Block a user