From 089a3ad0c98e5332c96fcd0bb9d1db12414344ab Mon Sep 17 00:00:00 2001 From: JOJO <1498581755@qq.com> Date: Sat, 22 Nov 2025 18:17:24 +0800 Subject: [PATCH] feat: update prompts and backend --- core/main_terminal.py | 16 ++++++++++++++ modules/user_manager.py | 2 ++ prompts/main_system.txt | 4 +++- prompts/personalization.txt | 2 ++ prompts/thinking_mode_guidelines.txt | 1 + web_server.py | 31 ++++++++++++++++++++++++++++ 6 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 prompts/personalization.txt diff --git a/core/main_terminal.py b/core/main_terminal.py index 7a3aef4..4ac2cbf 100644 --- a/core/main_terminal.py +++ b/core/main_terminal.py @@ -42,6 +42,10 @@ from modules.sub_agent_manager import SubAgentManager from modules.webpage_extractor import extract_webpage_content, tavily_extract from modules.ocr_client import OCRClient from modules.easter_egg_manager import EasterEggManager +from modules.personalization_manager import ( + load_personalization_config, + build_personalization_prompt, +) from core.tool_config import TOOL_CATEGORIES from utils.api_client import DeepSeekClient from utils.context_manager import ContextManager @@ -2164,6 +2168,18 @@ class MainTerminal: thinking_prompt = self.load_prompt("thinking_mode_guidelines").strip() if thinking_prompt: messages.append({"role": "system", "content": thinking_prompt}) + + personalization_config = load_personalization_config(self.data_dir) + personalization_block = build_personalization_prompt(personalization_config, include_header=False) + if personalization_block: + personalization_template = self.load_prompt("personalization").strip() + if personalization_template and "{personalization_block}" in personalization_template: + personalization_text = personalization_template.format(personalization_block=personalization_block) + elif personalization_template: + personalization_text = f"{personalization_template}\n{personalization_block}" + else: + personalization_text = personalization_block + messages.append({"role": "system", "content": personalization_text}) # 添加对话历史(保留完整结构,包括tool_calls和tool消息) conversation = context["conversation"] diff --git a/modules/user_manager.py b/modules/user_manager.py index 5d1ee0a..e8a6a32 100644 --- a/modules/user_manager.py +++ b/modules/user_manager.py @@ -16,6 +16,7 @@ from config import ( USER_SPACE_DIR, USERS_DB_FILE, ) +from modules.personalization_manager import ensure_personalization_config @dataclass @@ -128,6 +129,7 @@ class UserManager: # 初始化数据子目录 (data_dir / "conversations").mkdir(parents=True, exist_ok=True) (data_dir / "backups").mkdir(parents=True, exist_ok=True) + ensure_personalization_config(data_dir) return UserWorkspace( username=username, diff --git a/prompts/main_system.txt b/prompts/main_system.txt index 0e61923..857072a 100644 --- a/prompts/main_system.txt +++ b/prompts/main_system.txt @@ -256,4 +256,6 @@ tree -L 2 4. **用户友好**:用简单的语言解释复杂的操作 5. **正确执行**:和用户主动确认细节,用户明确告知可以开始任务后,再开始工作流程 -记住:你的用户可能不懂技术,你的目标是让他们感觉到"这个助手真好用",而不是"怎么这么复杂"。 \ No newline at end of file +记住:你的用户可能不懂技术,你的目标是让他们感觉到"这个助手真好用",而不是"怎么这么复杂"。 + +如果用户设置了个性化信息,根据用户的个性化需求回答 \ No newline at end of file diff --git a/prompts/personalization.txt b/prompts/personalization.txt new file mode 100644 index 0000000..3d85592 --- /dev/null +++ b/prompts/personalization.txt @@ -0,0 +1,2 @@ +以下内容为用户提供的个性化设置信息,请务必在整个任务过程中遵循: +{personalization_block} diff --git a/prompts/thinking_mode_guidelines.txt b/prompts/thinking_mode_guidelines.txt index 94c5964..c4ee62e 100644 --- a/prompts/thinking_mode_guidelines.txt +++ b/prompts/thinking_mode_guidelines.txt @@ -13,6 +13,7 @@ * 是否需要创建/修改/删除文件、运行终端命令或脚本? * 是否需要创建/等待/关闭子智能体? * 是否需要更新主记忆或任务记忆? + * 如果用户开启了个性化模式,要考虑哪些用户要求的必须考虑的点? 2. **正式输出阶段** - 直接向用户说明你的计划:描述每一步准备做什么、需要哪些工具或文件。 diff --git a/web_server.py b/web_server.py index be27e2e..b11981e 100644 --- a/web_server.py +++ b/web_server.py @@ -46,6 +46,10 @@ from config import ( ) from modules.user_manager import UserManager, UserWorkspace from modules.gui_file_manager import GuiFileManager +from modules.personalization_manager import ( + load_personalization_config, + save_personalization_config, +) app = Flask(__name__, static_folder='static') app.config['MAX_CONTENT_LENGTH'] = MAX_UPLOAD_SIZE @@ -649,6 +653,33 @@ def update_thinking_mode(terminal: WebTerminal, workspace: UserWorkspace, userna "message": "切换思考模式时发生异常" }), 500 + +@app.route('/api/personalization', methods=['GET']) +@api_login_required +@with_terminal +def get_personalization_settings(terminal: WebTerminal, workspace: UserWorkspace, username: str): + """获取个性化配置""" + try: + data = load_personalization_config(workspace.data_dir) + return jsonify({"success": True, "data": data}) + except Exception as exc: + return jsonify({"success": False, "error": str(exc)}), 500 + + +@app.route('/api/personalization', methods=['POST']) +@api_login_required +@with_terminal +def update_personalization_settings(terminal: WebTerminal, workspace: UserWorkspace, username: str): + """更新个性化配置""" + payload = request.get_json() or {} + try: + config = save_personalization_config(workspace.data_dir, payload) + return jsonify({"success": True, "data": config}) + except ValueError as exc: + return jsonify({"success": False, "error": str(exc)}), 400 + except Exception as exc: + return jsonify({"success": False, "error": str(exc)}), 500 + @app.route('/api/files') @api_login_required @with_terminal