Commit 6e789a252da3e6966b57b86ee87144991234d994
1 parent
6e76fb7b
添加未清选择 改成动态引导语
Showing
5 changed files
with
56 additions
and
49 deletions
src/main/java/com/xly/service/XlyErpService.java
| @@ -949,29 +949,37 @@ public class XlyErpService { | @@ -949,29 +949,37 @@ public class XlyErpService { | ||
| 949 | }else {return null;} | 949 | }else {return null;} |
| 950 | } | 950 | } |
| 951 | // 4. 获取/创建用Agent | 951 | // 4. 获取/创建用Agent |
| 952 | - ErpAiAgent aiAgent = UserSceneSessionService.ERP_AGENT_CACHE.get(userId); | ||
| 953 | - if(ObjectUtil.isEmpty(aiAgent)){ | ||
| 954 | - List<ToolSpecificationHolder> dataList = dynamicToolProvider.sceneToolCacheMap.get(session.getCurrentScene().getSId()); | ||
| 955 | - Set<String> immediateReturnToolNames = new HashSet<>(); | ||
| 956 | - Map<ToolSpecification, ToolExecutor> executors = new HashMap<>(); | ||
| 957 | - if(ObjectUtil.isNotEmpty(dataList)){ | ||
| 958 | - dataList.forEach(one->{ | ||
| 959 | - immediateReturnToolNames.add(one.getsName()); | ||
| 960 | - executors.put(one.getToolSpecification(),one.getToolExecutor()); | ||
| 961 | - }); | ||
| 962 | - } | ||
| 963 | - aiAgent = AiServices.builder(ErpAiAgent.class) | ||
| 964 | - .chatModel(chatModel) | ||
| 965 | - .chatMemoryProvider(operableChatMemoryProvider) | ||
| 966 | - .tools(executors,immediateReturnToolNames) | 952 | + // ErpAiAgent aiAgent = UserSceneSessionService.ERP_AGENT_CACHE.get(userId); |
| 953 | +// if(ObjectUtil.isEmpty(aiAgent)){ | ||
| 954 | + List<ToolSpecificationHolder> dataList = dynamicToolProvider.sceneToolCacheMap.get(session.getCurrentScene().getSId()); | ||
| 955 | + List<ToolSpecificationHolder> dataListOne = | ||
| 956 | + dataList.stream().filter(m-> | ||
| 957 | + userInput.equals(m.getsMethodName().trim()) || ("查询"+userInput).equals(m.getsMethodName().trim()) | ||
| 958 | + ).collect(Collectors.toUnmodifiableList()); | ||
| 959 | + | ||
| 960 | + if(ObjectUtil.isNotEmpty(dataListOne)){ | ||
| 961 | + dataList = dataListOne; | ||
| 962 | + } | ||
| 963 | + Set<String> immediateReturnToolNames = new HashSet<>(); | ||
| 964 | + Map<ToolSpecification, ToolExecutor> executors = new HashMap<>(); | ||
| 965 | + if(ObjectUtil.isNotEmpty(dataList)){ | ||
| 966 | + dataList.forEach(one->{ | ||
| 967 | + immediateReturnToolNames.add(one.getsName()); | ||
| 968 | + executors.put(one.getToolSpecification(),one.getToolExecutor()); | ||
| 969 | + }); | ||
| 970 | + } | ||
| 971 | + return AiServices.builder(ErpAiAgent.class) | ||
| 972 | + .chatModel(chatModel) | ||
| 973 | + .chatMemoryProvider(operableChatMemoryProvider) | ||
| 974 | + .tools(executors,immediateReturnToolNames) | ||
| 967 | // .toolProvider(dynamicToolProvider) | 975 | // .toolProvider(dynamicToolProvider) |
| 968 | // .returnBehavior(ReturnBehavior.IMMEDIATE) | 976 | // .returnBehavior(ReturnBehavior.IMMEDIATE) |
| 969 | // .toolChoice(ChatCompletionToolChoice.ofRequired()) | 977 | // .toolChoice(ChatCompletionToolChoice.ofRequired()) |
| 970 | - .build(); | ||
| 971 | - UserSceneSessionService.ERP_AGENT_CACHE.put(userId, aiAgent); | ||
| 972 | - log.info("用户{}Agent构建完成,已选场景:{},场景ID{}", userId, session.isSceneSelected() ? session.getCurrentScene().getSSceneName() : "未选(全场景匹配)", dynamicToolProvider.sSceneIdMap.get(userId)); | ||
| 973 | - } | ||
| 974 | - return aiAgent; | 978 | + .build(); |
| 979 | +// UserSceneSessionService.ERP_AGENT_CACHE.put(userId, aiAgent); | ||
| 980 | +// log.info("用户{}Agent构建完成,已选场景:{},场景ID{}", userId, session.isSceneSelected() ? session.getCurrentScene().getSSceneName() : "未选(全场景匹配)", dynamicToolProvider.sSceneIdMap.get(userId)); | ||
| 981 | +// } | ||
| 982 | +// return aiAgent; | ||
| 975 | } | 983 | } |
| 976 | 984 | ||
| 977 | private ErpAiAgent createConfirmeAgent(UserSceneSession session) { | 985 | private ErpAiAgent createConfirmeAgent(UserSceneSession session) { |
src/main/java/com/xly/tool/DynamicToolProvider.java
| @@ -83,14 +83,14 @@ public class DynamicToolProvider implements ToolProvider { | @@ -83,14 +83,14 @@ public class DynamicToolProvider implements ToolProvider { | ||
| 83 | doSetToolAIshowfieldShow(meta); | 83 | doSetToolAIshowfieldShow(meta); |
| 84 | ToolSpecification spec = buildToolSpecification(meta); | 84 | ToolSpecification spec = buildToolSpecification(meta); |
| 85 | ToolExecutor executor = createToolExecutor(meta); | 85 | ToolExecutor executor = createToolExecutor(meta); |
| 86 | - toolCache.put(meta.getSMethodNo(), new ToolSpecificationHolder(spec, executor,meta.getSMethodNo())); | 86 | + toolCache.put(meta.getSMethodNo(), new ToolSpecificationHolder(spec, executor,meta.getSMethodNo(),meta.getSMethodName())); |
| 87 | log.info("已加载动态工具:{}", meta.getSMethodNo()); | 87 | log.info("已加载动态工具:{}", meta.getSMethodNo()); |
| 88 | String sceneId = meta.getSSceneId(); | 88 | String sceneId = meta.getSSceneId(); |
| 89 | List<ToolSpecificationHolder> dataList = new ArrayList<>(); | 89 | List<ToolSpecificationHolder> dataList = new ArrayList<>(); |
| 90 | if(ObjectUtil.isNotEmpty(sceneToolCacheMap.get(sceneId))) { | 90 | if(ObjectUtil.isNotEmpty(sceneToolCacheMap.get(sceneId))) { |
| 91 | dataList = sceneToolCacheMap.get(sceneId); | 91 | dataList = sceneToolCacheMap.get(sceneId); |
| 92 | } | 92 | } |
| 93 | - dataList.add(new ToolSpecificationHolder(spec, executor,meta.getSMethodNo())); | 93 | + dataList.add(new ToolSpecificationHolder(spec, executor,meta.getSMethodNo(),meta.getSMethodName())); |
| 94 | sceneToolCacheMap.put(sceneId, dataList); | 94 | sceneToolCacheMap.put(sceneId, dataList); |
| 95 | } catch (Exception e) { | 95 | } catch (Exception e) { |
| 96 | e.printStackTrace(); | 96 | e.printStackTrace(); |
| @@ -1016,31 +1016,25 @@ public class DynamicToolProvider implements ToolProvider { | @@ -1016,31 +1016,25 @@ public class DynamicToolProvider implements ToolProvider { | ||
| 1016 | public String buildDynamicSystemPrompt(UserSceneSession session) { | 1016 | public String buildDynamicSystemPrompt(UserSceneSession session) { |
| 1017 | String methodNo = session.getCurrentTool().getSMethodNo(); | 1017 | String methodNo = session.getCurrentTool().getSMethodNo(); |
| 1018 | String rowJson = JSONUtil.toJsonStr(session.getCurrentRowData()); | 1018 | String rowJson = JSONUtil.toJsonStr(session.getCurrentRowData()); |
| 1019 | - | ||
| 1020 | return """ | 1019 | return """ |
| 1021 | - 【极强约束·必须执行】 | ||
| 1022 | - 1. 禁止说话!禁止解释! | ||
| 1023 | - 2. 必须调用工具! | ||
| 1024 | - 3. 只输出标准工具调用JSON! | ||
| 1025 | - | ||
| 1026 | - 表格数据: | ||
| 1027 | - %s | ||
| 1028 | - | ||
| 1029 | - 【解析规则】 | ||
| 1030 | - 1. 用户说“第N行” → 取对应sSlaveId | ||
| 1031 | - 2. 用户说“全部确认” → 取所有sSlaveId | ||
| 1032 | - 3. 多行用英文逗号拼接 | ||
| 1033 | - | ||
| 1034 | - 【输出格式·绝对严格·必须照做】 | ||
| 1035 | - 你必须输出标准工具调用JSON,只输出这一段,不许加任何文字: | ||
| 1036 | - { | ||
| 1037 | - "name": "%s", | ||
| 1038 | - "parameters": { | ||
| 1039 | - "operateType": "全部确认/合并确认/单行确认", | ||
| 1040 | - "sSlaveId": "id1,id2,id3" | ||
| 1041 | - } | ||
| 1042 | - } | ||
| 1043 | - """.formatted(rowJson, methodNo); | 1020 | + 【极强约束·必须执行】 |
| 1021 | + 1. 禁止说话!禁止解释! | ||
| 1022 | + 2. 必须调用工具! | ||
| 1023 | + 3. 只输出标准工具调用JSON! | ||
| 1024 | + | ||
| 1025 | + 表格数据(key是行号): | ||
| 1026 | + %s | ||
| 1027 | + | ||
| 1028 | + 【规则】 | ||
| 1029 | + 用户输入如"第N条数据确认",N为行号。 | ||
| 1030 | + 在表格中查找 key = N 的数据,取出 sSlaveId。 | ||
| 1031 | + | ||
| 1032 | + 【输出格式】 | ||
| 1033 | + {"name": "%s", "parameters": {"operateType": "单行确认", "sSlaveId": "取出的ID"}} | ||
| 1034 | + | ||
| 1035 | + 【警告】 | ||
| 1036 | + 禁止编造!必须从表格中提取! | ||
| 1037 | + """.formatted(rowJson, methodNo); | ||
| 1044 | } | 1038 | } |
| 1045 | 1039 | ||
| 1046 | private List<Map<String, Object>> findFieldNameByChinese(List<Map<String, Object>> sAIshowfieldShow,List<Map<String, Object>> rows){ | 1040 | private List<Map<String, Object>> findFieldNameByChinese(List<Map<String, Object>> sAIshowfieldShow,List<Map<String, Object>> rows){ |
src/main/java/com/xly/tool/ToolSpecificationHolder.java
| @@ -8,10 +8,12 @@ public class ToolSpecificationHolder { | @@ -8,10 +8,12 @@ public class ToolSpecificationHolder { | ||
| 8 | private final ToolSpecification toolSpecification; | 8 | private final ToolSpecification toolSpecification; |
| 9 | private final ToolExecutor toolExecutor; | 9 | private final ToolExecutor toolExecutor; |
| 10 | private final String sName; | 10 | private final String sName; |
| 11 | - public ToolSpecificationHolder(ToolSpecification toolSpecification, ToolExecutor toolExecutor,String sName) { | 11 | + private final String sMethodName; |
| 12 | + public ToolSpecificationHolder(ToolSpecification toolSpecification, ToolExecutor toolExecutor,String sName,String sMethodName) { | ||
| 12 | this.toolSpecification = toolSpecification; | 13 | this.toolSpecification = toolSpecification; |
| 13 | this.toolExecutor = toolExecutor; | 14 | this.toolExecutor = toolExecutor; |
| 14 | this.sName = sName; | 15 | this.sName = sName; |
| 16 | + this.sMethodName = sMethodName; | ||
| 15 | } | 17 | } |
| 16 | 18 | ||
| 17 | public ToolSpecification getToolSpecification() { | 19 | public ToolSpecification getToolSpecification() { |
| @@ -26,5 +28,8 @@ public class ToolSpecificationHolder { | @@ -26,5 +28,8 @@ public class ToolSpecificationHolder { | ||
| 26 | return sName; | 28 | return sName; |
| 27 | } | 29 | } |
| 28 | 30 | ||
| 31 | + public String getsMethodName() { | ||
| 32 | + return sMethodName; | ||
| 33 | + } | ||
| 29 | } | 34 | } |
| 30 | 35 |
src/main/java/com/xly/tts/service/PythonTtsProxyService.java
| @@ -4,7 +4,6 @@ import cn.hutool.core.util.ObjectUtil; | @@ -4,7 +4,6 @@ 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.BusinessCode; |
| 6 | import com.xly.constant.ReturnTypeCode; | 6 | import com.xly.constant.ReturnTypeCode; |
| 7 | -import com.xly.entity.AiResponseAccumulator; | ||
| 8 | import com.xly.entity.AiResponseDTO; | 7 | import com.xly.entity.AiResponseDTO; |
| 9 | import com.xly.entity.UserSceneSession; | 8 | import com.xly.entity.UserSceneSession; |
| 10 | import com.xly.service.UserSceneSessionService; | 9 | import com.xly.service.UserSceneSessionService; |
src/main/resources/application.yml
| @@ -135,7 +135,8 @@ langchain4j: | @@ -135,7 +135,8 @@ langchain4j: | ||
| 135 | ollama: | 135 | ollama: |
| 136 | # 聊天模型配置(用于一般对话) | 136 | # 聊天模型配置(用于一般对话) |
| 137 | base-url: http://112.82.245.194:11434 | 137 | base-url: http://112.82.245.194:11434 |
| 138 | - chat-model-name: qwen2.5:7b-instruct | 138 | +# chat-model-name: qwen2.5:7b-instruct |
| 139 | + chat-model-name: qwen2.5:14b | ||
| 139 | # chat-model-name: qwen3:14b | 140 | # chat-model-name: qwen3:14b |
| 140 | # chat-model-name: qwen3.5:9b | 141 | # chat-model-name: qwen3.5:9b |
| 141 | # SQL/代码模型配置(专门用于代码和SQL生成) | 142 | # SQL/代码模型配置(专门用于代码和SQL生成) |