mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-23 23:53:55 +08:00
feat:新增仅上报聊天记录(mem_report_only)记忆供应器
This commit is contained in:
@@ -151,6 +151,11 @@ public interface Constant {
|
|||||||
*/
|
*/
|
||||||
String MEMORY_NO_MEM = "Memory_nomem";
|
String MEMORY_NO_MEM = "Memory_nomem";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 仅上报聊天记录(不总结记忆)
|
||||||
|
*/
|
||||||
|
String MEMORY_MEM_REPORT_ONLY = "Memory_mem_report_only";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 火山引擎双声道语音克隆
|
* 火山引擎双声道语音克隆
|
||||||
*/
|
*/
|
||||||
|
|||||||
+17
-9
@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import xiaozhi.common.constant.Constant;
|
||||||
import xiaozhi.modules.agent.dto.AgentChatHistoryDTO;
|
import xiaozhi.modules.agent.dto.AgentChatHistoryDTO;
|
||||||
import xiaozhi.modules.agent.dto.AgentChatSummaryDTO;
|
import xiaozhi.modules.agent.dto.AgentChatSummaryDTO;
|
||||||
import xiaozhi.modules.agent.dto.AgentMemoryDTO;
|
import xiaozhi.modules.agent.dto.AgentMemoryDTO;
|
||||||
@@ -90,21 +91,28 @@ public class AgentChatSummaryServiceImpl implements AgentChatSummaryService {
|
|||||||
@Override
|
@Override
|
||||||
public boolean generateAndSaveChatSummary(String sessionId) {
|
public boolean generateAndSaveChatSummary(String sessionId) {
|
||||||
try {
|
try {
|
||||||
// 1. 生成总结
|
// 1. 获取设备信息(通过会话关联的设备)
|
||||||
AgentChatSummaryDTO summaryDTO = generateChatSummary(sessionId);
|
|
||||||
if (!summaryDTO.isSuccess()) {
|
|
||||||
log.info("生成总结失败: {}", summaryDTO.getErrorMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 获取设备信息(通过会话关联的设备)
|
|
||||||
DeviceEntity device = getDeviceBySessionId(sessionId);
|
DeviceEntity device = getDeviceBySessionId(sessionId);
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
log.info("未找到与会话 {} 关联的设备", sessionId);
|
log.info("未找到与会话 {} 关联的设备", sessionId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 更新智能体记忆
|
// 2. 检查记忆模型类型,如果是仅上报聊天记录模式则跳过总结
|
||||||
|
String memModelId = agentService.getAgentById(device.getAgentId()).getMemModelId();
|
||||||
|
if (memModelId != null && memModelId.equals(Constant.MEMORY_MEM_REPORT_ONLY)) {
|
||||||
|
log.info("会话 {} 使用仅上报聊天记录模式,跳过记忆总结", sessionId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 生成总结
|
||||||
|
AgentChatSummaryDTO summaryDTO = generateChatSummary(sessionId);
|
||||||
|
if (!summaryDTO.isSuccess()) {
|
||||||
|
log.info("生成总结失败: {}", summaryDTO.getErrorMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 更新智能体记忆
|
||||||
AgentMemoryDTO memoryDTO = new AgentMemoryDTO();
|
AgentMemoryDTO memoryDTO = new AgentMemoryDTO();
|
||||||
memoryDTO.setSummaryMemory(summaryDTO.getSummary());
|
memoryDTO.setSummaryMemory(summaryDTO.getSummary());
|
||||||
|
|
||||||
|
|||||||
+1
@@ -95,6 +95,7 @@ public class ModelProviderServiceImpl extends BaseServiceImpl<ModelProviderDao,
|
|||||||
|
|
||||||
QueryWrapper<ModelProviderEntity> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<ModelProviderEntity> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("model_type", StringUtils.isBlank(modelType) ? "" : modelType);
|
queryWrapper.eq("model_type", StringUtils.isBlank(modelType) ? "" : modelType);
|
||||||
|
queryWrapper.orderByAsc("sort");
|
||||||
List<ModelProviderEntity> providerEntities = modelProviderDao.selectList(queryWrapper);
|
List<ModelProviderEntity> providerEntities = modelProviderDao.selectList(queryWrapper);
|
||||||
return ConvertUtils.sourceToTarget(providerEntities, ModelProviderDTO.class);
|
return ConvertUtils.sourceToTarget(providerEntities, ModelProviderDTO.class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
delete from `ai_model_provider` where `id` = 'SYSTEM_Memory_mem_report_only';
|
||||||
|
delete from `ai_model_config` where `id` = 'Memory_mem_report_only';
|
||||||
|
|
||||||
|
INSERT INTO `ai_model_provider` VALUES ('SYSTEM_Memory_mem_report_only', 'Memory', 'mem_report_only', '仅上报聊天记录', '[]', 4, 1, NOW(), 1, NOW());
|
||||||
|
INSERT INTO `ai_model_config` VALUES ('Memory_mem_report_only', 'Memory', 'mem_report_only', '仅上报聊天记录', 0, 1, '{"type": "mem_report_only"}', NULL, NULL, 3, NULL, NULL, NULL, NULL);
|
||||||
@@ -571,3 +571,10 @@ databaseChangeLog:
|
|||||||
- sqlFile:
|
- sqlFile:
|
||||||
encoding: utf8
|
encoding: utf8
|
||||||
path: classpath:db/changelog/202603111131.sql
|
path: classpath:db/changelog/202603111131.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202603231036
|
||||||
|
author: rainv123
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202603231036.sql
|
||||||
@@ -751,8 +751,8 @@ class ConnectionHandler:
|
|||||||
memory_type = self.config["Memory"][self.config["selected_module"]["Memory"]][
|
memory_type = self.config["Memory"][self.config["selected_module"]["Memory"]][
|
||||||
"type"
|
"type"
|
||||||
]
|
]
|
||||||
# 如果使用 nomen,直接返回
|
# 如果使用 nomen 或 mem_report_only,直接返回
|
||||||
if memory_type == "nomem":
|
if memory_type == "nomem" or memory_type == "mem_report_only":
|
||||||
return
|
return
|
||||||
# 使用 mem_local_short 模式
|
# 使用 mem_local_short 模式
|
||||||
elif memory_type == "mem_local_short":
|
elif memory_type == "mem_local_short":
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
"""
|
||||||
|
仅上报聊天记录,不进行记忆总结
|
||||||
|
"""
|
||||||
|
|
||||||
|
from ..base import MemoryProviderBase, logger
|
||||||
|
|
||||||
|
TAG = __name__
|
||||||
|
|
||||||
|
|
||||||
|
class MemoryProvider(MemoryProviderBase):
|
||||||
|
def __init__(self, config, summary_memory=None):
|
||||||
|
super().__init__(config)
|
||||||
|
|
||||||
|
async def save_memory(self, msgs, session_id=None):
|
||||||
|
logger.bind(tag=TAG).debug("mem_report_only mode: No memory saving or summarization is performed.")
|
||||||
|
return None
|
||||||
|
|
||||||
|
async def query_memory(self, query: str) -> str:
|
||||||
|
logger.bind(tag=TAG).debug("mem_report_only mode: No memory query is performed.")
|
||||||
|
return ""
|
||||||
Reference in New Issue
Block a user