🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -14,7 +14,6 @@ from src.chat.focus_chat.info.relation_info import RelationInfo
|
|||||||
from src.chat.focus_chat.info.expression_selection_info import ExpressionSelectionInfo
|
from src.chat.focus_chat.info.expression_selection_info import ExpressionSelectionInfo
|
||||||
from src.common.logger import get_logger
|
from src.common.logger import get_logger
|
||||||
from src.chat.utils.prompt_builder import Prompt, global_prompt_manager
|
from src.chat.utils.prompt_builder import Prompt, global_prompt_manager
|
||||||
from src.individuality.individuality import get_individuality
|
|
||||||
from src.chat.focus_chat.planners.action_manager import ActionManager
|
from src.chat.focus_chat.planners.action_manager import ActionManager
|
||||||
from json_repair import repair_json
|
from json_repair import repair_json
|
||||||
from src.chat.focus_chat.planners.base_planner import BasePlanner
|
from src.chat.focus_chat.planners.base_planner import BasePlanner
|
||||||
@@ -26,30 +25,30 @@ install(extra_lines=3)
|
|||||||
|
|
||||||
|
|
||||||
def init_prompt():
|
def init_prompt():
|
||||||
# Prompt(
|
# Prompt(
|
||||||
# """
|
# """
|
||||||
# {time_block}
|
# {time_block}
|
||||||
# {indentify_block}你现在正在参与以下的聊天,以下是具体的聊天内容:
|
# {indentify_block}你现在正在参与以下的聊天,以下是具体的聊天内容:
|
||||||
|
|
||||||
# {chat_content_block}
|
# {chat_content_block}
|
||||||
|
|
||||||
# {self_info_block}
|
# {self_info_block}
|
||||||
# {relation_info_block}
|
# {relation_info_block}
|
||||||
|
|
||||||
# {cycle_info_block}
|
# {cycle_info_block}
|
||||||
|
|
||||||
# {moderation_prompt}
|
# {moderation_prompt}
|
||||||
# 注意,除了下面动作选项之外,你在群聊里不能做其他任何事情,这是你能力的边界,现在请你选择合适的action:
|
# 注意,除了下面动作选项之外,你在群聊里不能做其他任何事情,这是你能力的边界,现在请你选择合适的action:
|
||||||
|
|
||||||
# {action_options_text}
|
# {action_options_text}
|
||||||
|
|
||||||
# 请以动作的输出要求,以严格的 JSON 格式输出,且仅包含 JSON 内容。
|
# 请以动作的输出要求,以严格的 JSON 格式输出,且仅包含 JSON 内容。
|
||||||
# 请输出你提取的JSON,不要有任何其他文字或解释:
|
# 请输出你提取的JSON,不要有任何其他文字或解释:
|
||||||
|
|
||||||
|
# """,
|
||||||
|
# "simple_planner_prompt",
|
||||||
|
# )
|
||||||
|
|
||||||
# """,
|
|
||||||
# "simple_planner_prompt",
|
|
||||||
# )
|
|
||||||
|
|
||||||
Prompt(
|
Prompt(
|
||||||
"""
|
"""
|
||||||
{time_block}
|
{time_block}
|
||||||
|
|||||||
@@ -154,10 +154,10 @@ class Prompt(str):
|
|||||||
"""处理模板中的转义花括号,将 \{ 和 \} 替换为临时标记"""
|
"""处理模板中的转义花括号,将 \{ 和 \} 替换为临时标记"""
|
||||||
# 如果传入的是列表,将其转换为字符串
|
# 如果传入的是列表,将其转换为字符串
|
||||||
if isinstance(template, list):
|
if isinstance(template, list):
|
||||||
template = '\n'.join(str(item) for item in template)
|
template = "\n".join(str(item) for item in template)
|
||||||
elif not isinstance(template, str):
|
elif not isinstance(template, str):
|
||||||
template = str(template)
|
template = str(template)
|
||||||
|
|
||||||
return template.replace("\\{", Prompt._TEMP_LEFT_BRACE).replace("\\}", Prompt._TEMP_RIGHT_BRACE)
|
return template.replace("\\{", Prompt._TEMP_LEFT_BRACE).replace("\\}", Prompt._TEMP_RIGHT_BRACE)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ def init_prompt():
|
|||||||
Prompt(extract_keywords_prompt, "extract_keywords_prompt")
|
Prompt(extract_keywords_prompt, "extract_keywords_prompt")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Individuality:
|
class Individuality:
|
||||||
"""个体特征管理类"""
|
"""个体特征管理类"""
|
||||||
|
|
||||||
@@ -345,8 +343,6 @@ class Individuality:
|
|||||||
fetch_info_data = self._load_fetch_info_from_file()
|
fetch_info_data = self._load_fetch_info_from_file()
|
||||||
logger.info(f"加载已有数据,现有关键词数量: {len(fetch_info_data)}")
|
logger.info(f"加载已有数据,现有关键词数量: {len(fetch_info_data)}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 构建完整描述(personality + identity)
|
# 构建完整描述(personality + identity)
|
||||||
personality_sides_str = ""
|
personality_sides_str = ""
|
||||||
for personality_side in personality_sides:
|
for personality_side in personality_sides:
|
||||||
@@ -362,8 +358,7 @@ class Individuality:
|
|||||||
|
|
||||||
# 提取关键词
|
# 提取关键词
|
||||||
extract_prompt = (await global_prompt_manager.get_prompt_async("extract_keywords_prompt")).format(
|
extract_prompt = (await global_prompt_manager.get_prompt_async("extract_keywords_prompt")).format(
|
||||||
personality_sides=personality_sides_str,
|
personality_sides=personality_sides_str, bot_name=self.name
|
||||||
bot_name=self.name
|
|
||||||
)
|
)
|
||||||
|
|
||||||
llm_model = LLMRequest(
|
llm_model = LLMRequest(
|
||||||
@@ -378,18 +373,16 @@ class Individuality:
|
|||||||
logger.info("未提取到有效关键词")
|
logger.info("未提取到有效关键词")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 使用json_repair修复并解析JSON
|
# 使用json_repair修复并解析JSON
|
||||||
keyword_dict = json.loads(repair_json(keywords_result))
|
keyword_dict = json.loads(repair_json(keywords_result))
|
||||||
logger.info(f"成功解析JSON格式的关键词: {keyword_dict}")
|
logger.info(f"成功解析JSON格式的关键词: {keyword_dict}")
|
||||||
|
|
||||||
# 从字典中提取关键词列表,跳过"keywords"键
|
# 从字典中提取关键词列表,跳过"keywords"键
|
||||||
keyword_set = []
|
keyword_set = []
|
||||||
for key, value in keyword_dict.items():
|
for key, _value in keyword_dict.items():
|
||||||
if key.lower() != "keywords" and key.strip():
|
if key.lower() != "keywords" and key.strip():
|
||||||
keyword_set.append(key.strip())
|
keyword_set.append(key.strip())
|
||||||
|
|
||||||
logger.info(f"最终提取的关键词列表: {keyword_set}")
|
logger.info(f"最终提取的关键词列表: {keyword_set}")
|
||||||
logger.info(f"共提取到 {len(keyword_set)} 个关键词")
|
logger.info(f"共提取到 {len(keyword_set)} 个关键词")
|
||||||
|
|
||||||
@@ -412,7 +405,11 @@ class Individuality:
|
|||||||
|
|
||||||
# 从JSON结果中获取关键词的信息
|
# 从JSON结果中获取关键词的信息
|
||||||
existing_info_from_json = keyword_dict.get(keyword, "")
|
existing_info_from_json = keyword_dict.get(keyword, "")
|
||||||
if existing_info_from_json and existing_info_from_json.strip() and existing_info_from_json != keyword:
|
if (
|
||||||
|
existing_info_from_json
|
||||||
|
and existing_info_from_json.strip()
|
||||||
|
and existing_info_from_json != keyword
|
||||||
|
):
|
||||||
# 如果JSON中有有效信息且不只是重复关键词本身,直接使用
|
# 如果JSON中有有效信息且不只是重复关键词本身,直接使用
|
||||||
logger.info(f"从JSON结果中获取到关键词 '{keyword}' 的信息: '{existing_info_from_json}'")
|
logger.info(f"从JSON结果中获取到关键词 '{keyword}' 的信息: '{existing_info_from_json}'")
|
||||||
if existing_info_from_json not in fetch_info_data[keyword]:
|
if existing_info_from_json not in fetch_info_data[keyword]:
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ logger = get_logger("core_actions")
|
|||||||
WAITING_TIME_THRESHOLD = 1200 # 等待新消息时间阈值,单位秒
|
WAITING_TIME_THRESHOLD = 1200 # 等待新消息时间阈值,单位秒
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ReplyAction(BaseAction):
|
class ReplyAction(BaseAction):
|
||||||
"""回复动作 - 参与聊天回复"""
|
"""回复动作 - 参与聊天回复"""
|
||||||
|
|
||||||
@@ -105,7 +103,6 @@ class ReplyAction(BaseAction):
|
|||||||
return False, f"回复失败: {str(e)}"
|
return False, f"回复失败: {str(e)}"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class NoReplyAction(BaseAction):
|
class NoReplyAction(BaseAction):
|
||||||
"""不回复动作,继承时会等待新消息或超时"""
|
"""不回复动作,继承时会等待新消息或超时"""
|
||||||
|
|
||||||
@@ -124,9 +121,9 @@ class NoReplyAction(BaseAction):
|
|||||||
|
|
||||||
# 连续no_reply计数器
|
# 连续no_reply计数器
|
||||||
_consecutive_count = 0
|
_consecutive_count = 0
|
||||||
|
|
||||||
random_activation_probability = 0.2
|
random_activation_probability = 0.2
|
||||||
|
|
||||||
# 分级等待时间
|
# 分级等待时间
|
||||||
_waiting_stages = [10, 60, 600] # 第1、2、3次的等待时间
|
_waiting_stages = [10, 60, 600] # 第1、2、3次的等待时间
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user