update:聊天记录上报模式和记忆模式绑定

This commit is contained in:
hrz
2025-05-12 15:49:44 +08:00
parent fd1c4ec792
commit 4a0bdbf779
4 changed files with 67 additions and 50 deletions
@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import xiaozhi.common.constant.Constant;
import xiaozhi.common.page.PageData; import xiaozhi.common.page.PageData;
import xiaozhi.common.redis.RedisKeys; import xiaozhi.common.redis.RedisKeys;
import xiaozhi.common.redis.RedisUtils; import xiaozhi.common.redis.RedisUtils;
@@ -46,7 +47,14 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
@Override @Override
public AgentEntity getAgentById(String id) { public AgentEntity getAgentById(String id) {
return agentDao.selectById(id); AgentEntity agent = agentDao.selectById(id);
if (agent != null && agent.getMemModelId() != null && agent.getMemModelId().equals("Memory_nomem")) {
agent.setChatHistoryConf(Constant.ChatHistoryConfEnum.IGNORE.getCode());
} else if (agent != null && agent.getMemModelId() != null && !agent.getMemModelId().equals("Memory_nomem")
&& agent.getChatHistoryConf() == null) {
agent.setChatHistoryConf(Constant.ChatHistoryConfEnum.RECORD_TEXT_AUDIO.getCode());
}
return agent;
} }
@Override @Override
@@ -1,6 +1,6 @@
-- 添加聊天记录配置字段 -- 添加聊天记录配置字段
ALTER TABLE `ai_agent` ALTER TABLE `ai_agent`
ADD COLUMN `chat_history_conf` tinyint NOT NULL DEFAULT 2 COMMENT '聊天记录配置(0不记录 1仅记录文本 2记录文本和语音)' AFTER `system_prompt`; ADD COLUMN `chat_history_conf` tinyint NOT NULL DEFAULT 0 COMMENT '聊天记录配置(0不记录 1仅记录文本 2记录文本和语音)' AFTER `system_prompt`;
ALTER TABLE `ai_agent_template` ALTER TABLE `ai_agent_template`
ADD COLUMN `chat_history_conf` tinyint NOT NULL DEFAULT 2 COMMENT '聊天记录配置(0不记录 1仅记录文本 2记录文本和语音)' AFTER `system_prompt`; ADD COLUMN `chat_history_conf` tinyint NOT NULL DEFAULT 0 COMMENT '聊天记录配置(0不记录 1仅记录文本 2记录文本和语音)' AFTER `system_prompt`;
@@ -115,9 +115,9 @@ databaseChangeLog:
encoding: utf8 encoding: utf8
path: classpath:db/changelog/202505091409.sql path: classpath:db/changelog/202505091409.sql
- changeSet: - changeSet:
id: 202505111913 id: 202505111914
author: hrz author: hrz
changes: changes:
- sqlFile: - sqlFile:
encoding: utf8 encoding: utf8
path: classpath:db/changelog/202505111913.sql path: classpath:db/changelog/202505111914.sql
+54 -45
View File
@@ -61,29 +61,40 @@
<el-form-item v-for="(model, index) in models" :key="`model-${index}`" :label="model.label" <el-form-item v-for="(model, index) in models" :key="`model-${index}`" :label="model.label"
class="model-item"> class="model-item">
<div class="model-select-wrapper"> <div class="model-select-wrapper">
<el-select v-model="form.model[model.key]" filterable placeholder="请选择" class="form-select" @change="handleModelChange(model.type, $event)"> <el-select v-model="form.model[model.key]" filterable placeholder="请选择" class="form-select"
<el-option v-for="(item, optionIndex) in modelOptions[model.type]" :key="`option-${index}-${optionIndex}`" :label="item.label" :value="item.value"/> @change="handleModelChange(model.type, $event)">
<el-option v-for="(item, optionIndex) in modelOptions[model.type]"
:key="`option-${index}-${optionIndex}`" :label="item.label" :value="item.value" />
</el-select> </el-select>
<div v-if="showFunctionIcons(model.type)" class="function-icons"> <div v-if="showFunctionIcons(model.type)" class="function-icons">
<el-tooltip v-for="func in currentFunctions" :key="func.name" effect="dark" placement="top" popper-class="custom-tooltip"> <el-tooltip v-for="func in currentFunctions" :key="func.name" effect="dark" placement="top"
<div slot="content"> popper-class="custom-tooltip">
<div><strong>功能名称:</strong> {{ func.name }}</div> <div slot="content">
<div v-if="Object.keys(func.params).length > 0"> <div><strong>功能名称:</strong> {{ func.name }}</div>
<strong>参数配置:</strong> <div v-if="Object.keys(func.params).length > 0">
<div v-for="(value, key) in func.params" :key="key"> <strong>参数配置:</strong>
{{ key }}: {{ value }} <div v-for="(value, key) in func.params" :key="key">
</div> {{ key }}: {{ value }}
</div> </div>
<div v-else>无参数配置</div>
</div> </div>
<div class="icon-dot" :style="{backgroundColor: getFunctionColor(func.name)}"> <div v-else>无参数配置</div>
{{ func.name.charAt(0) }} </div>
</div> <div class="icon-dot" :style="{ backgroundColor: getFunctionColor(func.name) }">
</el-tooltip> {{ func.name.charAt(0) }}
<el-button class="edit-function-btn" @click="showFunctionDialog = true" :class="{'active-btn': showFunctionDialog}"> </div>
编辑功能 </el-tooltip>
</el-button> <el-button class="edit-function-btn" @click="showFunctionDialog = true"
</div> :class="{ 'active-btn': showFunctionDialog }">
编辑功能
</el-button>
</div>
<div v-if="model.type === 'Memory' && form.model.memModelId !== 'Memory_nomem'"
class="chat-history-options">
<el-radio-group v-model="form.chatHistoryConf" @change="updateChatHistoryConf">
<el-radio-button :label="1">上报文字</el-radio-button>
<el-radio-button :label="2">上报文字+语音</el-radio-button>
</el-radio-group>
</div>
</div> </div>
</el-form-item> </el-form-item>
<el-form-item label="角色音色"> <el-form-item label="角色音色">
@@ -92,12 +103,6 @@
:value="item.value" /> :value="item.value" />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="聊天记录配置">
<el-select v-model="form.chatHistoryConf" placeholder="请选择" class="form-select">
<el-option v-for="(item, index) in chatHistoryOptions" :key="`chatHistoryConf-${index}`"
:label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</div> </div>
</div> </div>
</div> </div>
@@ -107,14 +112,15 @@
</div> </div>
</div> </div>
<function-dialog v-model="showFunctionDialog" :functions="currentFunctions" @update-functions="handleUpdateFunctions" @dialog-closed="handleDialogClosed"/> <function-dialog v-model="showFunctionDialog" :functions="currentFunctions"
@update-functions="handleUpdateFunctions" @dialog-closed="handleDialogClosed" />
</div> </div>
</template> </template>
<script> <script>
import Api from '@/apis/api'; import Api from '@/apis/api';
import HeaderBar from "@/components/HeaderBar.vue";
import FunctionDialog from "@/components/FunctionDialog.vue"; import FunctionDialog from "@/components/FunctionDialog.vue";
import HeaderBar from "@/components/HeaderBar.vue";
export default { export default {
name: 'RoleConfigPage', name: 'RoleConfigPage',
@@ -125,7 +131,7 @@ export default {
agentCode: "", agentCode: "",
agentName: "", agentName: "",
ttsVoiceId: "", ttsVoiceId: "",
chatHistoryConf: "", chatHistoryConf: 0,
systemPrompt: "", systemPrompt: "",
langCode: "", langCode: "",
language: "", language: "",
@@ -163,20 +169,6 @@ export default {
{ name: '工具', params: {} }, { name: '工具', params: {} },
{ name: '退出', params: {} } { name: '退出', params: {} }
], ],
chatHistoryOptions: [
{
"value": 0,
"label": "不记录"
},
{
"value": 1,
"label": "仅记录文本"
},
{
"value": 2,
"label": "文本音频都记录"
}
],
} }
}, },
methods: { methods: {
@@ -225,7 +217,7 @@ export default {
agentCode: "", agentCode: "",
agentName: "", agentName: "",
ttsVoiceId: "", ttsVoiceId: "",
chatHistoryConf: "", chatHistoryConf: 0,
systemPrompt: "", systemPrompt: "",
langCode: "", langCode: "",
language: "", language: "",
@@ -244,7 +236,7 @@ export default {
message: '配置已重置', message: '配置已重置',
showClose: true showClose: true
}) })
}).catch(() => {}); }).catch(() => { });
}, },
fetchTemplates() { fetchTemplates() {
Api.agent.getAgentTemplate(({ data }) => { Api.agent.getAgentTemplate(({ data }) => {
@@ -355,6 +347,12 @@ export default {
if (type === 'Intent' && value === 'Intent_function_call') { if (type === 'Intent' && value === 'Intent_function_call') {
this.fetchFunctionList(); this.fetchFunctionList();
} }
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;
}
}, },
fetchFunctionList() { fetchFunctionList() {
// 使用假数据代替API调用 // 使用假数据代替API调用
@@ -379,6 +377,11 @@ export default {
this.currentFunctions = JSON.parse(JSON.stringify(this.originalFunctions)); this.currentFunctions = JSON.parse(JSON.stringify(this.originalFunctions));
} }
}, },
updateChatHistoryConf() {
if (this.form.model.memModelId === 'Memory_nomem') {
this.form.chatHistoryConf = 0;
}
},
}, },
watch: { watch: {
'form.model.ttsModelId': { 'form.model.ttsModelId': {
@@ -693,4 +696,10 @@ export default {
color: white; color: white;
} }
.chat-history-options {
display: flex;
gap: 10px;
min-width: 250px;
justify-content: flex-end;
}
</style> </style>