From 2baba4394660b9844fe622b279ed4bb5e21621e8 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Sat, 15 Feb 2025 19:38:32 +0800 Subject: [PATCH] =?UTF-8?q?update:=E5=AE=8C=E6=88=90=E5=9C=A8web=E7=AB=AF?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=8F=90=E7=A4=BA=E8=AF=8D=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/settings.py | 22 ++++++++++++++++++---- core/connection.py | 2 +- manager/api/prompt.py | 11 ++++++++--- manager/static/css/common.css | 29 ++++++++++++++++++++++++++--- manager/static/index.html | 33 +++++++++++++++++++++++++++------ requirements.txt | 3 ++- 6 files changed, 82 insertions(+), 18 deletions(-) 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 @@