mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
调整代码
This commit is contained in:
@@ -97,6 +97,25 @@ export default {
|
||||
});
|
||||
}).send();
|
||||
},
|
||||
// 删除以下重复定义的方法
|
||||
// 保留此方法以保持向后兼容性,但内部使用分页API
|
||||
// getAgentTemplate(callback) {
|
||||
// // 内部调用分页API获取所有模板
|
||||
// this.getAgentTemplatesPage({ pageNum: 1, pageSize: 100 }, (res) => {
|
||||
// if (res && res.data && res.data.code === 0) {
|
||||
// // 转换响应格式以保持兼容性
|
||||
// const compatibleRes = {
|
||||
// data: {
|
||||
// code: 0,
|
||||
// data: res.data.data?.records || []
|
||||
// }
|
||||
// };
|
||||
// callback(compatibleRes);
|
||||
// } else {
|
||||
// callback(res);
|
||||
// }
|
||||
// });
|
||||
// },
|
||||
|
||||
// 新增:获取智能体模板分页列表
|
||||
getAgentTemplatesPage(params, callback) {
|
||||
@@ -350,4 +369,20 @@ export default {
|
||||
});
|
||||
}).send();
|
||||
},
|
||||
// 在getAgentTemplate方法后添加获取单个模板的方法
|
||||
getAgentTemplateById(templateId, callback) {
|
||||
RequestService.sendRequest()
|
||||
.url(`${getServiceUrl()}/agent/template/${templateId}`)
|
||||
.method('GET')
|
||||
.success((res) => {
|
||||
RequestService.clearRequestTime();
|
||||
callback(res);
|
||||
})
|
||||
.networkFail((err) => {
|
||||
console.error('获取单个模板失败:', err);
|
||||
RequestService.reAjaxFun(() => {
|
||||
this.getAgentTemplateById(templateId, callback);
|
||||
});
|
||||
}).send();
|
||||
},
|
||||
}
|
||||
|
||||
@@ -852,30 +852,8 @@ export default {
|
||||
'agentTemplateManagement.confirmBatchDelete': 'Are you sure you want to delete the selected {count} templates?',
|
||||
'agentTemplateManagement.deleteFailed': 'Template deletion failed',
|
||||
'agentTemplateManagement.batchDeleteFailed': 'Template batch deletion failed',
|
||||
'agentTemplateManagement.deleteBackendError': 'Deletion failed, please check if the backend service is working properly',
|
||||
|
||||
// agentTemplateManagement Dialog
|
||||
'agentTemplateManagement.templateDialog.title': 'Template Configuration',
|
||||
'agentTemplateManagement.templateDialog.templateName': 'Template Name',
|
||||
'agentTemplateManagement.templateDialog.templateNamePlaceholder': 'Please enter template name',
|
||||
'agentTemplateManagement.templateDialog.description': 'Description',
|
||||
'agentTemplateManagement.templateDialog.descriptionPlaceholder': 'Please enter description',
|
||||
'agentTemplateManagement.templateDialog.roleName': 'Role Name',
|
||||
'agentTemplateManagement.templateDialog.roleNamePlaceholder': 'Please enter role name',
|
||||
'agentTemplateManagement.templateDialog.avatar': 'Avatar',
|
||||
'agentTemplateManagement.templateDialog.selectAvatar': 'Select Avatar',
|
||||
'agentTemplateManagement.templateDialog.systemPrompt': 'System Prompt',
|
||||
'agentTemplateManagement.templateDialog.systemPromptPlaceholder': 'Please enter system prompt',
|
||||
'agentTemplateManagement.templateDialog.modelConfig': 'Model Configuration',
|
||||
'agentTemplateManagement.templateDialog.modelName': 'Model Name',
|
||||
'agentTemplateManagement.templateDialog.temperature': 'Temperature',
|
||||
'agentTemplateManagement.templateDialog.topP': 'Top P',
|
||||
'agentTemplateManagement.templateDialog.maxTokens': 'Max Tokens',
|
||||
'agentTemplateManagement.templateDialog.save': 'Save',
|
||||
'agentTemplateManagement.templateDialog.cancel': 'Cancel',
|
||||
'agentTemplateManagement.templateDialog.nameRequired': 'Please enter template name',
|
||||
'agentTemplateManagement.templateDialog.roleNameRequired': 'Please enter role name',
|
||||
'agentTemplateManagement.templateDialog.systemPromptRequired': 'Please enter system prompt',
|
||||
'agentTemplateManagement.deleteBackendError': 'Deletion failed, please check if the backend service is normal',
|
||||
'agentTemplateManagement.deleteCancelled': 'Deletion cancelled',
|
||||
|
||||
// templateQuickConfig
|
||||
'templateQuickConfig.title': 'Module Quick Configuration',
|
||||
@@ -895,7 +873,14 @@ export default {
|
||||
'templateQuickConfig.configReset': 'Configuration has been reset',
|
||||
'templateQuickConfig.confirmReset': 'Are you sure you want to reset the configuration?',
|
||||
'templateQuickConfig.success': 'Success',
|
||||
'error': 'Error',
|
||||
'templateQuickConfig.error': 'Error',
|
||||
'templateQuickConfig.configSaveFailed': 'Template configuration save failed',
|
||||
'templateQuickConfig.saveBackendError': 'Save failed, please check if the backend service is normal',
|
||||
'templateQuickConfig.confirm': 'Confirm',
|
||||
'templateQuickConfig.cancel': 'Cancel',
|
||||
'templateQuickConfig.templateNotFound': 'Template not found',
|
||||
'templateQuickConfig.fetchTemplateFailed': 'Failed to fetch template',
|
||||
'templateQuickConfig.fetchTemplateBackendError': 'Failed to fetch template, please check if the backend service is normal',
|
||||
'warning': 'Warning',
|
||||
'info': 'Info'
|
||||
}
|
||||
|
||||
@@ -853,29 +853,6 @@ export default {
|
||||
'agentTemplateManagement.batchDeleteFailed': '模板批量删除失败',
|
||||
'agentTemplateManagement.deleteBackendError': '删除失败,请检查后端服务是否正常',
|
||||
|
||||
// 默认角色模版对话框文本
|
||||
'agentTemplateManagement.templateDialog.title': '模板配置',
|
||||
'agentTemplateManagement.templateDialog.templateName': '模板名称',
|
||||
'agentTemplateManagement.templateDialog.templateNamePlaceholder': '请输入模板名称',
|
||||
'agentTemplateManagement.templateDialog.description': '模板描述',
|
||||
'agentTemplateManagement.templateDialog.descriptionPlaceholder': '请输入模板描述',
|
||||
'agentTemplateManagement.templateDialog.roleName': '角色名称',
|
||||
'agentTemplateManagement.templateDialog.roleNamePlaceholder': '请输入角色名称',
|
||||
'agentTemplateManagement.templateDialog.avatar': '头像',
|
||||
'agentTemplateManagement.templateDialog.selectAvatar': '选择头像',
|
||||
'agentTemplateManagement.templateDialog.systemPrompt': '系统提示词',
|
||||
'agentTemplateManagement.templateDialog.systemPromptPlaceholder': '请输入系统提示词',
|
||||
'agentTemplateManagement.templateDialog.modelConfig': '模型配置',
|
||||
'agentTemplateManagement.templateDialog.modelName': '模型名称',
|
||||
'agentTemplateManagement.templateDialog.temperature': '温度',
|
||||
'agentTemplateManagement.templateDialog.topP': 'Top P',
|
||||
'agentTemplateManagement.templateDialog.maxTokens': '最大 tokens',
|
||||
'agentTemplateManagement.templateDialog.save': '保存',
|
||||
'agentTemplateManagement.templateDialog.cancel': '取消',
|
||||
'agentTemplateManagement.templateDialog.nameRequired': '请输入模板名称',
|
||||
'agentTemplateManagement.templateDialog.roleNameRequired': '请输入角色名称',
|
||||
'agentTemplateManagement.templateDialog.systemPromptRequired': '请输入系统提示词',
|
||||
|
||||
// 模板快速配置页面文本
|
||||
'templateQuickConfig.title': '模块快速配置',
|
||||
'templateQuickConfig.basicSettings': '基本设置',
|
||||
@@ -889,12 +866,17 @@ export default {
|
||||
'templateQuickConfig.deviceSettings': '设备设置',
|
||||
'templateQuickConfig.pluginSettings': '插件设置',
|
||||
'templateQuickConfig.saveConfig': '保存配置',
|
||||
'templateQuickConfig.resetConfig': '重置配置',
|
||||
'templateQuickConfig.configSaved': '配置保存成功',
|
||||
'templateQuickConfig.configReset': '配置已重置',
|
||||
'templateQuickConfig.resetConfig': '配置已重置',
|
||||
'templateQuickConfig.confirmReset': '确定要重置配置吗?',
|
||||
'templateQuickConfig.success': '成功',
|
||||
'templateQuickConfig.error': '错误',
|
||||
'templateQuickConfig.configSaveFailed': '模板配置保存失败',
|
||||
'templateQuickConfig.saveBackendError': '保存失败,请检查后端服务是否正常',
|
||||
'templateQuickConfig.confirm': '确定',
|
||||
'templateQuickConfig.cancel': '取消',
|
||||
'templateQuickConfig.templateNotFound': '未找到指定模板',
|
||||
'templateQuickConfig.fetchTemplateFailed': '获取模板失败',
|
||||
'templateQuickConfig.fetchTemplateBackendError': '获取模板失败,请检查后端服务是否正常',
|
||||
'warning': '警告',
|
||||
'info': '提示'
|
||||
}
|
||||
@@ -855,31 +855,8 @@ export default {
|
||||
'agentTemplateManagement.deleteBackendError': '刪除失敗,請檢查後端服務是否正常',
|
||||
'agentTemplateManagement.deleteCancelled': '已取消刪除',
|
||||
|
||||
// 預設角色管理對話框文本
|
||||
'agentTemplateManagement.templateDialog.title': '模板配置',
|
||||
'agentTemplateManagement.templateDialog.templateName': '模板名稱',
|
||||
'agentTemplateManagement.templateDialog.templateNamePlaceholder': '請輸入模板名稱',
|
||||
'agentTemplateManagement.templateDialog.description': '模板描述',
|
||||
'agentTemplateManagement.templateDialog.descriptionPlaceholder': '請輸入模板描述',
|
||||
'agentTemplateManagement.templateDialog.roleName': '角色名稱',
|
||||
'agentTemplateManagement.templateDialog.roleNamePlaceholder': '請輸入角色名稱',
|
||||
'agentTemplateManagement.templateDialog.avatar': '頭像',
|
||||
'agentTemplateManagement.templateDialog.selectAvatar': '選擇頭像',
|
||||
'agentTemplateManagement.templateDialog.systemPrompt': '系統提示詞',
|
||||
'agentTemplateManagement.templateDialog.systemPromptPlaceholder': '請輸入系統提示詞',
|
||||
'agentTemplateManagement.templateDialog.modelConfig': '模型配置',
|
||||
'agentTemplateManagement.templateDialog.modelName': '模型名稱',
|
||||
'agentTemplateManagement.templateDialog.temperature': '溫度',
|
||||
'agentTemplateManagement.templateDialog.topP': 'Top P',
|
||||
'agentTemplateManagement.templateDialog.maxTokens': '最大 tokens',
|
||||
'agentTemplateManagement.templateDialog.save': '保存',
|
||||
'agentTemplateManagement.templateDialog.cancel': '取消',
|
||||
'agentTemplateManagement.templateDialog.nameRequired': '請輸入模板名稱',
|
||||
'agentTemplateManagement.templateDialog.roleNameRequired': '請輸入角色名稱',
|
||||
'agentTemplateManagement.templateDialog.systemPromptRequired': '請輸入系統提示詞',
|
||||
|
||||
// 模組快速配置頁面文本
|
||||
'templateQuickConfig.title': '模組快速配置',
|
||||
// 模板快速配置
|
||||
'templateQuickConfig.title': '模組快速設定',
|
||||
'templateQuickConfig.basicSettings': '基本設置',
|
||||
'templateQuickConfig.agentSettings.agentName': '助手暱稱',
|
||||
'templateQuickConfig.agentSettings.agentNamePlaceholder': '請輸入助手暱稱',
|
||||
@@ -896,6 +873,14 @@ export default {
|
||||
'templateQuickConfig.configReset': '配置已重置',
|
||||
'templateQuickConfig.confirmReset': '確定要重置配置嗎?',
|
||||
'templateQuickConfig.success': '成功',
|
||||
'templateQuickConfig.error': '錯誤',
|
||||
'templateQuickConfig.configSaveFailed': '模板配置保存失敗',
|
||||
'templateQuickConfig.saveBackendError': '保存失敗,請檢查後端服務是否正常',
|
||||
'templateQuickConfig.confirm': '確定',
|
||||
'templateQuickConfig.cancel': '取消',
|
||||
'templateQuickConfig.templateNotFound': '未找到指定模板',
|
||||
'templateQuickConfig.fetchTemplateFailed': '獲取模板失敗',
|
||||
'templateQuickConfig.fetchTemplateBackendError': '獲取模板失敗,請檢查後端服務是否正常',
|
||||
'error': '錯誤',
|
||||
'warning': '警告',
|
||||
'info': '提示'
|
||||
|
||||
@@ -30,22 +30,16 @@
|
||||
<el-checkbox v-model="scope.row.selected" @change="handleRowSelectionChange(scope.row)" @click.stop></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 修改为序号列 -->
|
||||
<el-table-column :label="$t('agentTemplateManagement.serialNumber')" min-width="120" align="center">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ (currentPage - 1) * pageSize + scope.$index + 1 }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 模板名称 -->
|
||||
<el-table-column :label="$t('agentTemplateManagement.templateName')" prop="agentName" min-width="250" show-overflow-tooltip>
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.agentName }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 语言 -->
|
||||
<el-table-column :label="$t('templateQuickConfig.agentSettings.agentName')" prop="language" min-width="100" show-overflow-tooltip>
|
||||
<!-- 修改为序号列,并移动到此处 -->
|
||||
<el-table-column :label="$t('agentTemplateManagement.serialNumber')" min-width="120" align="center">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ scope.row.language }}</span>
|
||||
<span>{{ (currentPage - 1) * pageSize + scope.$index + 1 }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 操作列 -->
|
||||
|
||||
@@ -57,210 +57,145 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Api from '@/apis/api';
|
||||
import FunctionDialog from "@/components/FunctionDialog.vue";
|
||||
import HeaderBar from "@/components/HeaderBar.vue";
|
||||
import agentApi from '@/apis/module/agent';
|
||||
|
||||
// 默认模型配置常量
|
||||
const DEFAULT_MODEL_CONFIG = {
|
||||
ttsModelId: "TTS_EdgeTTS",
|
||||
vadModelId: "VAD_SileroVAD",
|
||||
asrModelId: "ASR_FunASR",
|
||||
llmModelId: "LLM_ChatGLMLLM",
|
||||
vllmModelId: "VLLM_ChatGLMVLLM",
|
||||
memModelId: "Memory_nomem",
|
||||
intentModelId: "Intent_function_call"
|
||||
};
|
||||
|
||||
export default {
|
||||
name: 'TemplateQuickConfig',
|
||||
components: { HeaderBar, FunctionDialog },
|
||||
components: { HeaderBar },
|
||||
data() {
|
||||
return {
|
||||
form: {
|
||||
agentCode: "小智", // 设置默认值
|
||||
agentCode: "小智",
|
||||
agentName: "",
|
||||
ttsVoiceId: "TTS_EdgeTTS0001", // 添加默认值
|
||||
chatHistoryConf: 0,
|
||||
systemPrompt: "",
|
||||
summaryMemory: "",
|
||||
langCode: "zh", // 设置默认值
|
||||
language: "中文", // 设置默认值
|
||||
sort: 0, // 设置默认值
|
||||
model: {
|
||||
ttsModelId: "TTS_EdgeTTS", // 添加默认值
|
||||
vadModelId: "VAD_SileroVAD", // 设置默认值
|
||||
asrModelId: "ASR_FunASR", // 设置默认值
|
||||
llmModelId: "LLM_ChatGLMLLM", // 设置默认值
|
||||
vllmModelId: "VLLM_ChatGLMVLLM", // 设置默认值
|
||||
memModelId: "Memory_nomem", // 设置默认值
|
||||
intentModelId: "Intent_function_call", // 设置默认值
|
||||
}
|
||||
sort: 0,
|
||||
model: { ...DEFAULT_MODEL_CONFIG }
|
||||
},
|
||||
models: [
|
||||
{ label: '语音活动检测(VAD)', key: 'vadModelId', type: 'VAD' },
|
||||
{ label: '语音识别(ASR)', key: 'asrModelId', type: 'ASR' },
|
||||
{ label: '大语言模型(LLM)', key: 'llmModelId', type: 'LLM' },
|
||||
{ label: '视觉大模型(VLLM)', key: 'vllmModelId', type: 'VLLM' },
|
||||
{ label: '意图识别(Intent)', key: 'intentModelId', type: 'Intent' },
|
||||
{ label: '记忆(Memory)', key: 'memModelId', type: 'Memory' },
|
||||
{ label: '语音合成(TTS)', key: 'ttsModelId', type: 'TTS' }
|
||||
],
|
||||
llmModeTypeMap: new Map(),
|
||||
modelOptions: {},
|
||||
templateId: '',
|
||||
voiceOptions: [],
|
||||
showFunctionDialog: false,
|
||||
currentFunctions: [],
|
||||
functionColorMap: [
|
||||
'#FF6B6B', '#4ECDC4', '#45B7D1',
|
||||
'#96CEB4', '#FFEEAD', '#D4A5A5', '#A2836E'
|
||||
],
|
||||
allFunctions: [],
|
||||
originalFunctions: [],
|
||||
originalForm: null
|
||||
}
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
// 返回模板管理页面
|
||||
goToHome() {
|
||||
this.$router.push('/agent-template-management');
|
||||
},
|
||||
// 修改saveConfig方法中的响应检查逻辑
|
||||
|
||||
// 保存配置
|
||||
saveConfig() {
|
||||
const configData = {
|
||||
agentCode: this.form.agentCode,
|
||||
agentName: this.form.agentName,
|
||||
// 不需要单独提交agentDescription,使用systemPrompt字段
|
||||
asrModelId: this.form.model.asrModelId,
|
||||
vadModelId: this.form.model.vadModelId,
|
||||
llmModelId: this.form.model.llmModelId,
|
||||
vllmModelId: this.form.model.vllmModelId,
|
||||
ttsModelId: this.form.model.ttsModelId,
|
||||
ttsVoiceId: this.form.ttsVoiceId,
|
||||
chatHistoryConf: this.form.chatHistoryConf,
|
||||
memModelId: this.form.model.memModelId,
|
||||
intentModelId: this.form.model.intentModelId,
|
||||
systemPrompt: this.form.systemPrompt, // 这个字段会保存角色介绍
|
||||
summaryMemory: this.form.summaryMemory,
|
||||
langCode: this.form.langCode,
|
||||
language: this.form.language,
|
||||
sort: this.form.sort,
|
||||
functions: this.currentFunctions.map(item => {
|
||||
return ({
|
||||
pluginId: item.id,
|
||||
paramInfo: item.params
|
||||
})
|
||||
})
|
||||
};
|
||||
const configData = this.prepareConfigData();
|
||||
|
||||
// 修复saveConfig方法中的回调参数结构
|
||||
// 如果有templateId,使用更新模板API
|
||||
if (this.templateId) {
|
||||
configData.id = this.templateId;
|
||||
agentApi.updateAgentTemplate(configData, (res) => { // 修改为(res)而不是({ res })
|
||||
// 添加调试日志以便排查问题
|
||||
console.log('保存模板响应:', res);
|
||||
|
||||
if (res && typeof res === 'object') {
|
||||
// 检查res.data是否存在且包含code=0
|
||||
if (res.data && res.data.code === 0) {
|
||||
this.$message.success({
|
||||
message: '模板配置保存成功',
|
||||
showClose: true
|
||||
});
|
||||
this.originalForm = JSON.parse(JSON.stringify(this.form));
|
||||
this.originalFunctions = JSON.parse(JSON.stringify(this.currentFunctions));
|
||||
} else {
|
||||
this.$message.error({
|
||||
message: res?.data?.msg || '模板配置保存失败',
|
||||
showClose: true
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.error('无效的响应对象:', res);
|
||||
this.$message.error('保存失败,请检查后端服务是否正常');
|
||||
}
|
||||
});
|
||||
this.updateExistingTemplate(configData);
|
||||
} else {
|
||||
// 否则使用添加模板API
|
||||
agentApi.addAgentTemplate(configData, (res) => { // 修改为(res)而不是({ res })
|
||||
// 添加调试日志以便排查问题
|
||||
console.log('添加模板响应:', res);
|
||||
|
||||
if (res && typeof res === 'object') {
|
||||
// 检查res.data是否存在且包含code=0
|
||||
if (res.data && res.data.code === 0) {
|
||||
this.$message.success({
|
||||
message: '模板配置保存成功',
|
||||
showClose: true
|
||||
});
|
||||
this.goToHome();
|
||||
} else {
|
||||
this.$message.error({
|
||||
message: res?.data?.msg || '模板配置保存失败',
|
||||
showClose: true
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.error('无效的响应对象:', res);
|
||||
this.$message.error('保存失败,请检查后端服务是否正常');
|
||||
}
|
||||
});
|
||||
this.createNewTemplate(configData);
|
||||
}
|
||||
},
|
||||
|
||||
// 准备配置数据
|
||||
prepareConfigData() {
|
||||
return {
|
||||
id: this.templateId || '',
|
||||
agentCode: this.form.agentCode,
|
||||
agentName: this.form.agentName,
|
||||
systemPrompt: this.form.systemPrompt,
|
||||
sort: this.form.sort,
|
||||
functions: [],
|
||||
// 包含必要的模型字段以确保API调用成功
|
||||
...this.form.model
|
||||
};
|
||||
},
|
||||
|
||||
// 更新现有模板
|
||||
updateExistingTemplate(configData) {
|
||||
agentApi.updateAgentTemplate(configData, (res) => {
|
||||
if (res && res.data && res.data.code === 0) {
|
||||
this.$message.success({
|
||||
message: this.$t('templateQuickConfig.saveSuccess'),
|
||||
showClose: true
|
||||
});
|
||||
this.originalForm = JSON.parse(JSON.stringify(this.form));
|
||||
} else {
|
||||
this.$message.error({
|
||||
message: res?.data?.msg || this.$t('templateQuickConfig.saveFailed'),
|
||||
showClose: true
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 创建新模板
|
||||
createNewTemplate(configData) {
|
||||
agentApi.addAgentTemplate(configData, (res) => {
|
||||
if (res && res.data && res.data.code === 0) {
|
||||
this.$message.success({
|
||||
message: this.$t('templateQuickConfig.saveSuccess'),
|
||||
showClose: true
|
||||
});
|
||||
this.goToHome();
|
||||
} else {
|
||||
this.$message.error({
|
||||
message: res?.data?.msg || this.$t('templateQuickConfig.saveFailed'),
|
||||
showClose: true
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 重置配置
|
||||
resetConfig() {
|
||||
this.$confirm('确定要重置配置吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
this.$confirm(
|
||||
this.$t('templateQuickConfig.confirmReset'),
|
||||
this.$t('common.tip'),
|
||||
{
|
||||
confirmButtonText: this.$t('common.confirm'),
|
||||
cancelButtonText: this.$t('common.cancel'),
|
||||
type: 'warning'
|
||||
}
|
||||
).then(() => {
|
||||
if (this.originalForm) {
|
||||
this.form = JSON.parse(JSON.stringify(this.originalForm));
|
||||
this.currentFunctions = JSON.parse(JSON.stringify(this.originalFunctions));
|
||||
}
|
||||
this.$message.success({
|
||||
message: '配置已重置',
|
||||
showClose: true
|
||||
})
|
||||
}).catch(() => {
|
||||
});
|
||||
this.$message.success({
|
||||
message: this.$t('templateQuickConfig.resetSuccess'),
|
||||
showClose: true
|
||||
});
|
||||
}).catch(() => {});
|
||||
},
|
||||
// 修改fetchTemplateById方法中的回调参数结构
|
||||
|
||||
// 根据ID获取模板
|
||||
fetchTemplateById(templateId) {
|
||||
// 获取所有模板,然后找到指定ID的模板
|
||||
agentApi.getAgentTemplate((res) => { // 修改为(res)而不是({ data })
|
||||
// 添加调试日志以便排查问题
|
||||
console.log('获取模板列表完整响应:', res);
|
||||
|
||||
if (res && typeof res === 'object') {
|
||||
// 检查res.data是否存在且包含code=0
|
||||
if (res.data && res.data.code === 0) {
|
||||
// 实际数据在res.data.data中,而不是res.data
|
||||
const templateList = res.data.data || [];
|
||||
console.log('实际模板列表数据:', templateList);
|
||||
|
||||
const template = templateList.find(t => t.id === templateId);
|
||||
if (template) {
|
||||
this.applyTemplateData(template);
|
||||
this.templateId = templateId;
|
||||
this.originalForm = JSON.parse(JSON.stringify(this.form));
|
||||
this.originalFunctions = JSON.parse(JSON.stringify(this.currentFunctions));
|
||||
} else {
|
||||
console.error('未找到指定模板,ID:', templateId);
|
||||
this.$message.error('未找到指定模板');
|
||||
}
|
||||
} else {
|
||||
console.error('获取模板失败:', res);
|
||||
this.$message.error(res?.data?.msg || '获取模板失败');
|
||||
}
|
||||
agentApi.getAgentTemplateById(templateId, (res) => {
|
||||
if (res && res.data && res.data.code === 0 && res.data.data) {
|
||||
const template = res.data.data;
|
||||
this.applyTemplateData(template);
|
||||
this.templateId = templateId;
|
||||
this.originalForm = JSON.parse(JSON.stringify(this.form));
|
||||
} else {
|
||||
console.error('无效的响应对象:', res);
|
||||
this.$message.error('获取模板失败,请检查后端服务是否正常');
|
||||
this.$message.error(res?.data?.msg || this.$t('templateQuickConfig.templateNotFound'));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 应用模板数据
|
||||
applyTemplateData(templateData) {
|
||||
this.form = {
|
||||
...this.form,
|
||||
agentName: templateData.agentName || this.form.agentName,
|
||||
agentCode: templateData.agentCode || this.form.agentCode,
|
||||
// 删除agentDescription字段的处理
|
||||
ttsVoiceId: templateData.ttsVoiceId || this.form.ttsVoiceId,
|
||||
chatHistoryConf: templateData.chatHistoryConf || this.form.chatHistoryConf,
|
||||
systemPrompt: templateData.systemPrompt || this.form.systemPrompt,
|
||||
summaryMemory: templateData.summaryMemory || this.form.summaryMemory,
|
||||
langCode: templateData.langCode || this.form.langCode,
|
||||
language: templateData.language || this.form.language,
|
||||
sort: templateData.sort || this.form.sort,
|
||||
model: {
|
||||
ttsModelId: templateData.ttsModelId || this.form.model.ttsModelId,
|
||||
@@ -273,224 +208,54 @@ export default {
|
||||
}
|
||||
};
|
||||
},
|
||||
fetchModelOptions() {
|
||||
this.models.forEach(model => {
|
||||
if (model.type != "LLM") {
|
||||
Api.model.getModelNames(model.type, '', ({ data }) => {
|
||||
if (data.code === 0) {
|
||||
this.$set(this.modelOptions, model.type, data.data.map(item => ({
|
||||
value: item.id,
|
||||
label: item.modelName,
|
||||
isHidden: false
|
||||
})));
|
||||
|
||||
// 如果是意图识别选项,需要根据当前LLM类型更新可见性
|
||||
if (model.type === 'Intent') {
|
||||
this.updateIntentOptionsVisibility();
|
||||
}
|
||||
} else {
|
||||
this.$message.error(data.msg || '获取模型列表失败');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Api.model.getLlmModelCodeList('', ({ data }) => {
|
||||
if (data.code === 0) {
|
||||
let LLMdata = []
|
||||
data.data.forEach(item => {
|
||||
LLMdata.push({
|
||||
value: item.id,
|
||||
label: item.modelName,
|
||||
isHidden: false
|
||||
})
|
||||
this.llmModeTypeMap.set(item.id, item.type)
|
||||
})
|
||||
this.$set(this.modelOptions, model.type, LLMdata);
|
||||
} else {
|
||||
this.$message.error(data.msg || '获取LLM模型列表失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
fetchVoiceOptions(modelId) {
|
||||
if (!modelId) {
|
||||
this.voiceOptions = [];
|
||||
return;
|
||||
}
|
||||
Api.model.getModelVoices(modelId, '', ({ data }) => {
|
||||
if (data.code === 0 && data.data) {
|
||||
this.voiceOptions = data.data.map(voice => ({
|
||||
value: voice.id,
|
||||
label: voice.name
|
||||
}));
|
||||
} else {
|
||||
this.voiceOptions = [];
|
||||
}
|
||||
});
|
||||
},
|
||||
getFunctionColor(name) {
|
||||
const hash = [...name].reduce((acc, char) => acc + char.charCodeAt(0), 0);
|
||||
return this.functionColorMap[hash % this.functionColorMap.length];
|
||||
},
|
||||
showFunctionIcons(type) {
|
||||
return type === 'Intent' &&
|
||||
this.form.model.intentModelId !== 'Intent_nointent';
|
||||
},
|
||||
handleModelChange(type, value) {
|
||||
if (type === 'Intent' && value !== 'Intent_nointent') {
|
||||
this.fetchAllFunctions();
|
||||
}
|
||||
if (type === 'Memory' && value === 'Memory_nomem') {
|
||||
this.form.chatHistoryConf = 0;
|
||||
}
|
||||
if (type === 'Memory' && value !== 'Memory_nomem' && (this.form.chatHistoryConf === 0 || this.form.chatHistoryConf === null)) {
|
||||
this.form.chatHistoryConf = 2;
|
||||
}
|
||||
if (type === 'LLM') {
|
||||
// 当LLM类型改变时,更新意图识别选项的可见性
|
||||
this.updateIntentOptionsVisibility();
|
||||
}
|
||||
},
|
||||
fetchAllFunctions() {
|
||||
return new Promise((resolve, reject) => {
|
||||
Api.model.getPluginFunctionList(null, ({ data }) => {
|
||||
if (data.code === 0) {
|
||||
this.allFunctions = data.data.map(item => {
|
||||
const meta = JSON.parse(item.fields || '[]');
|
||||
const params = meta.reduce((m, f) => {
|
||||
m[f.key] = f.default;
|
||||
return m;
|
||||
}, {});
|
||||
return { ...item, fieldsMeta: meta, params };
|
||||
});
|
||||
resolve();
|
||||
} else {
|
||||
this.$message.error(data.msg || '获取插件列表失败');
|
||||
reject();
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
openFunctionDialog() {
|
||||
// 显示编辑对话框时,确保 allFunctions 已经加载
|
||||
if (this.allFunctions.length === 0) {
|
||||
this.fetchAllFunctions().then(() => this.showFunctionDialog = true);
|
||||
} else {
|
||||
this.showFunctionDialog = true;
|
||||
}
|
||||
},
|
||||
handleUpdateFunctions(selected) {
|
||||
this.currentFunctions = selected;
|
||||
},
|
||||
handleDialogClosed(saved) {
|
||||
if (!saved) {
|
||||
this.currentFunctions = JSON.parse(JSON.stringify(this.originalFunctions));
|
||||
} else {
|
||||
this.originalFunctions = JSON.parse(JSON.stringify(this.currentFunctions));
|
||||
}
|
||||
this.showFunctionDialog = false;
|
||||
},
|
||||
updateIntentOptionsVisibility() {
|
||||
// 根据当前选择的LLM类型更新意图识别选项的可见性
|
||||
const currentLlmId = this.form.model.llmModelId;
|
||||
if (!currentLlmId || !this.modelOptions['Intent']) return;
|
||||
|
||||
const llmType = this.llmModeTypeMap.get(currentLlmId);
|
||||
if (!llmType) return;
|
||||
|
||||
this.modelOptions['Intent'].forEach(item => {
|
||||
if (item.value === "Intent_function_call") {
|
||||
// 如果llmType是openai或ollama,允许选择function_call
|
||||
// 否则隐藏function_call选项
|
||||
if (llmType === "openai" || llmType === "ollama") {
|
||||
item.isHidden = false;
|
||||
} else {
|
||||
item.isHidden = true;
|
||||
}
|
||||
} else {
|
||||
// 其他意图识别选项始终可见
|
||||
item.isHidden = false;
|
||||
}
|
||||
});
|
||||
|
||||
// 如果当前选择的意图识别是function_call,但LLM类型不支持,则设置为可选的第一项
|
||||
if (this.form.model.intentModelId === "Intent_function_call" &&
|
||||
llmType !== "openai" && llmType !== "ollama") {
|
||||
// 找到第一个可见的选项
|
||||
const firstVisibleOption = this.modelOptions['Intent'].find(item => !item.isHidden);
|
||||
if (firstVisibleOption) {
|
||||
this.form.model.intentModelId = firstVisibleOption.value;
|
||||
} else {
|
||||
// 如果没有可见选项,设置为Intent_nointent
|
||||
this.form.model.intentModelId = 'Intent_nointent';
|
||||
}
|
||||
}
|
||||
},
|
||||
updateChatHistoryConf() {
|
||||
if (this.form.model.memModelId === 'Memory_nomem') {
|
||||
this.form.chatHistoryConf = 0;
|
||||
}
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
'form.model.ttsModelId': {
|
||||
handler(newVal, oldVal) {
|
||||
if (oldVal && newVal !== oldVal) {
|
||||
this.form.ttsVoiceId = '';
|
||||
this.fetchVoiceOptions(newVal);
|
||||
} else {
|
||||
this.fetchVoiceOptions(newVal);
|
||||
}
|
||||
},
|
||||
immediate: true
|
||||
},
|
||||
voiceOptions: {
|
||||
handler(newVal) {
|
||||
if (newVal && newVal.length > 0 && !this.form.ttsVoiceId) {
|
||||
this.form.ttsVoiceId = newVal[0].value;
|
||||
}
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// 从URL参数获取templateId
|
||||
const templateId = this.$route.query.templateId;
|
||||
this.fetchModelOptions();
|
||||
this.fetchAllFunctions();
|
||||
|
||||
if (templateId) {
|
||||
this.fetchTemplateById(templateId);
|
||||
} else {
|
||||
// 如果没有templateId,初始化一个新的模板
|
||||
this.form.agentName = '新模板';
|
||||
// 设置默认模板值
|
||||
setDefaultTemplateValues() {
|
||||
this.form = {
|
||||
...this.form,
|
||||
agentName: this.$t('templateQuickConfig.newTemplate'),
|
||||
agentCode: '小智',
|
||||
systemPrompt: '',
|
||||
sort: 1
|
||||
};
|
||||
|
||||
// 获取所有模板以计算最大的sort值
|
||||
this.originalForm = JSON.parse(JSON.stringify(this.form));
|
||||
},
|
||||
|
||||
// 获取模板列表并设置排序号
|
||||
fetchTemplateListForSort() {
|
||||
agentApi.getAgentTemplate((res) => {
|
||||
if (res && typeof res === 'object' && res.data && res.data.code === 0) {
|
||||
if (res && res.data && res.data.code === 0) {
|
||||
const templateList = res.data.data || [];
|
||||
if (templateList && templateList.length > 0) {
|
||||
// 计算最大的sort值
|
||||
if (templateList.length > 0) {
|
||||
const maxSort = Math.max(...templateList.map(t => t.sort || 0));
|
||||
// 设置新模板的sort值为最大值+1
|
||||
this.form.sort = maxSort + 1;
|
||||
} else {
|
||||
// 如果没有模板,设置默认值为1
|
||||
this.form.sort = 1;
|
||||
}
|
||||
} else {
|
||||
console.error('获取模板列表失败,使用默认sort值');
|
||||
// 获取失败时使用默认值
|
||||
this.form.sort = 1;
|
||||
}
|
||||
|
||||
// 保存初始状态
|
||||
this.originalForm = JSON.parse(JSON.stringify(this.form));
|
||||
this.originalFunctions = JSON.parse(JSON.stringify(this.currentFunctions));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 组件挂载时执行初始化
|
||||
mounted() {
|
||||
const templateId = this.$route.query.templateId;
|
||||
|
||||
if (templateId) {
|
||||
// 编辑模式:加载现有模板
|
||||
this.fetchTemplateById(templateId);
|
||||
} else {
|
||||
// 新建模式:设置默认值并获取排序号
|
||||
this.form.agentName = this.$t('templateQuickConfig.newTemplate');
|
||||
this.fetchTemplateListForSort();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -521,15 +286,15 @@ export default {
|
||||
}
|
||||
|
||||
.main-wrapper {
|
||||
margin: 1vh 22px; /* 借鉴角色配置页面,使用1vh的上下边距,使上下边框更加均衡 */
|
||||
margin: 1vh 22px;
|
||||
border-radius: 15px;
|
||||
height: calc(100vh - 24vh); /* 借鉴角色配置页面的高度计算方式 */
|
||||
height: calc(100vh - 24vh);
|
||||
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
|
||||
position: relative;
|
||||
background: rgba(237, 242, 255, 0.5);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 0 !important; /* 确保没有内边距 */
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
.content-panel {
|
||||
@@ -539,7 +304,7 @@ export default {
|
||||
height: 100%;
|
||||
border-radius: 15px;
|
||||
background: transparent;
|
||||
border: 1px solid #fff; /* 借鉴角色配置页面,添加白色边框 */
|
||||
border: 1px solid #fff;
|
||||
}
|
||||
|
||||
.content-area {
|
||||
@@ -551,7 +316,6 @@ export default {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* 调整config-card样式 */
|
||||
.config-card {
|
||||
background: white !important;
|
||||
border-radius: 15px !important;
|
||||
@@ -562,7 +326,6 @@ export default {
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
/* 修复表单容器样式 */
|
||||
.full-height-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -571,43 +334,38 @@ export default {
|
||||
height: calc(100% - 120px);
|
||||
}
|
||||
|
||||
/* 助手昵称样式 */
|
||||
.nickname-item {
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
/* 修复角色介绍项目样式 */
|
||||
.description-item {
|
||||
margin-bottom: 0 !important;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* 修复Element UI的textarea容器样式 */
|
||||
::v-deep .description-item .el-textarea {
|
||||
height: 300px; /* 设置固定高度 */
|
||||
min-height: 200px; /* 最小高度 */
|
||||
max-height: 400px; /* 最大高度,防止超出页面 */
|
||||
height: 300px;
|
||||
min-height: 200px;
|
||||
max-height: 400px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* 修复textarea样式 */
|
||||
::v-deep .description-item .el-textarea__inner {
|
||||
height: 100% !important;
|
||||
min-height: 200px !important;
|
||||
max-height: 400px !important;
|
||||
resize: vertical !important; /* 允许垂直调整大小 */
|
||||
resize: vertical !important;
|
||||
line-height: 1.6;
|
||||
font-size: 14px;
|
||||
padding: 10px;
|
||||
border: 1px solid #dcdfe6; /* 添加边框使其更清晰可见 */
|
||||
border-radius: 4px; /* 添加圆角 */
|
||||
background-color: #fff; /* 确保背景色为白色 */
|
||||
color: #303133; /* 确保文字颜色正常 */
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 4px;
|
||||
background-color: #fff;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
/* 其他样式保持不变 */
|
||||
::v-deep .el-form-item__label {
|
||||
font-size: 12px !important;
|
||||
color: #3d4566 !important;
|
||||
@@ -627,9 +385,7 @@ export default {
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
/* 配置头部样式调整 */
|
||||
.config-header {
|
||||
|
||||
padding: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -638,7 +394,6 @@ export default {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* 使用角色配置页面相同的彩色图标样式 */
|
||||
.header-icon {
|
||||
width: 37px;
|
||||
height: 37px;
|
||||
@@ -660,7 +415,6 @@ export default {
|
||||
color: #2c3e50;
|
||||
}
|
||||
|
||||
/* 其他按钮和操作区样式保持不变 */
|
||||
.custom-close-btn {
|
||||
position: absolute;
|
||||
top: 25%;
|
||||
@@ -695,20 +449,6 @@ export default {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.header-actions .hint-text {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
color: #979db1;
|
||||
font-size: 12px;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.header-actions .hint-text img {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
.header-actions .save-btn {
|
||||
background: #5778ff;
|
||||
color: white;
|
||||
@@ -735,9 +475,4 @@ export default {
|
||||
height: 32px;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
/* 隐藏所有不需要的元素 */
|
||||
.model-select-wrapper, .model-row, .function-icons, .icon-dot, .edit-function-btn, .chat-history-options {
|
||||
display: none !important;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user