mofox-plugin-dev-toolkit 0.3.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. mofox_plugin_dev_toolkit-0.3.3.dist-info/METADATA +730 -0
  2. mofox_plugin_dev_toolkit-0.3.3.dist-info/RECORD +46 -0
  3. mofox_plugin_dev_toolkit-0.3.3.dist-info/WHEEL +5 -0
  4. mofox_plugin_dev_toolkit-0.3.3.dist-info/entry_points.txt +2 -0
  5. mofox_plugin_dev_toolkit-0.3.3.dist-info/licenses/LICENSE +674 -0
  6. mofox_plugin_dev_toolkit-0.3.3.dist-info/top_level.txt +1 -0
  7. mpdt/__init__.py +15 -0
  8. mpdt/__main__.py +8 -0
  9. mpdt/cli.py +316 -0
  10. mpdt/commands/__init__.py +9 -0
  11. mpdt/commands/check.py +498 -0
  12. mpdt/commands/dev.py +318 -0
  13. mpdt/commands/generate.py +448 -0
  14. mpdt/commands/init.py +686 -0
  15. mpdt/dev/bridge_plugin/__init__.py +17 -0
  16. mpdt/dev/bridge_plugin/cleanup_handler.py +65 -0
  17. mpdt/dev/bridge_plugin/dev_config.py +24 -0
  18. mpdt/dev/bridge_plugin/file_watcher.py +169 -0
  19. mpdt/dev/bridge_plugin/plugin.py +219 -0
  20. mpdt/templates/__init__.py +165 -0
  21. mpdt/templates/action_template.py +102 -0
  22. mpdt/templates/adapter_template.py +129 -0
  23. mpdt/templates/chatter_template.py +103 -0
  24. mpdt/templates/event_template.py +116 -0
  25. mpdt/templates/plus_command_template.py +150 -0
  26. mpdt/templates/prompt_template.py +92 -0
  27. mpdt/templates/router_template.py +175 -0
  28. mpdt/templates/tool_template.py +98 -0
  29. mpdt/utils/__init__.py +10 -0
  30. mpdt/utils/code_parser.py +401 -0
  31. mpdt/utils/color_printer.py +99 -0
  32. mpdt/utils/config_loader.py +171 -0
  33. mpdt/utils/config_manager.py +297 -0
  34. mpdt/utils/file_ops.py +207 -0
  35. mpdt/utils/license_generator.py +980 -0
  36. mpdt/utils/plugin_parser.py +195 -0
  37. mpdt/utils/template_engine.py +112 -0
  38. mpdt/validators/__init__.py +26 -0
  39. mpdt/validators/auto_fix_validator.py +990 -0
  40. mpdt/validators/base.py +129 -0
  41. mpdt/validators/component_validator.py +842 -0
  42. mpdt/validators/config_validator.py +119 -0
  43. mpdt/validators/metadata_validator.py +107 -0
  44. mpdt/validators/structure_validator.py +72 -0
  45. mpdt/validators/style_validator.py +117 -0
  46. mpdt/validators/type_validator.py +206 -0
