Files
xiaozhi-esp32-server/main/manager-web/src/views/roleConfig.vue
T

321 lines
10 KiB
Vue
Raw Normal View History

2025-03-14 23:48:59 +08:00
<template>
<div class="welcome">
<!-- 公共头部 -->
<HeaderBar/>
2025-03-21 01:39:23 +08:00
<!-- 面包屑-->
<div class="breadcrumbs" style="padding: 20px;">
<el-breadcrumb separator="/">
<el-breadcrumb-item>控制台</el-breadcrumb-item>
<el-breadcrumb-item><router-link to="/home">智能体</router-link></el-breadcrumb-item>
<el-breadcrumb-item>配置智能体</el-breadcrumb-item>
</el-breadcrumb>
</div>
<el-main style="padding: 16px;display: flex;flex-direction: column;align-items: center;">
<div style="border-radius: 16px;background: #fafcfe; border: 1px solid #e8f0ff;max-width: 800px;">
2025-03-14 23:48:59 +08:00
<div
2025-03-18 21:49:57 +08:00
style="padding: 15px 24px;font-weight: 700;font-size: 19px;text-align: left;color: #3d4566;display: flex;gap: 13px;align-items: center;">
2025-03-14 23:48:59 +08:00
<div
2025-03-18 21:49:57 +08:00
style="width: 37px;height: 37px;background: #5778ff;border-radius: 50%;display: flex;align-items: center;justify-content: center;">
<img src="@/assets/home/setting-user.png" alt="" style="width: 19px;height: 19px;"/>
2025-03-14 23:48:59 +08:00
</div>
2025-03-27 14:06:40 +08:00
{{ form.agentName }} ({{ agentId }})
2025-03-14 23:48:59 +08:00
</div>
<div style="height: 1px;background: #e8f0ff;"/>
2025-03-21 01:39:23 +08:00
<div style="padding: 16px 24px;max-width: 792px;">
<el-form ref="form" :model="form" label-width="100px">
2025-03-14 23:48:59 +08:00
<el-form-item label="角色模版:">
2025-03-21 01:39:23 +08:00
<div style="display: flex;gap: 8px;flex-wrap: wrap;">
2025-03-27 14:06:40 +08:00
<div v-for="template in templates" :key="template.id" class="template-item" @click="selectTemplate(template)">
{{ template.agentName }}
2025-03-14 23:48:59 +08:00
</div>
</div>
</el-form-item>
2025-03-21 01:39:23 +08:00
<el-form-item label="助手昵称:">
2025-03-27 14:06:40 +08:00
<el-input v-model="form.agentCode"/>
2025-03-21 01:39:23 +08:00
</el-form-item>
2025-03-14 23:48:59 +08:00
<el-form-item label="角色音色:">
2025-03-18 21:49:57 +08:00
<div style="display: flex;gap: 8px;align-items: center;">
2025-03-21 01:39:23 +08:00
<div style="flex:1;">
2025-03-27 14:06:40 +08:00
<el-select v-model="form.ttsVoiceId" placeholder="请选择" style="width: 100%;">
2025-03-27 22:14:52 +08:00
<el-option v-for="item in ttsVoices" :key="item.id" :label="item.name"
:value="item.id">
2025-03-14 23:48:59 +08:00
</el-option>
</el-select>
</div>
<div class="audio-box">
<audio src="http://music.163.com/song/media/outer/url?id=447925558.mp3" controls
style="height: 100%;width: 100%;"/>
</div>
</div>
</el-form-item>
<el-form-item label="角色介绍:">
2025-03-27 14:06:40 +08:00
<el-input type="textarea" rows="5" resize="none" placeholder="请输入内容" v-model="form.systemPrompt" maxlength="2000" show-word-limit/>
2025-03-14 23:48:59 +08:00
</el-form-item>
<el-form-item label="记忆体:">
2025-03-27 14:06:40 +08:00
<el-input type="textarea" rows="5" resize="none" placeholder="请输入内容" v-model="form.systemPrompt" maxlength="1000" show-word-limit/>
2025-03-21 01:39:23 +08:00
<div style="display: flex;gap: 8px;align-items: center;">
<div style="color: #979db1;font-size: 11px;">当前记忆每次对话后重新生成</div>
<div class="clear-btn">
<i class="el-icon-delete-solid" style="font-size: 11px;"/>
清除
2025-03-14 23:48:59 +08:00
</div>
</div>
</el-form-item>
2025-03-21 01:39:23 +08:00
<el-form-item v-for="model in models" :key="model.label" :label="model.label">
<template slot="label">
<div style="line-height: 20px;">{{model.label}}</div>
</template>
2025-03-27 22:14:52 +08:00
<el-select v-model="form[model.key+'ModelId']" filterable placeholder="请选择" style="width: 100%;" disabled>
<el-option v-for="item in model.list" :key="item.id" :label="item.modelName" :value="item.id"/>
2025-03-18 23:08:13 +08:00
</el-select>
2025-03-18 21:49:57 +08:00
</el-form-item>
<el-form-item label="" class="lh-form-item" style="margin-top: -25px;">
2025-03-14 23:48:59 +08:00
<div style="color: #979db1;text-align: left;">除了Qwen
实时”,其他模型通常会增加约1秒的延迟改变模型后建议清空记忆体以免影响体验
</div>
</el-form-item>
</el-form>
2025-03-21 01:39:23 +08:00
</div>
2025-03-18 21:49:57 +08:00
<div style="display: flex;padding: 16px;gap: 8px;align-items: center;">
2025-03-14 23:48:59 +08:00
<div class="save-btn" @click="saveConfig">
保存配置
</div>
<div class="reset-btn" @click="resetConfig">
重制
</div>
<div class="clear-text">
2025-03-18 21:49:57 +08:00
<img src="@/assets/home/red-info.png" alt="" style="width: 19px;height: 19px;"/>
2025-03-14 23:48:59 +08:00
保存配置后需要重启设备新的配置才会生效
</div>
</div>
</div>
</el-main>
2025-03-21 01:39:23 +08:00
<Footer :visible="true" />
2025-03-14 23:48:59 +08:00
</div>
</template>
<script>
2025-03-27 14:06:40 +08:00
import Api from '@/apis/api';
2025-03-14 23:48:59 +08:00
import HeaderBar from "@/components/HeaderBar.vue";
2025-03-21 01:39:23 +08:00
import Footer from "@/components/Footer.vue";
2025-03-27 22:14:52 +08:00
import {getUUID, goToPage, showDanger, showSuccess} from '@/utils'
2025-03-14 23:48:59 +08:00
export default {
name: 'RoleConfigPage',
2025-03-21 01:39:23 +08:00
components: {HeaderBar,Footer},
2025-03-14 23:48:59 +08:00
data() {
return {
2025-03-21 01:39:23 +08:00
agentId: this.$route.query.agentId,
2025-03-14 23:48:59 +08:00
form: {
2025-03-27 14:06:40 +08:00
agentCode:"",
agentName:"",
asrModelId:"",
intentModelId:"",
llmModelId:"",
2025-03-27 22:14:52 +08:00
memoryModelId:"",
2025-03-27 14:06:40 +08:00
systemPrompt:"",
ttsModelId:"",
ttsVoiceId:"",
vadModelId:"",
model:{}
2025-03-14 23:48:59 +08:00
},
2025-03-27 22:14:52 +08:00
ttsVoices: [],
2025-03-18 23:08:13 +08:00
models: [
2025-03-27 22:14:52 +08:00
{ label: '大语言模型(LLM)', key: 'llm', list: [] },
{ label: '语音转文本模型(ASR)', key: 'asr', list: [] },
{ label: '语音活动检测模型(VAD)', key: 'vad', list: [] },
{ label: '语音生成模型(TTS)', key: 'tts', list: [] },
{ label: '意图分类模型(Intent)', key: 'intent', list: [] },
{ label: '记忆增强模型(Memory)', key: 'memory', list: [] }
2025-03-24 09:26:45 +08:00
],
2025-03-27 22:14:52 +08:00
templates: []
2025-03-14 23:48:59 +08:00
}
},
2025-03-27 14:06:40 +08:00
mounted() {
// 获取智能体列表
this.fetchAgentTemplateList();
this.handleGetConfig();
2025-03-27 22:14:52 +08:00
this.fetchModelList();
this.getTtsVoicelList();
2025-03-27 14:06:40 +08:00
},
2025-03-14 23:48:59 +08:00
methods: {
2025-03-27 14:06:40 +08:00
fetchAgentTemplateList() {
// 获取智能体列表
Api.agent.getAgentTemplateList(({data}) => {
if (data.code === 0) {
this.templates = data.data
} else {
showDanger(data.msg)
}
})
},
2025-03-27 22:14:52 +08:00
fetchModelList() {
// 获取模型配置列表
Api.model.getModelList(({data}) => {
if (data.code === 0) {
let models = data.data;
this.models.map(model => {
model.list = models.filter(item => item.modelType.toLowerCase() === model.key)
})
console.log("models", this.models)
} else {
showDanger(data.msg)
}
})
},
getTtsVoicelList(ttsModelId) {
// 获取智能体列表
Api.model.getTtsVoiceList(ttsModelId || '',({data}) => {
if (data.code === 0) {
this.ttsVoices = data.data
} else {
showDanger(data.msg)
}
})
},
2025-03-21 01:39:23 +08:00
handleGetConfig(){
2025-03-27 14:06:40 +08:00
Api.agent.getAgentConfig(this.agentId, ({data}) => {
if (data.code === 0) {
this.form = data.data
} else {
showDanger(data.msg)
}
2025-03-21 01:39:23 +08:00
})
},
2025-03-14 23:48:59 +08:00
saveConfig() {
// 此处写保存配置逻辑
2025-03-27 22:14:52 +08:00
Api.agent.saveAgentConfig(this.agentId, this.form, ({data}) => {
if (data.code === 0) {
showSuccess('保存成功')
} else {
showDanger(data.msg)
}
})
2025-03-14 23:48:59 +08:00
},
resetConfig() {
this.$confirm('确定要重置配置吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// 重置表单
this.form = {
name: "",
timbre: "",
introduction: "",
prompt: "",
model: ""
}
this.$message.success('配置已重置')
}).catch(() => {
})
2025-03-18 23:08:13 +08:00
},
// 处理选择模板的逻辑
selectTemplate(template) {
2025-03-27 22:14:52 +08:00
Object.assign(this.form,{
agentCode: template.agentCode,
llmModelId: template.llmModelId,
asrModelId: template.asrModelId,
vadModelId: template.vadModelId,
ttsModelId: template.ttsModelId,
ttsVoiceId: template.ttsVoiceId,
intentModelId: template.intentModelId,
memoryModelId: template.memoryModelId,
systemPrompt: template.systemPrompt
})
this.$message.success(`已选择模板:${template.agentName}`);
2025-03-14 23:48:59 +08:00
}
}
}
</script>
<style scoped>
2025-03-21 01:39:23 +08:00
.breadcrumbs{
padding: 20px 0 0 5px;
}
2025-03-14 23:48:59 +08:00
.welcome {
2025-03-18 21:49:57 +08:00
min-width: 900px;
min-height: 506px;
2025-03-14 23:48:59 +08:00
height: 100vh;
2025-03-18 21:49:57 +08:00
display: flex;
flex-direction: column;
2025-03-14 23:48:59 +08:00
background-image: url("@/assets/home/background.png");
background-size: cover;
/* 确保背景图像覆盖整个元素 */
background-position: center;
/* 从顶部中心对齐 */
-webkit-background-size: cover;
/* 兼容老版本WebKit浏览器 */
-o-background-size: cover;
/* 兼容老版本Opera浏览器 */
}
2025-03-18 21:49:57 +08:00
2025-03-14 23:48:59 +08:00
.audio-box {
flex: 1;
2025-03-18 21:49:57 +08:00
height: 37px;
border-radius: 20px;
2025-03-14 23:48:59 +08:00
border: 1px solid #e4e6ef;
}
.clear-btn {
2025-03-18 21:49:57 +08:00
width: 48px;
height: 19px;
2025-03-14 23:48:59 +08:00
background: #fd8383;
2025-03-18 21:49:57 +08:00
border-radius: 10px;
line-height: 19px;
font-size: 11px;
2025-03-14 23:48:59 +08:00
color: #fff;
cursor: pointer;
}
.clear-text {
color: #979db1;
2025-03-18 21:49:57 +08:00
font-size: 11px;
2025-03-14 23:48:59 +08:00
display: flex;
align-items: center;
2025-03-18 21:49:57 +08:00
gap: 8px;
margin-left: 16px;
2025-03-14 23:48:59 +08:00
}
.template-item {
2025-03-21 01:39:23 +08:00
padding: 0 20px;
border-radius: 6px;
2025-03-14 23:48:59 +08:00
background: #e6ebff;
2025-03-21 01:39:23 +08:00
font-weight: 500;
font-size: 14px;
2025-03-14 23:48:59 +08:00
text-align: center;
color: #5778ff;
2025-03-18 23:08:13 +08:00
cursor: pointer;
transition: background-color 0.3s ease;
}
.template-item:hover {
background-color: #d0d8ff;
2025-03-14 23:48:59 +08:00
}
.save-btn,
.reset-btn {
2025-03-18 21:49:57 +08:00
width: 112px;
height: 37px;
border-radius: 18px;
line-height: 37px;
2025-03-14 23:48:59 +08:00
box-sizing: border-box;
cursor: pointer;
2025-03-18 21:49:57 +08:00
font-size: 11px
2025-03-14 23:48:59 +08:00
}
.save-btn {
2025-03-18 21:49:57 +08:00
border-radius: 18px;
2025-03-14 23:48:59 +08:00
background: #5778ff;
color: #fff;
}
.reset-btn {
border: 1px solid #adbdff;
background: #e6ebff;
color: #5778ff;
}
2025-03-18 21:49:57 +08:00
</style>