🤖 自动格式化代码 [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.common.logger import get_logger
|
||||
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 json_repair import repair_json
|
||||
from src.chat.focus_chat.planners.base_planner import BasePlanner
|
||||
@@ -26,29 +25,29 @@ install(extra_lines=3)
|
||||
|
||||
|
||||
def init_prompt():
|
||||
# Prompt(
|
||||
# """
|
||||
# {time_block}
|
||||
# {indentify_block}你现在正在参与以下的聊天,以下是具体的聊天内容:
|
||||
# Prompt(
|
||||
# """
|
||||
# {time_block}
|
||||
# {indentify_block}你现在正在参与以下的聊天,以下是具体的聊天内容:
|
||||
|
||||
# {chat_content_block}
|
||||
# {chat_content_block}
|
||||
|
||||
# {self_info_block}
|
||||
# {relation_info_block}
|
||||
# {self_info_block}
|
||||
# {relation_info_block}
|
||||
|
||||
# {cycle_info_block}
|
||||
# {cycle_info_block}
|
||||
|
||||
# {moderation_prompt}
|
||||
# 注意,除了下面动作选项之外,你在群聊里不能做其他任何事情,这是你能力的边界,现在请你选择合适的action:
|
||||
# {moderation_prompt}
|
||||
# 注意,除了下面动作选项之外,你在群聊里不能做其他任何事情,这是你能力的边界,现在请你选择合适的action:
|
||||
|
||||
# {action_options_text}
|
||||
# {action_options_text}
|
||||
|
||||
# 请以动作的输出要求,以严格的 JSON 格式输出,且仅包含 JSON 内容。
|
||||
# 请输出你提取的JSON,不要有任何其他文字或解释:
|
||||
# 请以动作的输出要求,以严格的 JSON 格式输出,且仅包含 JSON 内容。
|
||||
# 请输出你提取的JSON,不要有任何其他文字或解释:
|
||||
|
||||
# """,
|
||||
# "simple_planner_prompt",
|
||||
# )
|
||||
# """,
|
||||
# "simple_planner_prompt",
|
||||
# )
|
||||
|
||||
Prompt(
|
||||
"""
|
||||
|
||||
@@ -154,7 +154,7 @@ class Prompt(str):
|
||||
"""处理模板中的转义花括号,将 \{ 和 \} 替换为临时标记"""
|
||||
# 如果传入的是列表,将其转换为字符串
|
||||
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):
|
||||
template = str(template)
|
||||
|
||||
|
||||
@@ -45,8 +45,6 @@ def init_prompt():
|
||||
Prompt(extract_keywords_prompt, "extract_keywords_prompt")
|
||||
|
||||
|
||||
|
||||
|
||||
class Individuality:
|
||||
"""个体特征管理类"""
|
||||
|
||||
@@ -345,8 +343,6 @@ class Individuality:
|
||||
fetch_info_data = self._load_fetch_info_from_file()
|
||||
logger.info(f"加载已有数据,现有关键词数量: {len(fetch_info_data)}")
|
||||
|
||||
|
||||
|
||||
# 构建完整描述(personality + identity)
|
||||
personality_sides_str = ""
|
||||
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(
|
||||
personality_sides=personality_sides_str,
|
||||
bot_name=self.name
|
||||
personality_sides=personality_sides_str, bot_name=self.name
|
||||
)
|
||||
|
||||
llm_model = LLMRequest(
|
||||
@@ -378,15 +373,13 @@ class Individuality:
|
||||
logger.info("未提取到有效关键词")
|
||||
return
|
||||
|
||||
|
||||
|
||||
# 使用json_repair修复并解析JSON
|
||||
keyword_dict = json.loads(repair_json(keywords_result))
|
||||
logger.info(f"成功解析JSON格式的关键词: {keyword_dict}")
|
||||
|
||||
# 从字典中提取关键词列表,跳过"keywords"键
|
||||
keyword_set = []
|
||||
for key, value in keyword_dict.items():
|
||||
for key, _value in keyword_dict.items():
|
||||
if key.lower() != "keywords" and key.strip():
|
||||
keyword_set.append(key.strip())
|
||||
|
||||
@@ -412,7 +405,11 @@ class Individuality:
|
||||
|
||||
# 从JSON结果中获取关键词的信息
|
||||
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中有有效信息且不只是重复关键词本身,直接使用
|
||||
logger.info(f"从JSON结果中获取到关键词 '{keyword}' 的信息: '{existing_info_from_json}'")
|
||||
if existing_info_from_json not in fetch_info_data[keyword]:
|
||||
|
||||
@@ -24,8 +24,6 @@ logger = get_logger("core_actions")
|
||||
WAITING_TIME_THRESHOLD = 1200 # 等待新消息时间阈值,单位秒
|
||||
|
||||
|
||||
|
||||
|
||||
class ReplyAction(BaseAction):
|
||||
"""回复动作 - 参与聊天回复"""
|
||||
|
||||
@@ -105,7 +103,6 @@ class ReplyAction(BaseAction):
|
||||
return False, f"回复失败: {str(e)}"
|
||||
|
||||
|
||||
|
||||
class NoReplyAction(BaseAction):
|
||||
"""不回复动作,继承时会等待新消息或超时"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user