@@ -0,0 +1,102 @@
1
+ """
2
+ Action 组件模板
3
+ """
4
+
5
+ ACTION_TEMPLATE = '''"""
6
+ {description}
7
+
8
+ Created by: {author}
9
+ Created at: {date}
10
+ """
11
+
12
+ from src.common.logger import get_logger
13
+ from src.plugin_system import BaseAction, ActionActivationType, ChatMode
14
+
15
+ logger = get_logger(__name__)
16
+
17
+
18
+ class {class_name}(BaseAction):
19
+ """
20
+ {description}
21
+
22
+ Action 组件用于执行聊天中的具体动作任务。
23
+ """
24
+
25
+ # Action 元数据
26
+ action_name: str = "{component_name}"
27
+ action_description: str = "{description}"
28
+
29
+ # 激活配置
30
+ mode_enable: list[ChatMode] = [ChatMode.FOCUS, ChatMode.NORMAL] # 支持的聊天模式
31
+ parallel_action: bool = False # 是否允许与其他 Action 并行执行
32
+
33
+ # 专注模式激活配置
34
+ focus_activation_type: ActionActivationType = ActionActivationType.KEYWORD
35
+ # 普通模式激活配置
36
+ normal_activation_type: ActionActivationType = ActionActivationType.LLM_JUDGE
37
+
38
+ # 激活条件
39
+ activation_keywords: list[str] = ["关键词1", "关键词2"] # 关键词激活时使用
40
+ keyword_case_sensitive: bool = False # 关键词是否区分大小写
41
+
42
+ # LLM 判断激活的提示词
43
+ llm_judge_prompt: str = """
44
+ 判断用户是否需要执行某个特定操作。
45
+ 如果需要,返回 true,否则返回 false。
46
+ """
47
+
48
+ async def go_activate(self, llm_judge_model=None) -> bool:
49
+ """
50
+ 自定义激活逻辑(推荐方式)
51
+
52
+ 可以组合使用以下工具函数:
53
+ - await self._keyword_match(["关键词"]) # 关键词匹配
54
+ - await self._random_activation(0.3) # 随机激活(30%概率)
55
+ - await self._llm_judge_activation(prompt, llm_judge_model) # LLM判断
56
+
57
+ Returns:
58
+ 是否激活此 Action
59
+ """
60
+ # 示例:关键词匹配
61
+ return await self._keyword_match(self.activation_keywords, self.keyword_case_sensitive)
62
+
63
+ async def execute(self) -> tuple[bool, str]:
64
+ """
65
+ 执行 Action 的主要逻辑
66
+
67
+ 可以使用以下方法:
68
+ - await self.send_text("文本内容") # 发送文本消息
69
+ - await self.send_image(image_base64) # 发送图片
70
+ - await self.send_command("command_name", args) # 调用命令
71
+ - await self.call_action("action_name", data) # 调用其他 Action
72
+ - await self.wait_for_new_message(timeout) # 等待用户回复
73
+
74
+ Returns:
75
+ (是否成功, 结果消息)
76
+ """
77
+ try:
78
+ logger.info(f"执行 Action: {{self.action_name}}")
79
+
80
+ # TODO: 实现 Action 的核心逻辑
81
+
82
+ # 示例:发送消息
83
+ await self.send_text("Action 执行成功!")
84
+
85
+ # 存储 Action 信息到上下文
86
+ await self.store_action_info(
87
+ action_build_into_prompt=True,
88
+ action_prompt_display=f"执行了 {{self.action_name}}",
89
+ action_done=True
90
+ )
91
+
92
+ return True, "执行成功"
93
+
94
+ except Exception as e:
95
+ logger.error(f"Action 执行失败: {{e}}")
96
+ return False, f"执行失败: {{e}}"
97
+ '''
98
+
99
+
100
+ def get_action_template() -> str:
101
+ """获取 Action 组件模板"""
102
+ return ACTION_TEMPLATE
@@ -0,0 +1,129 @@
1
+ """
2
+ Adapter 组件模板
3
+ """
4
+
5
+ ADAPTER_TEMPLATE = '''"""
6
+ {description}
7
+
8
+ Created by: {author}
9
+ Created at: {date}
10
+ """
11
+
12
+ from typing import Any
13
+
14
+ from mofox_wire import MessageEnvelope
15
+ from src.common.logger import get_logger
16
+ from src.plugin_system import BaseAdapter
17
+
18
+ logger = get_logger(__name__)
19
+
20
+
21
+ class {class_name}(BaseAdapter):
22
+ """
23
+ {description}
24
+
25
+ Adapter 组件用于连接不同的平台或服务。
26
+
27
+ 支持的场景:
28
+ - QQ/微信等聊天平台
29
+ - Discord/Telegram 等国际平台
30
+ - 自定义 API 服务
31
+ - WebSocket/HTTP 协议适配
32
+ """
33
+
34
+ # Adapter 元数据
35
+ adapter_name: str = "{adapter_name}"
36
+ adapter_version: str = "1.0.0"
37
+ adapter_author: str = "{author}"
38
+ adapter_description: str = "{description}"
39
+
40
+ # 是否在子进程中运行
41
+ run_in_subprocess: bool = False
42
+ # 子进程启动脚本路径(相对于插件目录)
43
+ subprocess_entry: str | None = None
44
+
45
+ async def from_platform_message(self, raw: Any) -> MessageEnvelope:
46
+ """
47
+ 将平台原始消息转换为标准 MessageEnvelope 格式
48
+
49
+ Args:
50
+ raw: 平台原始消息对象
51
+
52
+ Returns:
53
+ MessageEnvelope: 标准消息信封
54
+ """
55
+ try:
56
+ logger.debug(f"转换平台消息: {{raw}}")
57
+
58
+ # TODO: 解析平台消息并转换为 MessageEnvelope
59
+ # 示例:
60
+ # message_id = raw.get("message_id")
61
+ # user_id = raw.get("user_id")
62
+ # content = raw.get("content")
63
+ # timestamp = raw.get("timestamp")
64
+ #
65
+ # return MessageEnvelope(
66
+ # message_id=message_id,
67
+ # user_id=user_id,
68
+ # content=content,
69
+ # timestamp=timestamp,
70
+ # platform="your_platform"
71
+ # )
72
+
73
+ raise NotImplementedError("需要实现 from_platform_message 方法")
74
+
75
+ except Exception as e:
76
+ logger.error(f"转换消息失败: {{e}}")
77
+ raise
78
+
79
+ async def _send_platform_message(self, envelope: MessageEnvelope) -> None:
80
+ """
81
+ 发送消息到平台
82
+
83
+ Args:
84
+ envelope: 要发送的消息信封
85
+ """
86
+ try:
87
+ logger.info(f"发送消息: {{envelope.message_id}}")
88
+
89
+ # TODO: 实现发送消息逻辑
90
+ # 将 MessageEnvelope 转换为平台格式并发送
91
+ # 示例:
92
+ # platform_message = {{
93
+ # "target_id": envelope.target_id,
94
+ # "content": envelope.content,
95
+ # "message_type": envelope.message_type
96
+ # }}
97
+ # await self.platform_api.send(platform_message)
98
+
99
+ raise NotImplementedError("需要实现 _send_platform_message 方法")
100
+
101
+ except Exception as e:
102
+ logger.error(f"发送消息失败: {{e}}")
103
+ raise
104
+
105
+ async def on_adapter_loaded(self) -> None:
106
+ """
107
+ 适配器加载时的钩子
108
+ 可以在这里执行初始化逻辑
109
+ """
110
+ logger.info(f"{{self.adapter_name}} 适配器加载完成")
111
+
112
+ # TODO: 初始化逻辑
113
+ # 例如:建立连接、加载配置、启动后台任务等
114
+
115
+ async def on_adapter_unloaded(self) -> None:
116
+ """
117
+ 适配器卸载时的钩子
118
+ 可以在这里执行清理逻辑
119
+ """
120
+ logger.info(f"{{self.adapter_name}} 适配器卸载")
121
+
122
+ # TODO: 清理逻辑
123
+ # 例如:关闭连接、保存状态、停止后台任务等
124
+ '''
125
+
126
+
127
+ def get_adapter_template() -> str:
128
+ """获取 Adapter 组件模板"""
129
+ return ADAPTER_TEMPLATE
@@ -0,0 +1,103 @@
1
+ """
2
+ Chatter 组件模板
3
+ """
4
+
5
+ CHATTER_TEMPLATE = '''"""
6
+ {description}
7
+
8
+ Created by: {author}
9
+ Created at: {date}
10
+ """
11
+
12
+ from src.common.data_models.message_manager_data_model import StreamContext
13
+ from src.common.logger import get_logger
14
+ from src.plugin_system import BaseChatter, ChatType
15
+
16
+ logger = get_logger(__name__)
17
+
18
+
19
+ class {class_name}(BaseChatter):
20
+ """
21
+ {description}
22
+
23
+ Chatter 组件用于处理聊天流程,控制对话的整体逻辑。
24
+
25
+ 使用场景:
26
+ - 自定义对话流程
27
+ - 特殊聊天模式处理
28
+ - 对话状态管理
29
+ - 多轮对话控制
30
+ """
31
+
32
+ # Chatter 元数据
33
+ chatter_name: str = "{chatter_name}"
34
+ chatter_description: str = "{description}"
35
+ chat_types: list[ChatType] = [ChatType.PRIVATE, ChatType.GROUP] # 支持的聊天类型
36
+
37
+ async def execute(self, context: StreamContext) -> dict:
38
+ """
39
+ 执行聊天处理逻辑
40
+
41
+ Args:
42
+ context: StreamContext对象,包含聊天上下文信息
43
+ - context.stream_id: 聊天流ID
44
+ - context.user_id: 用户ID
45
+ - context.user_name: 用户名
46
+ - context.message_content: 消息内容
47
+ - context.chat_type: 聊天类型
48
+ - 等等...
49
+
50
+ Returns:
51
+ 处理结果字典,包含:
52
+ - success: 是否成功
53
+ - response: 响应内容(可选)
54
+ - next_action: 下一步动作(可选)
55
+ """
56
+ try:
57
+ logger.info(f"执行 Chatter: {{self.chatter_name}}")
58
+ logger.debug(f"聊天上下文: {{context}}")
59
+
60
+ # TODO: 实现聊天处理逻辑
61
+
62
+ # 示例:根据消息内容处理
63
+ message = context.message_content
64
+ user_name = context.user_name
65
+
66
+ # 可以使用 action_manager 调用 Action
67
+ # result = await self.action_manager.execute_action("action_name", {{}})
68
+
69
+ # 构建响应
70
+ response = self._generate_response(message, user_name)
71
+
72
+ return {{
73
+ "success": True,
74
+ "response": response,
75
+ "next_action": None
76
+ }}
77
+
78
+ except Exception as e:
79
+ logger.error(f"Chatter 执行失败: {{e}}")
80
+ return {{
81
+ "success": False,
82
+ "error": str(e)
83
+ }}
84
+
85
+ def _generate_response(self, message: str, user_name: str) -> str:
86
+ """
87
+ 生成响应内容
88
+
89
+ Args:
90
+ message: 用户消息
91
+ user_name: 用户名
92
+
93
+ Returns:
94
+ 响应文本
95
+ """
96
+ # TODO: 实现响应生成逻辑
97
+ return f"收到 {{user_name}} 的消息: {{message}}"
98
+ '''
99
+
100
+
101
+ def get_chatter_template() -> str:
102
+ """获取 Chatter 组件模板"""
103
+ return CHATTER_TEMPLATE
@@ -0,0 +1,116 @@
1
+ """
2
+ Event Handler 组件模板
3
+ """
4
+
5
+ EVENT_HANDLER_TEMPLATE = '''"""
6
+ {description}
7
+
8
+ Created by: {author}
9
+ Created at: {date}
10
+ """
11
+
12
+ from src.common.logger import get_logger
13
+ from src.plugin_system import BaseEventHandler, HandlerResult
14
+
15
+ logger = get_logger(__name__)
16
+
17
+
18
+ class {class_name}(BaseEventHandler):
19
+ """
20
+ {description}
21
+
22
+ Event Handler 组件用于处理系统事件。
23
+
24
+ 处理的事件类型: {event_type}
25
+
26
+ 使用场景:
27
+ - 监听消息事件
28
+ - 监听系统事件
29
+ - 实现事件驱动逻辑
30
+ - 在特定事件发生时执行操作
31
+ """
32
+
33
+ # Event Handler 元数据
34
+ handler_name: str = "{class_name}"
35
+ event_types: list[str] = ["{event_type}"] # 监听的事件类型列表
36
+ weight: int = 100 # 权重:0-1000,数字越大优先级越高
37
+
38
+ async def execute(self, params: dict) -> HandlerResult:
39
+ """
40
+ 处理事件
41
+
42
+ Args:
43
+ params: 事件参数字典,包含事件相关的所有信息
44
+
45
+ Returns:
46
+ HandlerResult: 处理结果
47
+ - success: 是否成功
48
+ - continue_process: 是否继续处理后续 handler
49
+ - message: 返回消息
50
+ """
51
+ try:
52
+ logger.info(f"处理事件: {{self.handler_name}}")
53
+ logger.debug(f"事件参数: {{params}}")
54
+
55
+ # 检查是否应该处理此事件
56
+ if not self._should_handle(params):
57
+ logger.debug("跳过此事件")
58
+ return HandlerResult(
59
+ success=True,
60
+ continue_process=True,
61
+ message="已跳过",
62
+ handler_name=self.handler_name
63
+ )
64
+
65
+ # TODO: 实现事件处理逻辑
66
+ result = await self._process_event(params)
67
+
68
+ logger.info("事件处理完成")
69
+ return HandlerResult(
70
+ success=True,
71
+ continue_process=True, # 设为 False 可以阻止后续 handler 执行
72
+ message=result,
73
+ handler_name=self.handler_name
74
+ )
75
+
76
+ except Exception as e:
77
+ logger.error(f"事件处理失败: {{e}}")
78
+ return HandlerResult(
79
+ success=False,
80
+ continue_process=True,
81
+ message=str(e),
82
+ handler_name=self.handler_name
83
+ )
84
+
85
+ def _should_handle(self, params: dict) -> bool:
86
+ """
87
+ 判断是否应该处理该事件
88
+
89
+ Args:
90
+ params: 事件参数
91
+
92
+ Returns:
93
+ 是否处理
94
+ """
95
+ # TODO: 实现判断逻辑
96
+ # 示例: 检查事件类型、来源、条件等
97
+ return True
98
+
99
+ async def _process_event(self, params: dict) -> str:
100
+ """
101
+ 处理事件的具体逻辑
102
+
103
+ Args:
104
+ params: 事件参数
105
+
106
+ Returns:
107
+ 处理结果消息
108
+ """
109
+ # TODO: 实现具体的事件处理逻辑
110
+ return "处理成功"
111
+ '''
112
+
113
+
114
+ def get_event_handler_template() -> str:
115
+ """获取 Event Handler 组件模板"""
116
+ return EVENT_HANDLER_TEMPLATE
@@ -0,0 +1,150 @@
1
+ """
2
+ PlusCommand 组件模板
3
+ """
4
+
5
+ PLUS_COMMAND_TEMPLATE = '''"""
6
+ {description}
7
+
8
+ Created by: {author}
9
+ Created at: {date}
10
+ """
11
+
12
+ from src.common.logger import get_logger
13
+ from src.plugin_system import BasePlusCommand
14
+
15
+ logger = get_logger(__name__)
16
+
17
+
18
+ class {class_name}(BasePlusCommand):
19
+ """
20
+ {description}
21
+
22
+ PlusCommand 是增强型命令,支持:
23
+ - 复杂的参数解析
24
+ - 子命令系统
25
+ - 权限检查
26
+ - 更丰富的交互方式
27
+ """
28
+
29
+ # PlusCommand 元数据
30
+ command_name: str = "{command_name}"
31
+ command_description: str = "{description}"
32
+ command_aliases: list[str] = [] # 命令别名
33
+ usage: str = "{command_name} [子命令] [选项]"
34
+
35
+ async def execute(self, **kwargs) -> tuple[bool, str]:
36
+ """
37
+ 执行命令
38
+
39
+ 可以访问的参数:
40
+ - self.stream_context: 聊天流上下文
41
+ - self.raw_text: 原始命令文本
42
+ - self.command_args: 解析后的命令参数
43
+
44
+ Returns:
45
+ (是否成功, 结果消息)
46
+ """
47
+ try:
48
+ logger.info(f"执行 PlusCommand: {{self.command_name}}")
49
+
50
+ # 获取命令参数
51
+ args = self.command_args if hasattr(self, "command_args") else []
52
+
53
+ if not args:
54
+ return True, self._help_message()
55
+
56
+ subcommand = args[0]
57
+ subcommand_args = args[1:] if len(args) > 1 else []
58
+
59
+ # 执行子命令
60
+ if subcommand == "list":
61
+ return await self._list_command(subcommand_args)
62
+ elif subcommand == "add":
63
+ return await self._add_command(subcommand_args)
64
+ elif subcommand == "remove":
65
+ return await self._remove_command(subcommand_args)
66
+ elif subcommand == "help":
67
+ return True, self._help_message()
68
+ else:
69
+ return False, f"未知子命令: {{subcommand}}\\n{{self._help_message()}}"
70
+
71
+ except Exception as e:
72
+ logger.error(f"命令执行失败: {{e}}")
73
+ return False, f"执行失败: {{e}}"
74
+
75
+ async def _list_command(self, args: list[str]) -> tuple[bool, str]:
76
+ """
77
+ 列表子命令
78
+
79
+ Args:
80
+ args: 参数列表
81
+
82
+ Returns:
83
+ (是否成功, 结果消息)
84
+ """
85
+ # TODO: 实现列表功能
86
+ return True, "列表功能"
87
+
88
+ async def _add_command(self, args: list[str]) -> tuple[bool, str]:
89
+ """
90
+ 添加子命令
91
+
92
+ Args:
93
+ args: 参数列表
94
+
95
+ Returns:
96
+ (是否成功, 结果消息)
97
+ """
98
+ if not args:
99
+ return False, f"用法: {{self.command_name}} add <项目>"
100
+
101
+ item = " ".join(args)
102
+ # TODO: 实现添加功能
103
+ return True, f"已添加: {{item}}"
104
+
105
+ async def _remove_command(self, args: list[str]) -> tuple[bool, str]:
106
+ """
107
+ 删除子命令
108
+
109
+ Args:
110
+ args: 参数列表
111
+
112
+ Returns:
113
+ (是否成功, 结果消息)
114
+ """
115
+ if not args:
116
+ return False, f"用法: {{self.command_name}} remove <项目>"
117
+
118
+ item = " ".join(args)
119
+ # TODO: 实现删除功能
120
+ return True, f"已删除: {{item}}"
121
+
122
+ def _help_message(self) -> str:
123
+ """
124
+ 生成帮助信息
125
+
126
+ Returns:
127
+ 帮助信息文本
128
+ """
129
+ return f"""
130
+ 命令: {{self.command_name}}
131
+ 描述: {{self.command_description}}
132
+ 用法: {{self.usage}}
133
+
134
+ 子命令:
135
+ list 列出所有项目
136
+ add 添加新项目
137
+ remove 删除项目
138
+ help 显示此帮助信息
139
+
140
+ 示例:
141
+ {{self.command_name}} list
142
+ {{self.command_name}} add item1
143
+ {{self.command_name}} remove item1
144
+ """
145
+ '''
146
+
147
+
148
+ def get_plus_command_template() -> str:
149
+ """获取 PlusCommand 组件模板"""
150
+ return PLUS_COMMAND_TEMPLATE
@@ -0,0 +1,92 @@
1
+ """
2
+ Prompt 组件模板
3
+ """
4
+
5
+ PROMPT_TEMPLATE = '''"""
6
+ {description}
7
+
8
+ Created by: {author}
9
+ Created at: {date}
10
+ """
11
+
12
+ from src.chat.utils.prompt_params import PromptParameters
13
+ from src.common.logger import get_logger
14
+ from src.plugin_system.base.component_types import InjectionRule
15
+ logger = get_logger(__name__)
16
+
17
+
18
+ class {class_name}(BasePrompt):
19
+ """
20
+ {description}
21
+
22
+ Prompt 组件用于向核心 Prompt 模板注入额外的上下文信息。
23
+
24
+ 使用场景:
25
+ - 向系统提示词添加自定义指令
26
+ - 注入动态上下文信息
27
+ - 添加角色设定或行为规则
28
+ - 提供额外的背景知识
29
+ """
30
+
31
+ # Prompt 组件元数据
32
+ prompt_name: str = "{prompt_name}"
33
+ prompt_description: str = "{description}"
34
+
35
+ # 定义注入规则:指定要注入到哪个核心 Prompt,以什么方式注入
36
+ injection_rules = [
37
+ InjectionRule(
38
+ target_prompt="planner_prompt", # 目标 Prompt 名称
39
+ injection_type=InjectionType.APPEND, # 注入方式:APPEND(追加) 或 PREPEND(前置)
40
+ priority=50 # 优先级:0-100,数字越大优先级越高
41
+ )
42
+ ]
43
+
44
+ async def execute(self) -> str:
45
+ """
46
+ 生成要注入的 Prompt 内容
47
+
48
+ 可以访问 self.params 来获取上下文信息:
49
+ - self.params.user_id: 用户ID
50
+ - self.params.user_name: 用户名
51
+ - self.params.bot_name: 机器人名称
52
+ - self.params.recent_messages: 最近的消息列表
53
+ - self.params.chat_type: 聊天类型(私聊/群聊)
54
+ - 等等...
55
+
56
+ Returns:
57
+ 要注入的文本内容
58
+ """
59
+ try:
60
+ logger.info(f"生成 Prompt: {{self.prompt_name}}")
61
+
62
+ # TODO: 根据 self.params 构建要注入的内容
63
+ # 示例:根据用户信息生成个性化提示词
64
+ user_name = self.params.user_name or "用户"
65
+
66
+ prompt_content = f"""
67
+ # 特殊指令
68
+
69
+ 你正在与 {{user_name}} 对话。
70
+
71
+ ## 行为规则
72
+ - 保持友好和专业的态度
73
+ - 准确理解用户意图
74
+ - 提供有价值的回答
75
+
76
+ ## 额外能力
77
+ - 你可以执行特定的操作
78
+ - 你有访问某些数据的权限
79
+ """
80
+
81
+ logger.debug(f"生成的内容: {{prompt_content[:100]}}...")
82
+ return prompt_content.strip()
83
+
84
+ except Exception as e:
85
+ logger.error(f"生成 Prompt 失败: {{e}}")
86
+ return ""
87
+ '''
88
+
89
+
90
+ def get_prompt_template() -> str:
91
+ """获取 Prompt 组件模板"""
92
+ return PROMPT_TEMPLATE