[feature][chat]Add deleteQuery API to support try-again feature.#1808

This commit is contained in:
jerryjzhang
2024-10-15 20:11:40 +08:00
parent fdbb588fab
commit 2901460845
5 changed files with 29 additions and 19 deletions

View File

@@ -64,6 +64,7 @@ public class ChatQueryRepositoryImpl implements ChatQueryRepository {
queryWrapper.lambda().isNotNull(ChatQueryDO::getQueryResult); queryWrapper.lambda().isNotNull(ChatQueryDO::getQueryResult);
queryWrapper.lambda().ne(ChatQueryDO::getQueryResult, ""); queryWrapper.lambda().ne(ChatQueryDO::getQueryResult, "");
queryWrapper.lambda().orderByDesc(ChatQueryDO::getQuestionId); queryWrapper.lambda().orderByDesc(ChatQueryDO::getQuestionId);
queryWrapper.lambda().eq(ChatQueryDO::getQueryState, 1);
PageInfo<ChatQueryDO> pageInfo = PageInfo<ChatQueryDO> pageInfo =
PageHelper.startPage(pageQueryInfoReq.getCurrent(), pageQueryInfoReq.getPageSize()) PageHelper.startPage(pageQueryInfoReq.getCurrent(), pageQueryInfoReq.getPageSize())
@@ -95,6 +96,7 @@ public class ChatQueryRepositoryImpl implements ChatQueryRepository {
QueryWrapper<ChatQueryDO> queryWrapper = new QueryWrapper<>(); QueryWrapper<ChatQueryDO> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ChatQueryDO::getChatId, chatId); queryWrapper.lambda().eq(ChatQueryDO::getChatId, chatId);
queryWrapper.lambda().orderByDesc(ChatQueryDO::getQuestionId); queryWrapper.lambda().orderByDesc(ChatQueryDO::getQuestionId);
queryWrapper.lambda().eq(ChatQueryDO::getQueryState, 1);
return chatQueryDOMapper.selectList(queryWrapper).stream().map(q -> convertTo(q)) return chatQueryDOMapper.selectList(queryWrapper).stream().map(q -> convertTo(q))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@@ -132,6 +134,7 @@ public class ChatQueryRepositoryImpl implements ChatQueryRepository {
chatQueryDO.setQueryText(chatParseReq.getQueryText()); chatQueryDO.setQueryText(chatParseReq.getQueryText());
chatQueryDO.setAgentId(chatParseReq.getAgentId()); chatQueryDO.setAgentId(chatParseReq.getAgentId());
chatQueryDO.setQueryResult(""); chatQueryDO.setQueryResult("");
chatQueryDO.setQueryState(1);
try { try {
chatQueryDOMapper.insert(chatQueryDO); chatQueryDOMapper.insert(chatQueryDO);
} catch (Exception e) { } catch (Exception e) {

View File

@@ -11,13 +11,7 @@ import com.tencent.supersonic.chat.api.pojo.response.ShowCaseResp;
import com.tencent.supersonic.chat.server.persistence.dataobject.ChatDO; import com.tencent.supersonic.chat.server.persistence.dataobject.ChatDO;
import com.tencent.supersonic.chat.server.service.ChatManageService; import com.tencent.supersonic.chat.server.service.ChatManageService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
@@ -37,7 +31,7 @@ public class ChatController {
} }
@GetMapping("/getAll") @GetMapping("/getAll")
public List<ChatDO> getAllConversions( public List<ChatDO> getAllChats(
@RequestParam(value = "agentId", required = false) Integer agentId, @RequestParam(value = "agentId", required = false) Integer agentId,
HttpServletRequest request, HttpServletResponse response) { HttpServletRequest request, HttpServletResponse response) {
String userName = UserHolder.findUser(request, response).getName(); String userName = UserHolder.findUser(request, response).getName();
@@ -45,14 +39,14 @@ public class ChatController {
} }
@PostMapping("/delete") @PostMapping("/delete")
public Boolean deleteConversion(@RequestParam(value = "chatId") long chatId, public Boolean deleteChat(@RequestParam(value = "chatId") long chatId,
HttpServletRequest request, HttpServletResponse response) { HttpServletRequest request, HttpServletResponse response) {
String userName = UserHolder.findUser(request, response).getName(); String userName = UserHolder.findUser(request, response).getName();
return chatService.deleteChat(chatId, userName); return chatService.deleteChat(chatId, userName);
} }
@PostMapping("/updateChatName") @PostMapping("/updateChatName")
public Boolean updateConversionName(@RequestParam(value = "chatId") Long chatId, public Boolean updateChatName(@RequestParam(value = "chatId") Long chatId,
@RequestParam(value = "chatName") String chatName, HttpServletRequest request, @RequestParam(value = "chatName") String chatName, HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
String userName = UserHolder.findUser(request, response).getName(); String userName = UserHolder.findUser(request, response).getName();
@@ -67,7 +61,7 @@ public class ChatController {
} }
@PostMapping("/updateChatIsTop") @PostMapping("/updateChatIsTop")
public Boolean updateConversionIsTop(@RequestParam(value = "chatId") Long chatId, public Boolean updateChatIsTop(@RequestParam(value = "chatId") Long chatId,
@RequestParam(value = "isTop") int isTop) { @RequestParam(value = "isTop") int isTop) {
return chatService.updateChatIsTop(chatId, isTop); return chatService.updateChatIsTop(chatId, isTop);
} }
@@ -85,6 +79,12 @@ public class ChatController {
return chatService.getChatQuery(queryId); return chatService.getChatQuery(queryId);
} }
@DeleteMapping("/{queryId}")
public boolean deleteChatQuery(@PathVariable(value = "queryId") Long queryId) {
chatService.deleteQuery(queryId);
return true;
}
@PostMapping("/queryShowCase") @PostMapping("/queryShowCase")
public ShowCaseResp queryShowCase(@RequestBody PageQueryInfoReq pageQueryInfoCommand, public ShowCaseResp queryShowCase(@RequestBody PageQueryInfoReq pageQueryInfoCommand,
@RequestParam(value = "agentId") int agentId) { @RequestParam(value = "agentId") int agentId) {

View File

@@ -43,6 +43,8 @@ public interface ChatManageService {
int updateQuery(ChatQueryDO chatQueryDO); int updateQuery(ChatQueryDO chatQueryDO);
void deleteQuery(Long queryId);
void updateParseCostTime(ParseResp parseResp); void updateParseCostTime(ParseResp parseResp);
List<ChatParseDO> batchAddParse(ChatParseReq chatParseReq, ParseResp parseResult); List<ChatParseDO> batchAddParse(ChatParseReq chatParseReq, ParseResp parseResult);

View File

@@ -25,11 +25,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.*;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -187,6 +183,15 @@ public class ChatManageServiceImpl implements ChatManageService {
return chatQueryRepository.updateChatQuery(chatQueryDO); return chatQueryRepository.updateChatQuery(chatQueryDO);
} }
@Override
public void deleteQuery(Long queryId) {
ChatQueryDO chatQuery = chatQueryRepository.getChatQueryDO(queryId);
if (Objects.nonNull(chatQuery)) {
chatQuery.setQueryState(0);
chatQueryRepository.updateChatQuery(chatQuery);
}
}
@Override @Override
public void updateParseCostTime(ParseResp parseResp) { public void updateParseCostTime(ParseResp parseResp) {
ChatQueryDO chatQueryDO = chatQueryRepository.getChatQueryDO(parseResp.getQueryId()); ChatQueryDO chatQueryDO = chatQueryRepository.getChatQueryDO(parseResp.getQueryId());

View File

@@ -389,9 +389,9 @@ ALTER TABLE s2_agent RENAME COLUMN config TO tool_config;
ALTER TABLE s2_agent RENAME COLUMN model_config TO chat_model_config; ALTER TABLE s2_agent RENAME COLUMN model_config TO chat_model_config;
--20241011 --20241011
ALTER TABLE s2_agent DROP COLUMN prompt_config; ALTER TABLE s2_agent DROP COLUMN IF EXISTS `prompt_config`;
ALTER TABLE s2_agent DROP COLUMN multi_turn_config; ALTER TABLE s2_agent DROP COLUMN IF EXISTS `multi_turn_config`;
ALTER TABLE s2_agent DROP COLUMN enable_memory_review; ALTER TABLE s2_agent DROP COLUMN IF EXISTS `enable_memory_review`;
--20241012 --20241012
alter table s2_agent add column `enable_feedback` tinyint DEFAULT 1; alter table s2_agent add column `enable_feedback` tinyint DEFAULT 1;