(fix)(Chat) Fix chat sample result save failed (#1261)

Co-authored-by: lxwcodemonkey
This commit is contained in:
LXW
2024-06-28 11:19:53 +08:00
committed by GitHub
parent 28f95ddf9e
commit 26cd73518d
6 changed files with 41 additions and 50 deletions

View File

@@ -20,7 +20,7 @@ public interface ChatService {
QueryResult performExecution(ChatExecuteReq chatExecuteReq) throws Exception;
QueryResult parseAndExecute(ChatParseReq chatParseReq);
QueryResult parseAndExecute(int chatId, int agentId, String queryText);
Object queryData(ChatQueryDataReq chatQueryDataReq, User user) throws Exception;

View File

@@ -3,7 +3,6 @@ package com.tencent.supersonic.chat.server.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.chat.api.pojo.request.ChatMemoryFilter;
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
import com.tencent.supersonic.chat.server.agent.Agent;
import com.tencent.supersonic.chat.server.agent.MultiTurnConfig;
import com.tencent.supersonic.chat.server.persistence.dataobject.AgentDO;
@@ -95,12 +94,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentDOMapper, AgentDO>
if (memoriesExisted.contains(example)) {
continue;
}
ChatParseReq chatParseReq = new ChatParseReq();
chatParseReq.setAgentId(agent.getId());
chatParseReq.setQueryText(example);
chatParseReq.setUser(User.getFakeUser());
chatParseReq.setChatId(-1);
chatService.parseAndExecute(chatParseReq);
chatService.parseAndExecute(-1, agent.getId(), example);
}
}

View File

@@ -6,6 +6,7 @@ import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.chat.api.pojo.request.ChatExecuteReq;
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
import com.tencent.supersonic.chat.api.pojo.request.PageQueryInfoReq;
import com.tencent.supersonic.chat.api.pojo.response.QueryResp;
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.ChatParseDO;
@@ -17,12 +18,12 @@ import com.tencent.supersonic.chat.server.service.ChatManageService;
import com.tencent.supersonic.common.util.JsonUtil;
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
import com.tencent.supersonic.chat.api.pojo.response.QueryResp;
import com.tencent.supersonic.headless.api.pojo.response.QueryResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;

View File

