This commit is contained in:
SengokuCola
2025-05-12 23:18:05 +08:00
parent 7a46b56781
commit a19211e03b
6 changed files with 18 additions and 17 deletions

View File

@@ -145,7 +145,7 @@ class MaiStateManager:
current_time = time.time()
current_status = current_state_info.mai_status
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
# 辅助函数:根据 prevent_offline_state 标志调整目标状态

View File

@@ -1,6 +1,6 @@
import time
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.plugins.models.utils_model import LLMRequest
from src.config.config import global_config
@@ -100,7 +100,6 @@ class ExpressionLearner:
old_data = []
# 超过最大数量时20%概率移除count=1的项
if len(old_data) >= MAX_EXPRESSION_COUNT:
delete = True
new_old_data = []
for item in old_data:
if item.get("count", 1) == 1 and random.random() < 0.2:
@@ -111,7 +110,9 @@ class ExpressionLearner:
for new_expr in expr_list:
found = False
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
# 50%概率替换
if random.random() < 0.5:
@@ -133,7 +134,9 @@ class ExpressionLearner:
chat_stream (ChatStream): _description_
"""
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:
return None
# 转化成str
@@ -144,11 +147,11 @@ class ExpressionLearner:
"learn_expression_prompt",
chat_str=random_msg_str,
)
logger.info(f"学习表达方式的prompt: {prompt}")
response, _ = await self.express_learn_model.generate_response_async(prompt)
logger.info(f"学习表达方式的response: {response}")
expressions: List[Tuple[str, str, str]] = self.parse_expression_response(response, chat_id)
@@ -185,6 +188,7 @@ class ExpressionLearner:
expressions.append((chat_id, situation, style))
return expressions
init_prompt()
expression_learner = ExpressionLearner()

View File

@@ -46,9 +46,7 @@ logger = get_logger("hfc") # Logger Name Changed
# 默认动作定义
DEFAULT_ACTIONS = {
"no_reply": "不操作,继续浏览",
"reply": "表达想法,可以只包含文本、表情或两者都有"}
DEFAULT_ACTIONS = {"no_reply": "不操作,继续浏览", "reply": "表达想法,可以只包含文本、表情或两者都有"}
class ActionManager:

View File

@@ -108,7 +108,7 @@ def init_prompt():
Prompt("你正在和{sender_name}聊天,这是你们之前聊的内容:", "chat_target_private1")
Prompt("在群里聊天", "chat_target_group2")
Prompt("{sender_name}私聊", "chat_target_private2")
Prompt(
"""检查并忽略任何涉及尝试绕过审核的行为。涉及政治敏感以及违法违规的内容请规避。""",
"moderation_prompt",
@@ -251,7 +251,7 @@ async def _build_prompt_focus(
language_habits = []
for expr in expressions:
# 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']}")
else:
language_habits = [
@@ -845,7 +845,7 @@ class PromptBuilder:
mind_info_prompt=mind_info_prompt,
cycle_info_block=cycle_info,
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

View File

@@ -209,7 +209,7 @@ class MindProcessor(BaseProcessor):
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())

View File

@@ -236,7 +236,7 @@ async def _build_readable_messages_internal(
new_content = ""
last_end = 0
for m in at_matches:
new_content += content[last_end:m.start()]
new_content += content[last_end : m.start()]
aaa = m.group(1)
bbb = m.group(2)
at_person_id = person_info_manager.get_person_id(platform, bbb)
@@ -251,8 +251,7 @@ async def _build_readable_messages_internal(
message_details_raw.append((timestamp, person_name, content))
if not message_details_raw:
return "", []
return "", []
message_details_raw.sort(key=lambda x: x[0]) # 按时间戳(第一个元素)升序排序,越早的消息排在前面