mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 19:51:00 +00:00
(improvement)(Chat) Optimize memory management (#1741)
Co-authored-by: lxwcodemonkey
This commit is contained in:
@@ -26,4 +26,11 @@ public class ChatMemoryFilter {
|
|||||||
private MemoryReviewResult llmReviewRet;
|
private MemoryReviewResult llmReviewRet;
|
||||||
|
|
||||||
private MemoryReviewResult humanReviewRet;
|
private MemoryReviewResult humanReviewRet;
|
||||||
|
|
||||||
|
private String sort = "desc";
|
||||||
|
private String orderCondition;
|
||||||
|
public boolean isAsc() {
|
||||||
|
return "asc".equalsIgnoreCase(sort);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ public interface ChatMemoryRepository {
|
|||||||
|
|
||||||
void updateMemory(ChatMemoryDO chatMemoryDO);
|
void updateMemory(ChatMemoryDO chatMemoryDO);
|
||||||
|
|
||||||
|
void batchDelete(List<Long> ids);
|
||||||
|
|
||||||
ChatMemoryDO getMemory(Long id);
|
ChatMemoryDO getMemory(Long id);
|
||||||
|
|
||||||
List<ChatMemoryDO> getMemories(QueryWrapper<ChatMemoryDO> queryWrapper);
|
List<ChatMemoryDO> getMemories(QueryWrapper<ChatMemoryDO> queryWrapper);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.springframework.context.annotation.Primary;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@Primary
|
@Primary
|
||||||
@@ -29,6 +30,17 @@ public class ChatMemoryRepositoryImpl implements ChatMemoryRepository {
|
|||||||
chatMemoryMapper.updateById(chatMemoryDO);
|
chatMemoryMapper.updateById(chatMemoryDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void batchDelete(List<Long> ids) {
|
||||||
|
if (CollectionUtils.isEmpty(ids)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (Long id : ids) {
|
||||||
|
chatMemoryMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatMemoryDO getMemory(Long id) {
|
public ChatMemoryDO getMemory(Long id) {
|
||||||
return chatMemoryMapper.selectById(id);
|
return chatMemoryMapper.selectById(id);
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
package com.tencent.supersonic.chat.server.rest;
|
package com.tencent.supersonic.chat.server.rest;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
|
||||||
@@ -10,6 +7,9 @@ import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryUpdateReq;
|
|||||||
import com.tencent.supersonic.chat.api.pojo.request.PageMemoryReq;
|
import com.tencent.supersonic.chat.api.pojo.request.PageMemoryReq;
|
||||||
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.MemoryService;
|
import com.tencent.supersonic.chat.server.service.MemoryService;
|
||||||
|
import com.tencent.supersonic.headless.api.pojo.request.MetaBatchReq;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
@@ -36,4 +36,10 @@ public class MemoryController {
|
|||||||
public PageInfo<ChatMemoryDO> pageMemories(@RequestBody PageMemoryReq pageMemoryReq) {
|
public PageInfo<ChatMemoryDO> pageMemories(@RequestBody PageMemoryReq pageMemoryReq) {
|
||||||
return memoryService.pageMemories(pageMemoryReq);
|
return memoryService.pageMemories(pageMemoryReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("batchDelete")
|
||||||
|
public Boolean batchDelete(@RequestBody MetaBatchReq metaBatchReq) {
|
||||||
|
memoryService.batchDelete(metaBatchReq.getIds());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ public interface MemoryService {
|
|||||||
|
|
||||||
void disableMemory(ChatMemoryDO memory);
|
void disableMemory(ChatMemoryDO memory);
|
||||||
|
|
||||||
|
void batchDelete(List<Long> ids);
|
||||||
|
|
||||||
PageInfo<ChatMemoryDO> pageMemories(PageMemoryReq pageMemoryReq);
|
PageInfo<ChatMemoryDO> pageMemories(PageMemoryReq pageMemoryReq);
|
||||||
|
|
||||||
List<ChatMemoryDO> getMemories(ChatMemoryFilter chatMemoryFilter);
|
List<ChatMemoryDO> getMemories(ChatMemoryFilter chatMemoryFilter);
|
||||||
|
|||||||
@@ -55,8 +55,16 @@ public class MemoryServiceImpl implements MemoryService {
|
|||||||
chatMemoryRepository.updateMemory(memory);
|
chatMemoryRepository.updateMemory(memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void batchDelete(List<Long> ids) {
|
||||||
|
chatMemoryRepository.batchDelete(ids);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<ChatMemoryDO> pageMemories(PageMemoryReq pageMemoryReq) {
|
public PageInfo<ChatMemoryDO> pageMemories(PageMemoryReq pageMemoryReq) {
|
||||||
|
ChatMemoryFilter chatMemoryFilter = pageMemoryReq.getChatMemoryFilter();
|
||||||
|
chatMemoryFilter.setSort(pageMemoryReq.getSort());
|
||||||
|
chatMemoryFilter.setOrderCondition(pageMemoryReq.getOrderCondition());
|
||||||
return PageHelper.startPage(pageMemoryReq.getCurrent(), pageMemoryReq.getPageSize())
|
return PageHelper.startPage(pageMemoryReq.getCurrent(), pageMemoryReq.getPageSize())
|
||||||
.doSelectPageInfo(() -> getMemories(pageMemoryReq.getChatMemoryFilter()));
|
.doSelectPageInfo(() -> getMemories(pageMemoryReq.getChatMemoryFilter()));
|
||||||
}
|
}
|
||||||
@@ -86,6 +94,11 @@ public class MemoryServiceImpl implements MemoryService {
|
|||||||
.lambda()
|
.lambda()
|
||||||
.eq(ChatMemoryDO::getLlmReviewRet, chatMemoryFilter.getLlmReviewRet());
|
.eq(ChatMemoryDO::getLlmReviewRet, chatMemoryFilter.getLlmReviewRet());
|
||||||
}
|
}
|
||||||
|
if (StringUtils.isBlank(chatMemoryFilter.getOrderCondition())) {
|
||||||
|
queryWrapper.orderByDesc("id");
|
||||||
|
} else {
|
||||||
|
queryWrapper.orderBy(true, chatMemoryFilter.isAsc(), chatMemoryFilter.getOrderCondition());
|
||||||
|
}
|
||||||
return chatMemoryRepository.getMemories(queryWrapper);
|
return chatMemoryRepository.getMemories(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user