@@ -30,6 +30,7 @@ import com.tencent.supersonic.headless.server.facade.service.RetrieveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
@@ -91,22 +92,34 @@ public class ChatServiceImpl implements ChatService {
for (ExecuteResultProcessor processor : executeResultProcessors) {
processor.process(chatExecuteContext, queryResult);
}
saveQueryResult(chatExecuteReq, queryResult);
}
return queryResult;
}
@Override
public QueryResult parseAndExecute(ChatParseReq chatParseReq) {
public QueryResult parseAndExecute(int chatId, int agentId, String queryText) {
ChatParseReq chatParseReq = new ChatParseReq();
chatParseReq.setQueryText(queryText);
chatParseReq.setChatId(chatId);
chatParseReq.setAgentId(agentId);
chatParseReq.setUser(User.getFakeUser());
ParseResp parseResp = performParsing(chatParseReq);
ChatExecuteReq chatExecuteReq = new ChatExecuteReq();
chatExecuteReq.setQueryId(parseResp.getQueryId());
chatExecuteReq.setChatId(chatParseReq.getChatId());
chatExecuteReq.setUser(chatParseReq.getUser());
chatExecuteReq.setAgentId(chatParseReq.getAgentId());
chatExecuteReq.setQueryText(chatParseReq.getQueryText());
chatExecuteReq.setParseId(parseResp.getSelectedParses().get(0).getId());
return performExecution(chatExecuteReq);
if (CollectionUtils.isEmpty(parseResp.getSelectedParses())) {
log.debug("chatId:{}, agentId:{}, queryText:{}, parseResp.getSelectedParses() is empty",
chatId, agentId, queryText);
return null;
}
ChatExecuteReq executeReq = new ChatExecuteReq();
executeReq.setQueryId(parseResp.getQueryId());
executeReq.setParseId(parseResp.getSelectedParses().get(0).getId());
executeReq.setQueryText(queryText);
executeReq.setChatId(parseResp.getChatId());
executeReq.setUser(User.getFakeUser());
executeReq.setAgentId(agentId);
executeReq.setSaveAnswer(true);
return performExecution(executeReq);
}
private ChatParseContext buildParseContext(ChatParseReq chatParseReq) {
@@ -153,4 +166,12 @@ public class ChatServiceImpl implements ChatService {
return chatQueryService.queryDimensionValue(dimensionValueReq, user);
}
public void saveQueryResult(ChatExecuteReq chatExecuteReq, QueryResult queryResult) {
//The history record only retains the query result of the first parse
if (chatExecuteReq.getParseId() > 1) {
return;
}
chatManageService.saveQueryResult(chatExecuteReq, queryResult);
}
}

View File

@@ -3,8 +3,6 @@ package com.tencent.supersonic.demo;
import com.google.common.collect.Lists;
import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.auth.api.authorization.service.AuthService;
import com.tencent.supersonic.chat.api.pojo.request.ChatExecuteReq;
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
import com.tencent.supersonic.chat.server.service.AgentService;
import com.tencent.supersonic.chat.server.service.ChatManageService;
import com.tencent.supersonic.chat.server.service.ChatService;
@@ -21,7 +19,6 @@ import com.tencent.supersonic.headless.api.pojo.response.DatabaseResp;
import com.tencent.supersonic.headless.api.pojo.response.DimensionResp;
import com.tencent.supersonic.headless.api.pojo.response.MetricResp;
import com.tencent.supersonic.headless.api.pojo.response.ModelResp;
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
import com.tencent.supersonic.headless.server.pojo.MetaFilter;
import com.tencent.supersonic.headless.server.web.service.CanvasService;
import com.tencent.supersonic.headless.server.web.service.DataSetService;
@@ -155,28 +152,6 @@ public abstract class S2BaseDemo implements CommandLineRunner {
return dataSetModelConfigs;
}
protected void parseAndExecute(int chatId, int agentId, String queryText) throws Exception {
ChatParseReq chatParseReq = new ChatParseReq();
chatParseReq.setQueryText(queryText);
chatParseReq.setChatId(chatId);
chatParseReq.setAgentId(agentId);
chatParseReq.setUser(User.getFakeUser());
ParseResp parseResp = chatService.performParsing(chatParseReq);
if (CollectionUtils.isEmpty(parseResp.getSelectedParses())) {
log.info("parseResp.getSelectedParses() is empty");
return;
}
ChatExecuteReq executeReq = new ChatExecuteReq();
executeReq.setQueryId(parseResp.getQueryId());
executeReq.setParseId(parseResp.getSelectedParses().get(0).getId());
executeReq.setQueryText(queryText);
executeReq.setChatId(parseResp.getChatId());
executeReq.setUser(User.getFakeUser());
executeReq.setAgentId(agentId);
executeReq.setSaveAnswer(true);
chatService.performExecution(executeReq);
}
protected void addTag(Long itemId, TagDefineType tagDefineType) {
TagReq tagReq = new TagReq();
tagReq.setTagDefineType(tagDefineType);

View File

@@ -132,15 +132,15 @@ public class S2VisitsDemo extends S2BaseDemo {
return true;
}
public void addSampleChats(Integer agentId) throws Exception {
public void addSampleChats(Integer agentId) {
Long chatId = chatManageService.addChat(user, "样例对话1", agentId);
parseAndExecute(chatId.intValue(), agentId, "超音数 访问次数");
parseAndExecute(chatId.intValue(), agentId, "按部门统计");
parseAndExecute(chatId.intValue(), agentId, "查询近30天");
parseAndExecute(chatId.intValue(), agentId, "alice 停留时长");
parseAndExecute(chatId.intValue(), agentId, "对比alice和lucy的访问次数");
parseAndExecute(chatId.intValue(), agentId, "访问次数最高的部门");
chatService.parseAndExecute(chatId.intValue(), agentId, "超音数 访问次数");
chatService.parseAndExecute(chatId.intValue(), agentId, "按部门统计");
chatService.parseAndExecute(chatId.intValue(), agentId, "查询近30天");
chatService.parseAndExecute(chatId.intValue(), agentId, "alice 停留时长");
chatService.parseAndExecute(chatId.intValue(), agentId, "对比alice和lucy的访问次数");
chatService.parseAndExecute(chatId.intValue(), agentId, "访问次数最高的部门");
}
private Integer addAgent(long dataSetId) {