Commit 64582e53 authored by alex yao's avatar alex yao

fix[智能问数]: 修复[数据库查询异常]断连问题

parent cf7758b9
...@@ -212,9 +212,10 @@ public class AiBiServiceImpl implements AiBiService { ...@@ -212,9 +212,10 @@ public class AiBiServiceImpl implements AiBiService {
@Override @Override
public void callV2(String dialoguesId, String input, String fileUrl, Integer[] knowledgeIds, Integer[] databaseIds, Long userId) throws Exception { public void callV2(String dialoguesId, String input, String fileUrl, Integer[] knowledgeIds, Integer[] databaseIds, Long userId) throws IOException {
SSEUtil sseUtil = new SSEUtil();
// 保存对话基础信息 // 保存对话基础信息
try {
BizAiDialoguesEntity bizAiDialoguesEntity = new BizAiDialoguesEntity(); BizAiDialoguesEntity bizAiDialoguesEntity = new BizAiDialoguesEntity();
bizAiDialoguesEntity.setMemberId(userId); bizAiDialoguesEntity.setMemberId(userId);
bizAiDialoguesEntity.setDialoguesId(dialoguesId); bizAiDialoguesEntity.setDialoguesId(dialoguesId);
...@@ -236,7 +237,7 @@ public class AiBiServiceImpl implements AiBiService { ...@@ -236,7 +237,7 @@ public class AiBiServiceImpl implements AiBiService {
throw new BusinessException("仅支持单个数据库"); throw new BusinessException("仅支持单个数据库");
} }
long inputTime = System.currentTimeMillis(); long inputTime = System.currentTimeMillis();
SSEUtil sseUtil = new SSEUtil();
CSVChainResult csvChainResult = new CSVChainResult(); CSVChainResult csvChainResult = new CSVChainResult();
List<DBChainResult> dbChainResults = new ArrayList<>(); List<DBChainResult> dbChainResults = new ArrayList<>();
String functionRecord = StringUtils.EMPTY; String functionRecord = StringUtils.EMPTY;
...@@ -285,14 +286,13 @@ public class AiBiServiceImpl implements AiBiService { ...@@ -285,14 +286,13 @@ public class AiBiServiceImpl implements AiBiService {
echartJSONObject.put("sql_result", dbChainResult.getSqlResult()); echartJSONObject.put("sql_result", dbChainResult.getSqlResult());
echartJSONObject.put("question", input); echartJSONObject.put("question", input);
AbstractFunctionResult<String> functionResult = eChartGenerateFunction.doFunction(echartJSONObject.toJSONString(), null, null, null); AbstractFunctionResult<String> functionResult = eChartGenerateFunction.doFunction(echartJSONObject.toJSONString(), null, null, null);
String eChartOption = functionResult.getFunctionResult();
//输出EChart //输出EChart
if (eChartOption != null) { if (functionResult != null && StringUtils.isNotBlank(functionResult.getFunctionResult())) {
JSONObject jsonObject = JSONObject.parseObject(eChartOption); JSONObject jsonObject = JSONObject.parseObject(functionResult.getFunctionResult());
if (!jsonObject.containsKey("skip")) { if (!jsonObject.containsKey("skip")) {
ToolFunction toolFunction = new ToolFunction(); ToolFunction toolFunction = new ToolFunction();
toolFunction.setName("echart_function"); toolFunction.setName("echart_function");
toolFunction.setResult(eChartOption); toolFunction.setResult(functionResult.getFunctionResult());
toolFunction.setDisplayFormat("json"); toolFunction.setDisplayFormat("json");
toolFunction.setArguments(null); toolFunction.setArguments(null);
result = new LargeModelDemandResult(); result = new LargeModelDemandResult();
...@@ -361,6 +361,9 @@ public class AiBiServiceImpl implements AiBiService { ...@@ -361,6 +361,9 @@ public class AiBiServiceImpl implements AiBiService {
bizAgentApplicationDialoguesRecordService.save(inputRecord); bizAgentApplicationDialoguesRecordService.save(inputRecord);
bizAgentApplicationDialoguesRecordService.save(assistantRecord); bizAgentApplicationDialoguesRecordService.save(assistantRecord);
} catch (Exception e) {
sseUtil.completeByError(e.getMessage());
}
} }
......
...@@ -33,6 +33,7 @@ public class ChainServiceImpl implements ChainService { ...@@ -33,6 +33,7 @@ public class ChainServiceImpl implements ChainService {
@Override @Override
public DBChainResult dbChain(DBChainResponse response) { public DBChainResult dbChain(DBChainResponse response) {
logger.info("dbChain response : {}", response); logger.info("dbChain response : {}", response);
try {
DBChainResult dbChainResult = aiDialogueService.dbChain(response); DBChainResult dbChainResult = aiDialogueService.dbChain(response);
if (dbChainResult == null || dbChainResult.getStatus().equals("error")) { if (dbChainResult == null || dbChainResult.getStatus().equals("error")) {
logger.error("dbChain result error : {} , response:{}", dbChainResult, response); logger.error("dbChain result error : {} , response:{}", dbChainResult, response);
...@@ -43,6 +44,10 @@ public class ChainServiceImpl implements ChainService { ...@@ -43,6 +44,10 @@ public class ChainServiceImpl implements ChainService {
return null; return null;
} }
return dbChainResult; return dbChainResult;
} catch (Exception e) {
logger.error("调用数据库失败:{}", e.getMessage());
return null;
}
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment