diff --git a/config/settings.py b/config/settings.py index 9bdab1fe..d1f5a984 100644 --- a/config/settings.py +++ b/config/settings.py @@ -1,15 +1,29 @@ import os import argparse +from ruamel.yaml import YAML from core.utils.util import read_config, get_project_dir +def get_config_file(): + default_config_file = "config.yaml" + # 判断是否存在私有的配置文件 + if os.path.exists(get_project_dir() + "." + default_config_file): + default_config_file = "." + default_config_file + return default_config_file + + def load_config(): """加载配置文件""" parser = argparse.ArgumentParser(description="Server configuration") - default_config_file = "config.yaml" - # 判断是否存在私有的配置文件 - if os.path.exists(get_project_dir() + "." + default_config_file): - default_config_file = "." + default_config_file + default_config_file = get_config_file() parser.add_argument("--config_path", type=str, default=default_config_file) args = parser.parse_args() return read_config(args.config_path) + + +def update_config(config): + yaml = YAML() + yaml.preserve_quotes = True + """将配置保存到YAML文件""" + with open(get_config_file(), 'w') as f: + yaml.dump(config, f) diff --git a/core/connection.py b/core/connection.py index c1cbe4b8..972e9ae5 100644 --- a/core/connection.py +++ b/core/connection.py @@ -15,7 +15,7 @@ from core.handle.textHandle import handleTextMessage from core.utils.util import get_string_no_punctuation_or_emoji from concurrent.futures import ThreadPoolExecutor, TimeoutError from core.handle.audioHandle import handleAudioMessage, sendAudioMessage -from .auth import AuthMiddleware, AuthenticationError +from core.auth import AuthMiddleware, AuthenticationError class ConnectionHandler: diff --git a/manager/api/prompt.py b/manager/api/prompt.py index a9ce8238..1fe5aa08 100644 --- a/manager/api/prompt.py +++ b/manager/api/prompt.py @@ -1,5 +1,7 @@ import logging from aiohttp import web +from config.settings import update_config +from ruamel.yaml.scalarstring import PreservedScalarString from manager.api.auth import verify_token from manager.api.response import response_unauthorized, response_success, response_error @@ -28,10 +30,13 @@ class PromptApi: if 'prompt' not in data: return response_success() - self.config['prompt'] = data['prompt'] - # TODO 保存到配置文件 - return response_success() + # 使用PreservedScalarString保留多行文本格式 + self.config['prompt'] = PreservedScalarString(data['prompt']) + # 保存到配置文件 + update_config(self.config) + + return response_success() except Exception as e: logger.error(f"Failed to update prompt: {e}") return response_error(str(e)) diff --git a/manager/static/css/common.css b/manager/static/css/common.css index ac0a6498..145ef688 100644 --- a/manager/static/css/common.css +++ b/manager/static/css/common.css @@ -60,7 +60,30 @@ body { } @keyframes gradient { - 0% { background-position: 0% 50% } - 50% { background-position: 100% 50% } - 100% { background-position: 0% 50% } + 0% { + background-position: 0% 50% + } + 50% { + background-position: 100% 50% + } + 100% { + background-position: 0% 50% + } +} + +.user-menu { + position: fixed; + top: 23px; + right: 32px; + z-index: 1000; + cursor: pointer; +} + +.user-info { + align-items: center; +} + +.user-name { + font-size: 14px; + color: #606266; } \ No newline at end of file diff --git a/manager/static/index.html b/manager/static/index.html index 8da76c5f..2e087027 100644 --- a/manager/static/index.html +++ b/manager/static/index.html @@ -51,15 +51,26 @@