mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 12:37:55 +00:00
(fix)(Chat) Fix chat sample result save failed (#1261)
Co-authored-by: lxwcodemonkey
This commit is contained in:
@@ -20,7 +20,7 @@ public interface ChatService {
|
|||||||
|
|
||||||
QueryResult performExecution(ChatExecuteReq chatExecuteReq) throws Exception;
|
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;
|
Object queryData(ChatQueryDataReq chatQueryDataReq, User user) throws Exception;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.tencent.supersonic.chat.server.service.impl;
|
|||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
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.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.Agent;
|
||||||
import com.tencent.supersonic.chat.server.agent.MultiTurnConfig;
|
import com.tencent.supersonic.chat.server.agent.MultiTurnConfig;
|
||||||
import com.tencent.supersonic.chat.server.persistence.dataobject.AgentDO;
|
import com.tencent.supersonic.chat.server.persistence.dataobject.AgentDO;
|
||||||
@@ -95,12 +94,7 @@ public class AgentServiceImpl extends ServiceImpl<AgentDOMapper, AgentDO>
|
|||||||
if (memoriesExisted.contains(example)) {
|
if (memoriesExisted.contains(example)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ChatParseReq chatParseReq = new ChatParseReq();
|
chatService.parseAndExecute(-1, agent.getId(), example);
|
||||||
chatParseReq.setAgentId(agent.getId());
|
|
||||||
chatParseReq.setQueryText(example);
|
|
||||||
chatParseReq.setUser(User.getFakeUser());
|
|
||||||
chatParseReq.setChatId(-1);
|
|
||||||
chatService.parseAndExecute(chatParseReq);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.ChatExecuteReq;
|
||||||
import com.tencent.supersonic.chat.api.pojo.request.ChatParseReq;
|
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.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.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.persistence.dataobject.ChatParseDO;
|
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.common.util.JsonUtil;
|
||||||
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
import com.tencent.supersonic.headless.api.pojo.SemanticParseInfo;
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
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 com.tencent.supersonic.headless.api.pojo.response.QueryResult;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
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.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import com.tencent.supersonic.headless.server.facade.service.RetrieveService;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -91,22 +92,34 @@ public class ChatServiceImpl implements ChatService {
|
|||||||
for (ExecuteResultProcessor processor : executeResultProcessors) {
|
for (ExecuteResultProcessor processor : executeResultProcessors) {
|
||||||
processor.process(chatExecuteContext, queryResult);
|
processor.process(chatExecuteContext, queryResult);
|
||||||
}
|
}
|
||||||
|
saveQueryResult(chatExecuteReq, queryResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
return queryResult;
|
return queryResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
ParseResp parseResp = performParsing(chatParseReq);
|
||||||
ChatExecuteReq chatExecuteReq = new ChatExecuteReq();
|
if (CollectionUtils.isEmpty(parseResp.getSelectedParses())) {
|
||||||
chatExecuteReq.setQueryId(parseResp.getQueryId());
|
log.debug("chatId:{}, agentId:{}, queryText:{}, parseResp.getSelectedParses() is empty",
|
||||||
chatExecuteReq.setChatId(chatParseReq.getChatId());
|
chatId, agentId, queryText);
|
||||||
chatExecuteReq.setUser(chatParseReq.getUser());
|
return null;
|
||||||
chatExecuteReq.setAgentId(chatParseReq.getAgentId());
|
}
|
||||||
chatExecuteReq.setQueryText(chatParseReq.getQueryText());
|
ChatExecuteReq executeReq = new ChatExecuteReq();
|
||||||
chatExecuteReq.setParseId(parseResp.getSelectedParses().get(0).getId());
|
executeReq.setQueryId(parseResp.getQueryId());
|
||||||
return performExecution(chatExecuteReq);
|
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) {
|
private ChatParseContext buildParseContext(ChatParseReq chatParseReq) {
|
||||||
@@ -153,4 +166,12 @@ public class ChatServiceImpl implements ChatService {
|
|||||||
return chatQueryService.queryDimensionValue(dimensionValueReq, user);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ package com.tencent.supersonic.demo;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
import com.tencent.supersonic.auth.api.authentication.pojo.User;
|
||||||
import com.tencent.supersonic.auth.api.authorization.service.AuthService;
|
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.AgentService;
|
||||||
import com.tencent.supersonic.chat.server.service.ChatManageService;
|
import com.tencent.supersonic.chat.server.service.ChatManageService;
|
||||||
import com.tencent.supersonic.chat.server.service.ChatService;
|
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.DimensionResp;
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.MetricResp;
|
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.ModelResp;
|
||||||
import com.tencent.supersonic.headless.api.pojo.response.ParseResp;
|
|
||||||
import com.tencent.supersonic.headless.server.pojo.MetaFilter;
|
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.CanvasService;
|
||||||
import com.tencent.supersonic.headless.server.web.service.DataSetService;
|
import com.tencent.supersonic.headless.server.web.service.DataSetService;
|
||||||
@@ -155,28 +152,6 @@ public abstract class S2BaseDemo implements CommandLineRunner {
|
|||||||
return dataSetModelConfigs;
|
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) {
|
protected void addTag(Long itemId, TagDefineType tagDefineType) {
|
||||||
TagReq tagReq = new TagReq();
|
TagReq tagReq = new TagReq();
|
||||||
tagReq.setTagDefineType(tagDefineType);
|
tagReq.setTagDefineType(tagDefineType);
|
||||||
|
|||||||
@@ -132,15 +132,15 @@ public class S2VisitsDemo extends S2BaseDemo {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSampleChats(Integer agentId) throws Exception {
|
public void addSampleChats(Integer agentId) {
|
||||||
Long chatId = chatManageService.addChat(user, "样例对话1", agentId);
|
Long chatId = chatManageService.addChat(user, "样例对话1", agentId);
|
||||||
|
|
||||||
parseAndExecute(chatId.intValue(), agentId, "超音数 访问次数");
|
chatService.parseAndExecute(chatId.intValue(), agentId, "超音数 访问次数");
|
||||||
parseAndExecute(chatId.intValue(), agentId, "按部门统计");
|
chatService.parseAndExecute(chatId.intValue(), agentId, "按部门统计");
|
||||||
parseAndExecute(chatId.intValue(), agentId, "查询近30天");
|
chatService.parseAndExecute(chatId.intValue(), agentId, "查询近30天");
|
||||||
parseAndExecute(chatId.intValue(), agentId, "alice 停留时长");
|
chatService.parseAndExecute(chatId.intValue(), agentId, "alice 停留时长");
|
||||||
parseAndExecute(chatId.intValue(), agentId, "对比alice和lucy的访问次数");
|
chatService.parseAndExecute(chatId.intValue(), agentId, "对比alice和lucy的访问次数");
|
||||||
parseAndExecute(chatId.intValue(), agentId, "访问次数最高的部门");
|
chatService.parseAndExecute(chatId.intValue(), agentId, "访问次数最高的部门");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer addAgent(long dataSetId) {
|
private Integer addAgent(long dataSetId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user