mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 04:27:39 +00:00
[improvement][chat]记忆评估性能优化 (#1887)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.tencent.supersonic.chat.server.memory;
|
package com.tencent.supersonic.chat.server.memory;
|
||||||
|
|
||||||
import com.tencent.supersonic.chat.api.pojo.enums.MemoryReviewResult;
|
import com.tencent.supersonic.chat.api.pojo.enums.MemoryReviewResult;
|
||||||
|
import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryFilter;
|
||||||
import com.tencent.supersonic.chat.server.agent.Agent;
|
import com.tencent.supersonic.chat.server.agent.Agent;
|
||||||
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatMemoryDO;
|
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatMemoryDO;
|
||||||
import com.tencent.supersonic.chat.server.service.AgentService;
|
import com.tencent.supersonic.chat.server.service.AgentService;
|
||||||
@@ -24,6 +25,7 @@ import java.util.Collections;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -57,24 +59,30 @@ public class MemoryReviewTask {
|
|||||||
|
|
||||||
@Scheduled(fixedDelay = 60 * 1000)
|
@Scheduled(fixedDelay = 60 * 1000)
|
||||||
public void review() {
|
public void review() {
|
||||||
memoryService.getMemoriesForLlmReview().stream().forEach(memory -> {
|
List<Agent> agentList = agentService.getAgents();
|
||||||
|
for (Agent agent : agentList) {
|
||||||
|
if(!agent.enableMemoryReview()){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ChatMemoryFilter chatMemoryFilter = ChatMemoryFilter.builder().agentId(agent.getId()).build();
|
||||||
|
memoryService.getMemories(chatMemoryFilter).stream().forEach(memory -> {
|
||||||
try {
|
try {
|
||||||
processMemory(memory);
|
processMemory(memory, agent);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Exception occurred while processing memory with id {}: {}",
|
log.error("Exception occurred while processing memory with id {}: {}",
|
||||||
memory.getId(), e.getMessage(), e);
|
memory.getId(), e.getMessage(), e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void processMemory(ChatMemoryDO m) {
|
private void processMemory(ChatMemoryDO m, Agent agent) {
|
||||||
Agent chatAgent = agentService.getAgent(m.getAgentId());
|
if (Objects.isNull(agent)) {
|
||||||
if (Objects.isNull(chatAgent)) {
|
|
||||||
log.warn("Agent id {} not found or memory review disabled", m.getAgentId());
|
log.warn("Agent id {} not found or memory review disabled", m.getAgentId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatApp chatApp = chatAgent.getChatAppConfig().get(APP_KEY);
|
ChatApp chatApp = agent.getChatAppConfig().get(APP_KEY);
|
||||||
if (Objects.isNull(chatApp) || !chatApp.isEnable()) {
|
if (Objects.isNull(chatApp) || !chatApp.isEnable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -90,7 +98,7 @@ public class MemoryReviewTask {
|
|||||||
response);
|
response);
|
||||||
processResponse(response, m);
|
processResponse(response, m);
|
||||||
} else {
|
} else {
|
||||||
log.debug("ChatLanguageModel not found for agent:{}", chatAgent.getId());
|
log.debug("ChatLanguageModel not found for agent:{}", agent.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user