Commit c784f262f5a7794462c6c97e6cfef1fa57089e3d

Authored by qianbao
1 parent af220654

AI 对于时间的处理

src/main/java/com/xly/constant/BusinessCode.java
@@ -13,7 +13,8 @@ import lombok.Getter; @@ -13,7 +13,8 @@ import lombok.Getter;
13 public enum BusinessCode { 13 public enum BusinessCode {
14 14
15 //报价确认 15 //报价确认
16 - QUOCONFIRM("quoconfirm", "报价确认"); 16 + QUOCONFIRM("quoconfirm", "报价确认"),
  17 + COMMONTS("commonTs", "如果切换场景,点[回首页],如果在本场景下,转换意图,点[清除记忆]");
17 18
18 private final String code; 19 private final String code;
19 private final String message; 20 private final String message;
src/main/java/com/xly/service/XlyErpService.java
@@ -14,6 +14,7 @@ import com.xly.constant.CommonConstant; @@ -14,6 +14,7 @@ import com.xly.constant.CommonConstant;
14 import com.xly.constant.ReturnTypeCode; 14 import com.xly.constant.ReturnTypeCode;
15 import com.xly.entity.*; 15 import com.xly.entity.*;
16 import com.xly.exception.sqlexception.SqlGenerateException; 16 import com.xly.exception.sqlexception.SqlGenerateException;
  17 +import com.xly.exception.sqlexception.SqlValidateException;
17 import com.xly.mapper.ToolMetaMapper; 18 import com.xly.mapper.ToolMetaMapper;
18 import com.xly.runner.AppStartupRunner; 19 import com.xly.runner.AppStartupRunner;
19 import com.xly.tool.DynamicToolProvider; 20 import com.xly.tool.DynamicToolProvider;
@@ -157,12 +158,11 @@ public class XlyErpService { @@ -157,12 +158,11 @@ public class XlyErpService {
157 UserSceneSession session = userSceneSessionService.getUserSceneSession(userId,sUserName,sBrandsId,sSubsidiaryId,sUserType,authorization); 158 UserSceneSession session = userSceneSessionService.getUserSceneSession(userId,sUserName,sBrandsId,sSubsidiaryId,sUserType,authorization);
158 operableChatMemoryProvider.clearSpecifiedMemory(userId); 159 operableChatMemoryProvider.clearSpecifiedMemory(userId);
159 session.setCurrentTool(null); 160 session.setCurrentTool(null);
160 - session.setBCleanMemory(false);  
161 UserSceneSessionService.ERP_AGENT_CACHE.remove(userId); 161 UserSceneSessionService.ERP_AGENT_CACHE.remove(userId);
162 UserSceneSessionService.CHAT_AGENT_CACHE.remove(userId); 162 UserSceneSessionService.CHAT_AGENT_CACHE.remove(userId);
  163 + session.setBCleanMemory(false);
163 String sceneName = ObjectUtil.isNotEmpty(session.getCurrentScene())?session.getCurrentScene().getSSceneName():StrUtil.EMPTY; 164 String sceneName = ObjectUtil.isNotEmpty(session.getCurrentScene())?session.getCurrentScene().getSSceneName():StrUtil.EMPTY;
164 - String methodName = ObjectUtil.isNotEmpty(session.getCurrentTool())?session.getCurrentTool().getSMethodName():StrUtil.EMPTY;  
165 - return AiResponseDTO.builder().sSceneName(sceneName).sMethodName(methodName).aiText(StrUtil.EMPTY).systemText("清除记忆成功!").sReturnType(ReturnTypeCode.HTML.getCode()).build(); 165 + return AiResponseDTO.builder().sSceneName(sceneName).sMethodName(StrUtil.EMPTY).aiText(StrUtil.EMPTY).systemText("清除记忆成功!").sReturnType(ReturnTypeCode.HTML.getCode()).build();
166 } 166 }
167 167
168 168
@@ -180,6 +180,8 @@ public class XlyErpService { @@ -180,6 +180,8 @@ public class XlyErpService {
180 try{ 180 try{
181 attempt = attempt+1; 181 attempt = attempt+1;
182 return getDynamicTableSqlExec(session, input, userId, userInput,errorSql,errorMessage,iErroCount,historySqlList); 182 return getDynamicTableSqlExec(session, input, userId, userInput,errorSql,errorMessage,iErroCount,historySqlList);
  183 + }catch (SqlValidateException e){
  184 + return "本场景没有识别到您的意图<br/> 如果切换场景,点[回首页],如果在本场景下,转换意图,点[清除记忆]";
183 }catch (Exception e){ 185 }catch (Exception e){
184 String erroMsg = e.getMessage(); 186 String erroMsg = e.getMessage();
185 String errorSqlOld = StrUtil.EMPTY; 187 String errorSqlOld = StrUtil.EMPTY;
@@ -194,7 +196,7 @@ public class XlyErpService { @@ -194,7 +196,7 @@ public class XlyErpService {
194 } 196 }
195 String errorMessageOld = erroMsg.split(EnhancedErrorGuidance.splitString)[0]; 197 String errorMessageOld = erroMsg.split(EnhancedErrorGuidance.splitString)[0];
196 if (attempt == maxRetries) { 198 if (attempt == maxRetries) {
197 - return resultExplain+"查询的SQL语句:"+historySqlList; 199 + return resultExplain +"<br/>查询的SQL语句:"+historySqlList;
198 } else { 200 } else {
199 return getDynamicTableSql( session, input, userId, userInput, attempt,errorSqlOld,errorMessageOld,attempt.toString(),historySqlList); 201 return getDynamicTableSql( session, input, userId, userInput, attempt,errorSqlOld,errorMessageOld,attempt.toString(),historySqlList);
200 } 202 }
@@ -202,7 +204,7 @@ public class XlyErpService { @@ -202,7 +204,7 @@ public class XlyErpService {
202 } 204 }
203 }catch (Exception e){ 205 }catch (Exception e){
204 }finally { 206 }finally {
205 - doCleanUserMemory(session,userId); 207 + // doCleanUserMemory(session,userId);
206 } 208 }
207 return resultExplain; 209 return resultExplain;
208 } 210 }
@@ -246,7 +248,7 @@ public class XlyErpService { @@ -246,7 +248,7 @@ public class XlyErpService {
246 rawSql = aiDynamicTableNl2SqlAiAgent.regenerateSqlWithError(userId, tableNames,tableStruct,sDataNow,userInput,errorSql,errorMessage,iErroCount,historySqlList); 248 rawSql = aiDynamicTableNl2SqlAiAgent.regenerateSqlWithError(userId, tableNames,tableStruct,sDataNow,userInput,errorSql,errorMessage,iErroCount,historySqlList);
247 } 249 }
248 if (rawSql == null || rawSql.trim().isEmpty()) { 250 if (rawSql == null || rawSql.trim().isEmpty()) {
249 - throw new SqlGenerateException("SQL EMPTY"); 251 + throw new SqlValidateException("SQL EMPTY");
250 } 252 }
251 // 2. 清理SQL多余符号 + 生产级强校验(核心安全保障,不可省略) 253 // 2. 清理SQL多余符号 + 生产级强校验(核心安全保障,不可省略)
252 String cleanSql = SqlValidateUtil.cleanSqlSymbol(rawSql); 254 String cleanSql = SqlValidateUtil.cleanSqlSymbol(rawSql);
src/main/java/com/xly/tool/DynamicToolProvider.java
@@ -196,7 +196,12 @@ public class DynamicToolProvider implements ToolProvider { @@ -196,7 +196,12 @@ public class DynamicToolProvider implements ToolProvider {
196 UserSceneSession session = UserSceneSessionService.USER_SCENE_SESSION_CACHE.get(sUserId); 196 UserSceneSession session = UserSceneSessionService.USER_SCENE_SESSION_CACHE.get(sUserId);
197 //过滤对应的权限方法 197 //过滤对应的权限方法
198 List<ToolSpecificationHolder> datalist = new ArrayList<>(); 198 List<ToolSpecificationHolder> datalist = new ArrayList<>();
199 - List<ToolMeta> toolMetaAll = session.getAuthTool(); 199 + List<ToolMeta> toolMetaAll = new ArrayList<>();
  200 + if(session.getCurrentTool()!=null){
  201 + toolMetaAll.add(session.getCurrentTool());
  202 + }else{
  203 + toolMetaAll = session.getAuthTool();
  204 + }
200 if(ObjectUtil.isNotEmpty(toolMetaAll)){ 205 if(ObjectUtil.isNotEmpty(toolMetaAll)){
201 toolMetaAll = toolMetaAll.stream().filter(to-> to.getSSceneId().equals(sSceneIdMap.get(sUserId))).collect(Collectors.toUnmodifiableList()); 206 toolMetaAll = toolMetaAll.stream().filter(to-> to.getSSceneId().equals(sSceneIdMap.get(sUserId))).collect(Collectors.toUnmodifiableList());
202 if(ObjectUtil.isNotEmpty(toolMetaAll)){ 207 if(ObjectUtil.isNotEmpty(toolMetaAll)){
@@ -532,10 +537,8 @@ public class DynamicToolProvider implements ToolProvider { @@ -532,10 +537,8 @@ public class DynamicToolProvider implements ToolProvider {
532 } 537 }
533 // Map<String, Object> argsOld = DeepCopyUtils.deepCopy(args); 538 // Map<String, Object> argsOld = DeepCopyUtils.deepCopy(args);
534 List<ParamRule> paramRuleData = meta.getParamRuleListAll(); 539 List<ParamRule> paramRuleData = meta.getParamRuleListAll();
535 - // 2. 【自动补全】应用参数的默认值  
536 - args = applyDefaultValues(args, paramRuleData);  
537 540
538 - // 2.1 【补全动态参数】动态参数补全 541 + // 2 【补全动态参数】动态参数补全
539 try{ 542 try{
540 args = applyValues(args, meta.getParamRuleListCheck()); 543 args = applyValues(args, meta.getParamRuleListCheck());
541 }catch (Exception e){ 544 }catch (Exception e){
@@ -546,6 +549,9 @@ public class DynamicToolProvider implements ToolProvider { @@ -546,6 +549,9 @@ public class DynamicToolProvider implements ToolProvider {
546 return String.valueOf(askUserResult(toolExecutionRequest, sTsMsg)); 549 return String.valueOf(askUserResult(toolExecutionRequest, sTsMsg));
547 } 550 }
548 551
  552 + // 2.1 【自动补全】应用参数的默认值
  553 + args = applyDefaultValues(args, paramRuleData);
  554 +
549 // 3. 【自动校验】检查必填项 555 // 3. 【自动校验】检查必填项
550 List<String> missing = checkRequiredParams(args, paramRuleData); 556 List<String> missing = checkRequiredParams(args, paramRuleData);
551 if (!missing.isEmpty()) { 557 if (!missing.isEmpty()) {
@@ -809,11 +815,10 @@ public class DynamicToolProvider implements ToolProvider { @@ -809,11 +815,10 @@ public class DynamicToolProvider implements ToolProvider {
809 Map<String, Object> result = new HashMap<>(args); 815 Map<String, Object> result = new HashMap<>(args);
810 for (ParamRule pd : paramDefs) { 816 for (ParamRule pd : paramDefs) {
811 String name = pd.getSParam(); 817 String name = pd.getSParam();
812 - if ((!result.containsKey(name)  
813 - || ObjectUtil.isEmpty(result.get(name))) 818 + if ((!result.containsKey(name)|| ObjectUtil.isEmpty(result.get(name)))
814 && ObjectUtil.isNotEmpty(pd.getSDefaultValue()) 819 && ObjectUtil.isNotEmpty(pd.getSDefaultValue())
815 - && !"enum".equals(pd.getSType())  
816 - && !"array".equals(pd.getSType()) 820 +// && !"enum".equals(pd.getSType())
  821 +// && !"array".equals(pd.getSType())
817 ) { 822 ) {
818 Object defaultValue = pd.getSDefaultValue(); 823 Object defaultValue = pd.getSDefaultValue();
819 result.put(name, defaultValue); 824 result.put(name, defaultValue);
src/main/java/com/xly/tts/bean/TTSResponseDTO.java
@@ -60,6 +60,8 @@ public class TTSResponseDTO implements Serializable { @@ -60,6 +60,8 @@ public class TTSResponseDTO implements Serializable {
60 private String sSceneName; 60 private String sSceneName;
61 //业务方法名称 61 //业务方法名称
62 private String sMethodName; 62 private String sMethodName;
  63 + //清除记忆提示
  64 + private String sCommonts;
63 65
64 private String sReturnType = ReturnTypeCode.MAKEDOWN.getCode(); 66 private String sReturnType = ReturnTypeCode.MAKEDOWN.getCode();
65 67
src/main/java/com/xly/tts/service/PythonTtsProxyService.java
@@ -2,6 +2,7 @@ package com.xly.tts.service; @@ -2,6 +2,7 @@ package com.xly.tts.service;
2 2
3 import cn.hutool.core.util.ObjectUtil; 3 import cn.hutool.core.util.ObjectUtil;
4 import cn.hutool.core.util.StrUtil; 4 import cn.hutool.core.util.StrUtil;
  5 +import com.xly.constant.BusinessCode;
5 import com.xly.constant.ReturnTypeCode; 6 import com.xly.constant.ReturnTypeCode;
6 import com.xly.entity.AiResponseDTO; 7 import com.xly.entity.AiResponseDTO;
7 import com.xly.service.UserSceneSessionService; 8 import com.xly.service.UserSceneSessionService;
@@ -149,6 +150,7 @@ public class PythonTtsProxyService { @@ -149,6 +150,7 @@ public class PythonTtsProxyService {
149 .sSceneName(aiResponseDTO.getSSceneName()) 150 .sSceneName(aiResponseDTO.getSSceneName())
150 .sMethodName (aiResponseDTO.getSMethodName()) 151 .sMethodName (aiResponseDTO.getSMethodName())
151 .sReturnType (aiResponseDTO.getSReturnType()) 152 .sReturnType (aiResponseDTO.getSReturnType())
  153 + .sCommonts(BusinessCode.COMMONTS.getMessage())
152 .timestamp(System.currentTimeMillis()) 154 .timestamp(System.currentTimeMillis())
153 .textLength(request.getText().length()) 155 .textLength(request.getText().length())
154 .build()); 156 .build());
@@ -190,6 +192,7 @@ public class PythonTtsProxyService { @@ -190,6 +192,7 @@ public class PythonTtsProxyService {
190 .sSceneName(aiResponseDTO.getSSceneName()) 192 .sSceneName(aiResponseDTO.getSSceneName())
191 .sMethodName(aiResponseDTO.getSMethodName()) 193 .sMethodName(aiResponseDTO.getSMethodName())
192 .sReturnType(aiResponseDTO.getSReturnType()) 194 .sReturnType(aiResponseDTO.getSReturnType())
  195 + .sCommonts(BusinessCode.COMMONTS.getMessage())
193 .audioFormat("audio/mpeg") 196 .audioFormat("audio/mpeg")
194 .build(); 197 .build();
195 return ResponseEntity.ok(ttsResponse); 198 return ResponseEntity.ok(ttsResponse);
@@ -213,6 +216,7 @@ public class PythonTtsProxyService { @@ -213,6 +216,7 @@ public class PythonTtsProxyService {
213 .sSceneName(aiResponseDTO.getSSceneName()) 216 .sSceneName(aiResponseDTO.getSSceneName())
214 .sMethodName (aiResponseDTO.getSMethodName()) 217 .sMethodName (aiResponseDTO.getSMethodName())
215 .sReturnType (aiResponseDTO.getSReturnType()) 218 .sReturnType (aiResponseDTO.getSReturnType())
  219 + .sCommonts(BusinessCode.COMMONTS.getMessage())
216 .build(); 220 .build();
217 return ResponseEntity.ok(ttsResponse); 221 return ResponseEntity.ok(ttsResponse);
218 } 222 }