mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 17:43:55 +08:00
update:完成在web端,修改提示词功能
This commit is contained in:
+18
-4
@@ -1,15 +1,29 @@
|
|||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
|
from ruamel.yaml import YAML
|
||||||
from core.utils.util import read_config, get_project_dir
|
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():
|
def load_config():
|
||||||
"""加载配置文件"""
|
"""加载配置文件"""
|
||||||
parser = argparse.ArgumentParser(description="Server configuration")
|
parser = argparse.ArgumentParser(description="Server configuration")
|
||||||
default_config_file = "config.yaml"
|
default_config_file = get_config_file()
|
||||||
# 判断是否存在私有的配置文件
|
|
||||||
if os.path.exists(get_project_dir() + "." + default_config_file):
|
|
||||||
default_config_file = "." + default_config_file
|
|
||||||
parser.add_argument("--config_path", type=str, default=default_config_file)
|
parser.add_argument("--config_path", type=str, default=default_config_file)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
return read_config(args.config_path)
|
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)
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ from core.handle.textHandle import handleTextMessage
|
|||||||
from core.utils.util import get_string_no_punctuation_or_emoji
|
from core.utils.util import get_string_no_punctuation_or_emoji
|
||||||
from concurrent.futures import ThreadPoolExecutor, TimeoutError
|
from concurrent.futures import ThreadPoolExecutor, TimeoutError
|
||||||
from core.handle.audioHandle import handleAudioMessage, sendAudioMessage
|
from core.handle.audioHandle import handleAudioMessage, sendAudioMessage
|
||||||
from .auth import AuthMiddleware, AuthenticationError
|
from core.auth import AuthMiddleware, AuthenticationError
|
||||||
|
|
||||||
|
|
||||||
class ConnectionHandler:
|
class ConnectionHandler:
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from aiohttp import web
|
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.auth import verify_token
|
||||||
from manager.api.response import response_unauthorized, response_success, response_error
|
from manager.api.response import response_unauthorized, response_success, response_error
|
||||||
|
|
||||||
@@ -28,10 +30,13 @@ class PromptApi:
|
|||||||
if 'prompt' not in data:
|
if 'prompt' not in data:
|
||||||
return response_success()
|
return response_success()
|
||||||
|
|
||||||
self.config['prompt'] = data['prompt']
|
# 使用PreservedScalarString保留多行文本格式
|
||||||
# TODO 保存到配置文件
|
self.config['prompt'] = PreservedScalarString(data['prompt'])
|
||||||
return response_success()
|
|
||||||
|
|
||||||
|
# 保存到配置文件
|
||||||
|
update_config(self.config)
|
||||||
|
|
||||||
|
return response_success()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to update prompt: {e}")
|
logger.error(f"Failed to update prompt: {e}")
|
||||||
return response_error(str(e))
|
return response_error(str(e))
|
||||||
|
|||||||
@@ -60,7 +60,30 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@keyframes gradient {
|
@keyframes gradient {
|
||||||
0% { background-position: 0% 50% }
|
0% {
|
||||||
50% { background-position: 100% 50% }
|
background-position: 0% 50%
|
||||||
100% { 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;
|
||||||
}
|
}
|
||||||
@@ -51,15 +51,26 @@
|
|||||||
<div class="animated-bg"></div>
|
<div class="animated-bg"></div>
|
||||||
<app-header>xiaozhi-esp32-server</app-header>
|
<app-header>xiaozhi-esp32-server</app-header>
|
||||||
|
|
||||||
<div class="content-container">
|
<div class="user-menu">
|
||||||
<div class="role-title">配置角色:</div>
|
<el-dropdown @command="handleCommand">
|
||||||
<div class="role-id">cc:ba:97:11:a6:ac</div>
|
<div class="user-info">
|
||||||
|
<el-avatar :size="32" src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"/>
|
||||||
|
<span class="user-name">管理员</span>
|
||||||
|
</div>
|
||||||
|
<template #dropdown>
|
||||||
|
<el-dropdown-menu>
|
||||||
|
<el-dropdown-item command="logout">退出</el-dropdown-item>
|
||||||
|
</el-dropdown-menu>
|
||||||
|
</template>
|
||||||
|
</el-dropdown>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="content-container">
|
||||||
<div class="role-description">角色介绍</div>
|
<div class="role-description">角色介绍</div>
|
||||||
<el-input
|
<el-input
|
||||||
type="textarea"
|
type="textarea"
|
||||||
v-model="form.prompt"
|
v-model="form.prompt"
|
||||||
:rows="6"
|
:rows="10"
|
||||||
resize="vertical"
|
resize="vertical"
|
||||||
@input="updateCharCount"
|
@input="updateCharCount"
|
||||||
></el-input>
|
></el-input>
|
||||||
@@ -67,7 +78,7 @@
|
|||||||
|
|
||||||
<div class="button-group">
|
<div class="button-group">
|
||||||
<el-button type="primary" @click="savePrompt">保存配置</el-button>
|
<el-button type="primary" @click="savePrompt">保存配置</el-button>
|
||||||
<el-button @click="resetPrompt">重置</el-button>
|
<el-button @click="loadPrompt">重置</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="note">注意:保存配置后,需要重启设备,新的配置才会生效。</div>
|
<div class="note">注意:保存配置后,需要重启设备,新的配置才会生效。</div>
|
||||||
@@ -121,7 +132,17 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
|
// 新增退出处理方法
|
||||||
|
handleCommand(command) {
|
||||||
|
if (command === 'logout') {
|
||||||
|
this.handleLogout();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleLogout() {
|
||||||
|
localStorage.removeItem('token');
|
||||||
|
location.href = 'login.html';
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.loadPrompt();
|
this.loadPrompt();
|
||||||
|
|||||||
@@ -12,3 +12,4 @@ google-generativeai==0.8.4
|
|||||||
edge_tts==7.0.0
|
edge_tts==7.0.0
|
||||||
httpx==0.27.2
|
httpx==0.27.2
|
||||||
aiohttp==3.9.3
|
aiohttp==3.9.3
|
||||||
|
ruamel.yaml==0.18.10
|
||||||
Reference in New Issue
Block a user