Browse Source

新jbot2框架下修改,电视控制跑通

wjg 1 year ago
parent
commit
bbb397107d
87 changed files with 560 additions and 2001 deletions
  1. 1 1
      app/src/main/assets/cfg/domains/dmtMediaInfo/domain.json
  2. 1 1
      app/src/main/assets/cfg/domains/dmtTVControl/domain.json
  3. 1 1
      app/src/main/assets/cfg/domains/jedgeSmartHome/domain.json
  4. 1 1
      app/src/main/assets/cfg/picker/jsh/setColorMode.json
  5. 1 1
      app/src/main/assets/cfg/picker/tvctrl/setVolume.json
  6. 87 100
      app/src/main/java/com/ch/jedge/bots/jsmart/JedgeSmartHomeBot.java
  7. 60 80
      app/src/main/java/com/ch/jedge/bots/tvass/JedgeTVAssistant.java
  8. 0 60
      app/src/main/java/com/ch/jedge/glm/JGlmJava.java
  9. 10 10
      app/src/main/java/com/ch/jedge/glm/JedgeGlmBridgeService.java
  10. 17 0
      app/src/main/java/com/ch/jedge/glm/JedgeGlmDriver.java
  11. 0 25
      app/src/main/java/com/ch/jedge/glm/JedgeGlmDriverClient.java
  12. 1 1
      app/src/main/java/com/ch/jedge/glm/zhipuai/SseMeta.java
  13. 1 2
      app/src/main/java/com/ch/jedge/glm/zhipuai/StandardEventSourceListener.java
  14. 0 1
      app/src/main/java/com/ch/jedge/glm/zhipuai/TokenManagerV3.java
  15. 1 1
      app/src/main/java/com/ch/jedge/glm/zhipuai/Usage.java
  16. 0 1
      app/src/main/java/com/ch/jedge/glm/zhipuai/ZhipuStringUtils.java
  17. 0 61
      app/src/main/java/com/ch/jedge/jbot/JBotJava.java
  18. 23 0
      app/src/main/java/com/ch/jedge/jbot/JBotNewJava.java
  19. 0 67
      app/src/main/java/com/ch/jedge/jbot/JEJBotLLMConst.java
  20. 38 52
      app/src/main/java/com/ch/jedge/jbot/JedgeBotGptService.java
  21. 15 16
      app/src/main/java/com/ch/jedge/jbot/JedgeDomainTesterOld.java
  22. 0 25
      app/src/main/java/com/ch/jedge/jbot/JedgeLlmBotClient.java
  23. 0 125
      app/src/main/java/com/ch/jedge/jbot/JedgeLlmUtil.java
  24. 0 308
      app/src/main/java/com/ch/jedge/jbot/JedgeVoiceBotService.java
  25. 0 61
      app/src/main/java/com/ch/jedge/jbot/dict/JEDictUtil.java
  26. 0 82
      app/src/main/java/com/ch/jedge/jbot/dict/JedgeWordDict.java
  27. 0 17
      app/src/main/java/com/ch/jedge/jbot/dict/JedgeWordItem.java
  28. 0 12
      app/src/main/java/com/ch/jedge/jbot/intent/JDataGetter.java
  29. 0 15
      app/src/main/java/com/ch/jedge/jbot/intent/JbotApi.java
  30. 0 15
      app/src/main/java/com/ch/jedge/jbot/intent/JbotData.java
  31. 0 320
      app/src/main/java/com/ch/jedge/jbot/intent/JedgeJBotCBService.java
  32. 0 64
      app/src/main/java/com/ch/jedge/jbot/intent/bot/JBotAppBase.java
  33. 0 30
      app/src/main/java/com/ch/jedge/jbot/intent/bot/JBotAppClient.java
  34. 0 189
      app/src/main/java/com/ch/jedge/jbot/intent/param/JedgeDataSetter.java
  35. 0 11
      app/src/main/java/com/ch/jedge/jbot/intent/param/JedgeLLMParamPicker.java
  36. 3 3
      app/src/main/java/com/ch/jedge/jbot/other/agent/JedgeGdeAgentRunner.java
  37. 1 1
      app/src/main/java/com/ch/jedge/jbot/other/agent/JedgeGdeConsts.java
  38. 9 0
      app/src/main/java/com/ch/jedge/jbot/other/agent/JedgeGdeObjective.java
  39. 15 15
      app/src/main/java/com/ch/jedge/jbot/other/agent/JedgeGdeSession.java
  40. 4 0
      app/src/main/java/com/ch/jedge/jbot/other/base/JedgeLLMObject.java
  41. 4 0
      app/src/main/java/com/ch/jedge/jbot/other/base/data/JedgeCacheAction.java
  42. 4 0
      app/src/main/java/com/ch/jedge/jbot/other/base/data/JedgeCacheCard.java
  43. 4 0
      app/src/main/java/com/ch/jedge/jbot/other/base/data/JedgeCacheObject.java
  44. 4 0
      app/src/main/java/com/ch/jedge/jbot/other/base/data/JedgeNextModule.java
  45. 4 0
      app/src/main/java/com/ch/jedge/jbot/other/base/handler/JedgeInforGetter.java
  46. 4 0
      app/src/main/java/com/ch/jedge/jbot/other/base/handler/JedgeIntentComparor.java
  47. 4 0
      app/src/main/java/com/ch/jedge/jbot/other/base/handler/JedgeIntentParser.java
  48. 12 0
      app/src/main/java/com/ch/jedge/jbot/other/base/handler/JedgeLLMCall.java
  49. 8 0
      app/src/main/java/com/ch/jedge/jbot/other/base/handler/JedgeStringHandler.java
  50. 4 0
      app/src/main/java/com/ch/jedge/jbot/other/base/handler/JedgeWordCutter.java
  51. 37 0
      app/src/main/java/com/ch/jedge/jbot/other/base/readme.txt
  52. 2 2
      app/src/main/java/com/ch/jedge/jbot/other/corpus/CorpusTask.java
  53. 13 13
      app/src/main/java/com/ch/jedge/jbot/other/knbase/JedgeGptApp.java
  54. 2 2
      app/src/main/java/com/ch/jedge/jbot/other/knbase/JedgeGptDialogEngine.java
  55. 6 6
      app/src/main/java/com/ch/jedge/jbot/other/knbase/JedgeGptDomain.java
  56. 4 4
      app/src/main/java/com/ch/jedge/jbot/other/knbase/JedgeLlmIntent.java
  57. 1 1
      app/src/main/java/com/ch/jedge/jbot/other/knbase/domain/JedgeGdeDomainBlock.java
  58. 3 3
      app/src/main/java/com/ch/jedge/jbot/other/knbase/domain/JedgeGdeDomainParer.java
  59. 9 0
      app/src/main/java/com/ch/jedge/jbot/other/knbase/intent/JedgeGdeIntentParser.java
  60. 4 3
      app/src/main/java/com/ch/jedge/jbot/other/knbase/intent/JedgeGdeQuery.java
  61. 17 0
      app/src/main/java/com/ch/jedge/jbot/other/knbase/intent/readme.txt
  62. 11 0
      app/src/main/java/com/ch/jedge/jbot/other/knbase/pool/JedgeGdeIntentPool.java
  63. 8 8
      app/src/main/java/com/ch/jedge/jbot/other/knbase/pool/JedgeGdeKnItemPool.java
  64. 6 6
      app/src/main/java/com/ch/jedge/jbot/other/knbase/query/JedgeGptQueryIntent.java
  65. 5 0
      app/src/main/java/com/ch/jedge/jbot/other/llm/JedgeGdeLLMCall.java
  66. 5 4
      app/src/main/java/com/ch/jedge/jbot/other/session/JedgeGdeKeywordPool.java
  67. 7 0
      app/src/main/java/com/ch/jedge/jbot/other/session/JedgeGptTopic.java
  68. 13 4
      app/src/main/java/com/ch/jedge/jbot/session/JedgeServiceSession.java
  69. 11 6
      app/src/main/java/com/ch/jedge/jbot2/JBot2Java.java
  70. 20 10
      app/src/main/java/com/ch/jedge/jbot2/JedgeBotGptService.java
  71. 1 1
      app/src/main/java/com/ch/jedge/jbot2/context/JedgeSmartTaskContext.java
  72. 1 1
      app/src/main/java/com/ch/jedge/jbot2/llm/pickers/JedgeSmartHomeActionPicker.java
  73. 3 0
      app/src/main/java/com/ch/jedge/jbot2/llm/request/JedgeLLMCOTRequest.java
  74. 2 1
      app/src/main/java/com/ch/jedge/jbot2/llm/request/JedgeLLMFilterRequest.java
  75. 3 2
      app/src/main/java/com/ch/jedge/jbot2/llm/request/JedgeLLMRequest.java
  76. 1 1
      app/src/main/java/com/ch/jedge/jbot2/llm/world/knl/JedgeDomainSelector.java
  77. 1 1
      app/src/main/java/com/ch/jedge/jbot2/llm/world/knl/JedgeLLMKnWorld.java
  78. 1 1
      app/src/main/java/com/ch/jedge/jbot2/llm/world/knl/task/JedgeContentCutter.java
  79. 1 1
      app/src/main/java/com/ch/jedge/jbot2/llm/world/model/JedgeMdDomain.java
  80. 1 1
      app/src/main/java/com/ch/jedge/jbot2/llm/world/task/JedgeTaskTester.java
  81. 1 1
      app/src/main/java/com/ch/jedge/llm/filter/glm/MainActivity.java
  82. 3 2
      app/src/main/java/com/ch/jedge/llm/filter/glm/service/JBotService.java
  83. 2 2
      app/src/main/java/com/ch/jedge/llm/filter/glm/service/JGlmService.java
  84. 8 2
      app/src/main/java/com/ch/jedge/tvmufis/JeageTVBridge.java
  85. 4 8
      app/src/main/java/com/ch/jedge/tvmufis/TvMufis.java
  86. 0 128
      app/src/main/java/com/ch/jedge/utils/JEVdbConfigUtil.java
  87. 1 1
      app/src/main/java/com/ch/jedge/utils/JedgeBotConst.java

+ 1 - 1
app/src/main/assets/cfg/domains/dmtMediaInfo/domain.json

@@ -1,5 +1,5 @@
 {
   "key": "MediaInfo",
-  "picker": "./cfg/picker/mediaAcc",
+  "picker": "/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/picker/mediaAcc",
   "disc": "电影,电视,音乐,纪录片,动画片等各类影视剧的媒体信息查询,播放,包括片名,出品制作方,导演,主要演员,片子简介,剧情简介,包括对U盘或移动硬盘和电视内的媒体文件进行搜索、文件操作或相互拷贝,弹出U盘或移动硬盘等媒体内容相关的外设操作。"
 }

+ 1 - 1
app/src/main/assets/cfg/domains/dmtTVControl/domain.json

@@ -1,5 +1,5 @@
 {
   "key": "TVControl",
-  "picker": "./cfg/picker/tvctrl",
+  "picker": "/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/picker/tvctrl",
   "disc": "电视机的控制和设置等功能,包括音量设置,屏幕设置,电视屏幕的色彩模式设置,频道选择,内容推荐,信号源控制等相关的指令,但是不要包括家居控制或媒体影片等信息。"
 }

+ 1 - 1
app/src/main/assets/cfg/domains/jedgeSmartHome/domain.json

@@ -1,5 +1,5 @@
 {
   "key": "JedgeSmartHome",
-  "picker": "./cfg/picker/jsh",
+  "picker": "/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/picker/jsh",
   "disc": "通过指令或场景,对一些具体设备进行操作,包括灯,锁,窗帘,插座,开关,空调的一次或者连续多次的操作。但不包含电视本身的控制操作。"
 }

+ 1 - 1
app/src/main/assets/cfg/picker/jsh/setColorMode.json

@@ -2,7 +2,7 @@
   "key":"setColorMode",
   "title":"设置颜色",
   "cmd":"从给定数据中提取恰当的参数",
-  "fmt":"{\"hue\":颜色值}",
+  "fmt":"{\"lightness\":65535,\"hue\":颜色值}",
   "prefix":"用户可以选择的颜色有红,橙,黄,绿,青,蓝,紫",
   "targets":"颜色参数",
   "datasets": [

+ 1 - 1
app/src/main/assets/cfg/picker/tvctrl/setVolume.json

@@ -3,5 +3,5 @@
   "cmd":"从给定数据中提取音量的值",
   "fmt":"{\"volume\":音量值}",
   "prefix":"音量是指电视的音量大小",
-  "targets":"音量是从0-100,0表示静音,1是最音量,模糊变化增减量为10"
+  "targets":"音量是从0-100,0表示静音,1是最音量,变化增减量为10"
 }

+ 87 - 100
app/src/main/java/com/ch/jedge/bots/jsmart/JedgeSmartHomeBot.java

@@ -3,11 +3,8 @@ package com.ch.jedge.bots.jsmart;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.ch.jedge.jbot.intent.JDataGetter;
-import com.ch.jedge.jbot.intent.JbotApi;
-import com.ch.jedge.jbot.intent.JbotData;
-import com.ch.jedge.jbot.intent.JedgeJBotCBService;
-import com.ch.jedge.jbot.intent.bot.JBotAppBase;
+import com.ch.jedge.jbot2.intent.*;
+import com.ch.jedge.jbot2.intent.bot.JBotAppBase;
 import com.changhong.jedge.JMgbusModual;
 import com.changhong.jedge.JMgbusUtil;
 import com.changhong.jedge.MgbusApi;
@@ -17,30 +14,81 @@ import com.changhong.qlib.intf.QIData;
 import java.util.ArrayList;
 import java.util.List;
 
-public class JedgeSmartHomeBot  extends JBotAppBase {
+public class JedgeSmartHomeBot extends JBotAppBase {
 
     public JedgeSmartHomeBot(String botName) {
         super(botName);
     }
 
+    @JedgeDomain( domains = "/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/domains/jedgeSmartHome")
     public static class JedgeSmartHomeService extends JedgeJBotCBService {
-        private static final String sval_domain_dev_ctrl_ = "控制设备";
-//        private static final String sval_domain_scene_ctrl_ = "场景控制";
+        private static final String sval_domain_dev_ctrl_ = "JedgeSmartHome";
         private static String cfg_path;
+
         public JedgeSmartHomeService(JMgbusModual holder) {
             super(holder);
         }
 
-//        @MgbusApi
-//        @JbotApi( domain = sval_domain_scene_ctrl_, disc="对家庭的已命名场景进行激活或触发",
-//                dataset = "场景名称",
-//                role="长虹超脑助手",
-//                msgFmt = "{\"name\":\"场景名称\"}")
-//        public QIData sceneCall(QIData eMsg) {
-//            eMsg.removeKey("~c");
-//            module.warnLog("Remote call %s", eMsg);
-//            return postServiceRequest("coss", "/system/activateScenebyName", eMsg);
-//        }
+        //设备控制JBOT回调API
+        @MgbusApi
+        @JbotApi( domain = sval_domain_dev_ctrl_)
+        public QIData devCtrl(QIData eMsg) {
+            eMsg.removeKey("~c");
+            module.warnLog("Remote call %s", eMsg);
+            try {
+                String cmd = eMsg.getString("command");
+                if(cmd==null) {
+                    return JMgbusUtil.MgbusResult(401,"控制失败");
+                }
+                switch (cmd) {
+                    case "setLightTemperature":
+                        cmd = "setColorTemperature";
+                        break;
+                    default:
+                        break;
+                }
+                QIData req = new QData().putString("command",cmd);
+
+                JSONArray params = eMsg.getJsonArray("param");
+                if (params != null) {
+                    QIData pp = new QData();
+                    for(Object param : params) {
+                        if(param instanceof String) {
+                            String[] paramSet = ((String) param).split("=");
+                            if(paramSet.length>=2) {
+                                String k = paramSet[0];
+                                String v = paramSet[1];
+                                switch (k) {
+                                    case "device_name":
+                                    case "device_location":
+                                    case "device_type":
+                                        req.putString(k, v);
+                                        break;
+                                    default:try {
+                                        pp.put(k, JSON.parse(v));
+                                    } catch (Exception e) {
+                                        e.printStackTrace();
+                                    } break;
+                                }
+                            }
+
+                        }
+                    }
+                    req.put("param", pp);
+                }
+                module.highLog("发送消息(coss):%s",req);
+                return postServiceRequest("coss", "/device/controlDevice", req);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            return JMgbusUtil.MgbusResult(401,"控制失败");
+        }
+
+        @JDataGetter
+        @JbotClass( domain = sval_domain_dev_ctrl_, words = "对象说明")
+        public List<String> devTypeList() {
+            return loadClassInfoFromFile(cfg_path+"/domains/jedgeSmartHome/classes");
+        }
 
         /**
          *   返回 : 返回命令参数
@@ -48,7 +96,7 @@ public class JedgeSmartHomeBot  extends JBotAppBase {
          * @return JSONArray
          */
         @JDataGetter
-        @JbotData( domain = sval_domain_dev_ctrl_, words = "场景名称")
+        @JbotObject( domain = sval_domain_dev_ctrl_, words = "scene")
         public List<String> sceneList() {
             List<String> re = new ArrayList<>();
             QIData p = postServiceRequest("coss", "/system/getSceneList", null);
@@ -58,7 +106,11 @@ public class JedgeSmartHomeBot  extends JBotAppBase {
                     for(Object item : payload) {
                         if(item instanceof JSONObject) {
                             String sceneName = ((JSONObject) item).getString("name");
-                            re.add(new QData().setKey(sceneName).putString("disc", String.format("触发条件:%s", "指令")).toJSONString());
+                            String runType = "manual".equals(((JSONObject) item).getString("runType"))?
+                                    "指令":"条件";
+                            re.add(new QData().setName(sceneName).setKey(sceneName)
+                                    .putString("disc", String.format("场景:%s, 触发条件:%s", sceneName, runType))
+                                    .toJSONString());
                         }
                     }
                 }
@@ -68,71 +120,7 @@ public class JedgeSmartHomeBot  extends JBotAppBase {
             return re;
         }
 
-        //设备控制JBOT回调API
-        @MgbusApi
-        @JbotApi( domain = sval_domain_dev_ctrl_,
-                disc="对一些具体设备进行操作,包括灯,锁,窗帘,插座,开关,空调的一次或者连续多次的操作",
-//                dataset = "设备名称,房间名称,设备类型,命令清单",
-                dataset = "设备名称,房间名称,设备类型,命令清单,场景名称",
-                role="长虹超脑助手",
-//                msgFmt = "[{\"command\":\"命令清单\",\"param\":[\"name=设备名称\",\"room=房间名称\",\"type=设备类型\",\"set_value=亮度或色温取值\",\"hue=颜色取值\"]}]"
-                msgFmt = "[{\"command\":\"命令清单\",\"param\":[\"设备名称\",\"房间名称\",\"设备类型\",\"额外参数关键字=参数取值\"]}]"
-        )
-        public QIData devCtrl(QIData eMsg) {
-            eMsg.removeKey("~c");
-            module.warnLog("Remote call %s", eMsg);
-            try {
-                JSONArray params = eMsg.getJsonArray("param");
-                if (params != null) {
-                    String cmd = eMsg.getString("command");
-                    switch (cmd) {
-                        case "setLightTemperature":
-                            cmd = "setColorTemperature";
-                            break;
-                        default:
-                            break;
-                    }
-                    QIData req = new QData().putString("command",cmd);
-                    Object name = params.get(0);
-                    if(name instanceof String)
-                        req.put("device_name", name);
-//                    Object room = params.get(1);
-//                    if(room instanceof String)
-//                        req.put("device_location", room);
-//                    Object type = params.get(2);
-//                    if(type instanceof String)
-//                        req.put("device_type", type);
-                    if(params.size()>3) {
-                        Object exParam = params.get(3);
-                        if (exParam instanceof String) {
-                            QIData param = new QData();
-                            String[] paramSet = ((String) exParam).split("=");
-                            if (paramSet.length > 1) {
-                                String key = paramSet[0];
-                                String val = paramSet[1];
-                                param.put(key, JSON.parse(val));
-                                req.put("param", param);
-                                if("hue".equals(key))
-                                    param.put("lightness",65535);
-                            }
-                        }
-                    }
-                    module.highLog("发送消息(coss):%s",req);
-                    return postServiceRequest("coss", "/device/controlDevice", req);
-                }
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            return JMgbusUtil.MgbusResult(401,"控制失败");
-        }
-
-        @JDataGetter
-        @JbotData( domain = sval_domain_dev_ctrl_, words = "命令清单", nullable = false)
-        public List<String> commandList() {
-            return loadDataSetFromFile(cfg_path+"/dataset/smarthome/sh_cmd_list.json");
-        }
-
-        @JbotData( domain = sval_domain_dev_ctrl_, words = "房间名称")
+        @JbotObject( domain = sval_domain_dev_ctrl_, words = "room")
         @JDataGetter
         public List<String> roomList() {
             List<String> re = new ArrayList<>();
@@ -144,12 +132,16 @@ public class JedgeSmartHomeBot  extends JBotAppBase {
                     JSONArray usr = payload.getJSONArray("user_location");
                     for(Object item : dft) {
                         if(item instanceof String) {
-                            re.add(new QData().setKey((String) item).putString("disc", "默认房间").toJSONString());
+                            re.add(new QData().setName((String) item).setKey((String) item)
+                                    .putString("disc", "默认房间")
+                                    .toJSONString());
                         }
                     }
                     for(Object item : usr) {
                         if(item instanceof String) {
-                            re.add(new QData().setKey((String) item).toJSONString());
+                            re.add(new QData().setKey((String) item).setName((String) item)
+                                    .putString("disc", String.format("(房间:%s)", item))
+                                    .toJSONString());
                         }
                     }
                 }
@@ -159,13 +151,7 @@ public class JedgeSmartHomeBot  extends JBotAppBase {
             return re;
         }
 
-        @JDataGetter
-        @JbotData( domain = sval_domain_dev_ctrl_, words = "设备类型")
-        public List<String> devTypeList() {
-            return loadDataSetFromFile(cfg_path+"/dataset/smarthome/device_types.json");
-        }
-
-        @JbotData( domain = sval_domain_dev_ctrl_, words = "设备名称")
+        @JbotObject( domain = sval_domain_dev_ctrl_, words = "name")
         @JDataGetter
         public List<String> devNameList() {
             List<String> re = new ArrayList<>();
@@ -175,16 +161,18 @@ public class JedgeSmartHomeBot  extends JBotAppBase {
                 if(payload!=null) {
                     for(Object item : payload) {
                         if(item instanceof JSONObject) {
-//                        boolean isLocal = StringUtils.isNotValidStr(((JSONObject) item).getString("other_panel"));
-//                        if(isLocal) {
                             String devName = ((JSONObject) item).getString("nick_name");
                             String devType = ((JSONObject) item).getString("device_type");
                             String devRoom = ((JSONObject) item).getString("device_location");
-                            String devInfo = new QData().setKey(devName).putString("disc", String.format("类型:%s,房间:%s)", devType, devRoom)).toJSONString();
+                            String devInfo = new QData()
+                                    .setKey(devName)
+                                    .setName(devName)
+                                    .putString("class", devType)
+                                    .putString("房间", devRoom)
+                                    .putString("disc", String.format("%s(class:%s,房间:%s)",devName,devType,devRoom))
+                                    .toJSONString();
                             re.add(devInfo);
                             module.exMarkLog("设备信息=%s", devInfo);
-
-//                        }
                         }
                     }
                 }
@@ -193,7 +181,6 @@ public class JedgeSmartHomeBot  extends JBotAppBase {
             }
             return re;
         }
-
     }
 
     public static void jssmart_main(String[] args, String cfgpath) {

+ 60 - 80
app/src/main/java/com/ch/jedge/bots/tvass/JedgeTVAssistant.java

@@ -1,16 +1,13 @@
 package com.ch.jedge.bots.tvass;
 
-import android.content.Context;
-import android.media.AudioManager;
-import android.util.Log;
-
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.ch.jedge.jbot.intent.JDataGetter;
-import com.ch.jedge.jbot.intent.JbotApi;
-import com.ch.jedge.jbot.intent.JbotData;
-import com.ch.jedge.jbot.intent.JedgeJBotCBService;
-import com.ch.jedge.jbot.intent.bot.JBotAppBase;
+import com.ch.jedge.jbot2.intent.JDataGetter;
+import com.ch.jedge.jbot2.intent.JbotApi;
+import com.ch.jedge.jbot2.intent.JbotObject;
+import com.ch.jedge.jbot2.intent.JedgeDomain;
+import com.ch.jedge.jbot2.intent.JedgeJBotCBService;
+import com.ch.jedge.jbot2.intent.bot.JBotAppBase;
 import com.ch.jedge.tvmufis.JeageTVBridge;
 import com.changhong.jedge.JMgbusModual;
 import com.changhong.jedge.JMgbusUtil;
@@ -18,51 +15,42 @@ import com.changhong.jedge.MgbusApi;
 import com.changhong.qlib.QData;
 import com.changhong.qlib.intf.QIData;
 
+import java.util.ArrayList;
 import java.util.List;
 
 public class JedgeTVAssistant extends JBotAppBase {
 
+    @JedgeDomain( domains = "/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/domains/dmtTVControl"
+            + ",/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/domains/dmtMediaInfo")
     public static class JedgeTVAssService extends JedgeJBotCBService {
-        private static final String sval_domain_tv_ctrl_ = "电视控制";
-        private static final String sval_domain_media_play_ = "媒体信息";
-
-        private static String cfg_path;
+        private static final String sval_domain_tv_ctrl_ = "TVControl";
+        private static final String sval_domain_media_play_ = "MediaInfo";
 
         public JedgeTVAssService(JMgbusModual holder) {
             super(holder);
         }
 
         @MgbusApi
-        @JbotApi( domain = sval_domain_media_play_,
-                disc="电影,电视,音乐,纪录片,动画片等各类影视剧的媒体信息查询,播放,包括片名,出品制作方,导演,主要演员,片子简介,剧情简介,包括对U盘或移动硬盘和电视内的媒体文件进行搜索、文件操作或相互拷贝、弹出U盘或移动硬盘等操作。",
-                role="电视超脑助手",
-                dataset = "媒体指令,媒体名称,播放模式",
-                msgFmt = "[{\"command\":\"媒体指令\",\"param\":[\"content=媒体名称\",\"file=拷贝文件\",\"mode=播放模式\",……]}]"
-        )
+        @JbotApi(domain = sval_domain_media_play_)
         public QIData tvPlay(QIData eMsg) {
             eMsg.removeKey("~c");
             //
             module.warnLog("Remote call %s", eMsg);
             String cmd = eMsg.getString("command");
-            JSONArray param = eMsg.getJsonArray("param");
+            JSONObject param = eMsg.getJsonObject("param");
             if("miPlay".equals(cmd))
                 playMedia(param);
             return JMgbusUtil.MgbusResult(200, "已知悉,但暂未实现完整功能");
         }
 
         @MgbusApi
-        @JbotApi( domain = sval_domain_tv_ctrl_,
-                disc="电视机的控制和设置等功能,频道选择,内容推荐,信号源控制等指令,但是不包括媒体影片等信息.",
-                role="电视超脑助手",
-                dataset = "电视指令",
-                msgFmt = "[{\"command\":\"电视指令\",\"param\":[\"额外关键字\",……]}]"
-        )
-        public QIData tvAsk(QIData eMsg) {
+        @JbotApi( domain = sval_domain_tv_ctrl_)
+        public QIData tvCtrl(QIData eMsg) {
             eMsg.removeKey("~c");
             //
             module.warnLog("Remote call %s", eMsg);
             String cmd = eMsg.getString("command");
-            JSONArray param = eMsg.getJsonArray("param");
+            JSONObject param = eMsg.getJsonObject("params");
             if("setVolume".equals(cmd))
                 setVolume(param);
 //            else if("switchSource".equals(cmd))
@@ -77,22 +65,34 @@ public class JedgeTVAssistant extends JBotAppBase {
             return JMgbusUtil.MgbusResult(200, "已知悉,但暂未实现完整功能");
         }
 
-        @JbotData( domain = sval_domain_media_play_, words = "媒体指令", nullable = false)
+        @JbotObject( domain = sval_domain_media_play_, words = "name")
         @JDataGetter
-        public List<String> mediaAccessTopics() {
-            return loadDataSetFromFile(cfg_path+"/dataset/tvass/media_cmdlist.json");
+        public List<String> mediaNameList() {
+            List<String> re = new ArrayList<>();
+            addTVCtrlDeviceDef(re,"媒体咨询","媒体咨询接口", "咨询和播放网络流媒体");
+            addTVCtrlDeviceDef(re,"U 盘控制器","U 盘控制器", "咨询和播放U盘中的内容");
+            return re;
         }
 
-        @JbotData( domain = sval_domain_tv_ctrl_, words = "电视指令", nullable = false)
+        @JbotObject( domain = sval_domain_tv_ctrl_, words = "name")
         @JDataGetter
-        public List<String> commandList() {
-            return loadDataSetFromFile(cfg_path+"/dataset/tvass/tv_cmd_list.json");
+        public List<String> tvCtrlNameList() {
+            List<String> re = new ArrayList<>();
+            addTVCtrlDeviceDef(re,"音量控制","音量控制器", "调节电视音量大小的设备");
+            addTVCtrlDeviceDef(re,"源控制","源控制器", "电视输入源控制");
+            addTVCtrlDeviceDef(re,"屏幕控制","屏幕控制", "控制屏幕的亮度,颜色等");
+            return re;
         }
 
-        @JbotData( domain = sval_domain_media_play_, words = "播放模式", nullable = false)
-        @JDataGetter
-        public List<String> playMode() {
-            return loadDataSetFromFile(cfg_path+"/dataset/tvass/tv_play_mode.json");
+        private void addTVCtrlDeviceDef(List<String> re, String ctrlName,String objClass, String disc) {
+            String devInfo = new QData()
+                    .setKey(ctrlName)
+                    .setName(ctrlName)
+                    .putString("class", objClass)
+                    .putString("disc", String.format("%s(class:%s,功能:%s)", ctrlName, objClass, disc))
+                    .toJSONString();
+            re.add(devInfo);
+            module.exMarkLog("设备信息=%s", devInfo);
         }
     }
 
@@ -101,29 +101,20 @@ public class JedgeTVAssistant extends JBotAppBase {
     }
 
     public static void TVAss_main(String[] args, String cfgpath) {
-        JedgeTVAssistant.JedgeTVAssService.cfg_path = cfgpath;
+//        JedgeTVAssistant.JedgeTVAssService.cfg_path = cfgpath;
         run("tvass", JedgeTVAssService.class, args);
     }
 
-    private static void setVolume(JSONArray param) {
+    private static void setVolume(JSONObject param) {
         if(param.isEmpty())
             return;
 
-        int cnt = param.size();
-        for(int i=0; i<cnt; i+=2){
-            Object obj = param.get(i);
-            if (obj instanceof String) {
-                if("volume".equals(obj)) {
-                    int volume = param.getIntValue(i+1);
-                    JeageTVBridge tvBridge = JeageTVBridge.getInstance();
-                    tvBridge.TVsetVolume(volume);
-                    return;
-                }
-            }
-        }
+        int volume = param.getIntValue("volume");
+        JeageTVBridge tvBridge = JeageTVBridge.getInstance();
+        tvBridge.TVsetVolume(volume);
     }
 
-//    private static void switchSource(JSONArray param) {
+//    private static void switchSource(JSONObject param) {
 //        if(param.isEmpty())
 //            return;
 //
@@ -134,47 +125,36 @@ public class JedgeTVAssistant extends JBotAppBase {
 //            tvBridge.TVsetInputSource(source);
 //        }
 //    }
-    private static void setDisplay(JSONArray param) {
+    private static void setDisplay(JSONObject param) {
         if(param.isEmpty())
             return;
 
-        int cnt = param.size();
-        for(int i=0; i<cnt; i+=2){
-            Object obj = param.get(i);
-            if (obj instanceof String) {
-                if("lightness".equals(obj)) {
-                    int value = param.getIntValue(i+1);
-                    JeageTVBridge tvBridge = JeageTVBridge.getInstance();
-                    tvBridge.TVsetBrightness(value);
-                    return;
-                }
-            }
+        String setItem = param.getString("item");
+        if("亮度".equals(setItem)) {
+            int value = param.getIntValue("param");
+            JeageTVBridge tvBridge = JeageTVBridge.getInstance();
+            tvBridge.TVsetBrightness(value);
         }
     }
 
-    private static void setSound(JSONArray param) {
+    private static void setSound(JSONObject param) {
         if(param.isEmpty())
             return;
 
-        Object obj = param.get(0);
-        if (obj instanceof String) {
-            String mode = obj.toString();
-            JeageTVBridge tvBridge = JeageTVBridge.getInstance();
-            tvBridge.TVsetSoundMode(mode);
-        }
+        String mode = param.getString("mode");
+        JeageTVBridge tvBridge = JeageTVBridge.getInstance();
+        tvBridge.TVsetSoundMode(mode);
     }
-    private static void setPicture(JSONArray param) {
+    private static void setPicture(JSONObject param) {
         if(param.isEmpty())
             return;
 
-        Object obj = param.get(0);
-        if (obj instanceof String) {
-            String mode = obj.toString();
-            JeageTVBridge tvBridge = JeageTVBridge.getInstance();
-            tvBridge.TVsetPictureMode(mode);
-        }
+        String mode = param.getString("mode");
+        JeageTVBridge tvBridge = JeageTVBridge.getInstance();
+        tvBridge.TVsetPictureMode(mode);
+
     }
-    private static void playMedia(JSONArray param) {
+    private static void playMedia(JSONObject param) {
         if(param.isEmpty())
             return;
 

+ 0 - 60
app/src/main/java/com/ch/jedge/glm/JGlmJava.java

@@ -1,60 +0,0 @@
-package com.ch.jedge.glm;
-
-import static com.ch.jedge.jbot.JEJBotLLMConst.sval_modual_glm_llm;
-
-import com.ch.jedge.utils.JEVdbConfigUtil;
-import com.changhong.qlib.QData;
-import com.changhong.qlib.intf.QIData;
-import com.changhong.qlib.util.cmdline.ArgUtils;
-import com.changhong.qlib.util.cmdline.CmdUtils;
-import com.changhong.qlib.util.sync.SystemUtils;
-
-public class JGlmJava extends QData implements CmdUtils.CmdController {
-
-    private static final JGlmJava instance = new JGlmJava(sval_modual_glm_llm);
-
-    public JGlmJava(String botName) {
-        setName(botName);
-    }
-
-    @Override
-    public String getControllerName() {
-        return getName();
-    }
-
-    @Override
-    public void setControllerName(String s) {
-        setName(s);
-    }
-
-
-    public static void glm_main(String[] args) {
-
-        JEVdbConfigUtil.loadConfigs();
-
-        JedgeGlmDriverClient llmDriver = JedgeGlmDriverClient.getInstance();
-
-        QIData param = ArgUtils.handleArgVList(args);
-
-        //加载mgbus的服务器配置参数
-        boolean runBack = JEVdbConfigUtil.setupInitConfigs(llmDriver, param, sval_modual_glm_llm);
-
-        if(!llmDriver.start()) {
-            llmDriver.errLog("Fail to start ap app : " + llmDriver.getName());
-            return;
-        }
-
-        while(!llmDriver.isActive()) {
-            //等待接入成功
-            llmDriver.warnLog("Wait for apApp to connect to mgbus : " + llmDriver.getName());
-            SystemUtils.tryWait(2000);
-        }
-
-        CmdUtils.run(instance, runBack, param);
-
-        llmDriver.shutdown();
-
-        JEVdbConfigUtil.releaseConfigs();
-    }
-
-}

+ 10 - 10
app/src/main/java/com/ch/jedge/glm/JedgeGlmBridgeService.java

@@ -22,12 +22,12 @@ import java.io.IOException;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 
-import static com.ch.jedge.jbot.JEJBotLLMConst.ival_mufis_text_message_gap_time_;
-import static com.ch.jedge.jbot.JEJBotLLMConst.sval_glm_config_filename;
+import static com.ch.jedge.utils.JedgeBotConst.ival_mufis_text_message_gap_time_;
+import static com.ch.jedge.utils.JedgeBotConst.sval_glm_config_filename;
 
 public class JedgeGlmBridgeService extends JMgbusService {
 
-//    static final QIData QIData_DefaultConfig = QData.fromFile(sval_glm_config_filename);
+    static final QIData QIData_DefaultConfig = QData.fromFile(sval_glm_config_filename);
 
     private ConfigV3 zhipuConfig;
     private ICache tokenCache;
@@ -46,14 +46,15 @@ public class JedgeGlmBridgeService extends JMgbusService {
     private String sval_glm_model_std = "chatglm_std";
     private String sval_glm_model_lite = "chatglm_std";
     private String sval_glm_model_lite32 = "chatglm_lite_32k";
+
     private String intentModel = sval_glm_model_pro;
+    private static final float fval_temperature = 0.9f;
+    private static final float fval_top_p = 0.7f;
 
 
     private final Queue<QIData> ret_msgs_ = new LinkedList<>();
     private boolean quit_ = false;
     private boolean active_ = false;
-    private static final float fval_temperature = 0.9f;
-    private static final float fval_top_p = 0.7f;
 
     public JedgeGlmBridgeService(JMgbusModual holder) {
         super(holder);
@@ -76,10 +77,8 @@ public class JedgeGlmBridgeService extends JMgbusService {
         quit_ = false;
 
         zhipuConfig = new ConfigV3();
-//        zhipuConfig.setApiKey("297ba886b74433514543eac6ff485ddf"); // QIData_DefaultConfig.getString("ApiKey");
-//        zhipuConfig.setApiSecret("yKwpPFiUmreQd5Vq");              // QIData_DefaultConfig.getString("ApiSecret");
-        zhipuConfig.setApiKey("233bd55079e5f14ca868d0c1c92b52cb");
-        zhipuConfig.setApiSecret("i8gP3u3LQB58KDGM");
+        zhipuConfig.setApiKey("297ba886b74433514543eac6ff485ddf"); // QIData_DefaultConfig.getString("ApiKey");
+        zhipuConfig.setApiSecret("yKwpPFiUmreQd5Vq");              // QIData_DefaultConfig.getString("ApiSecret");
         zhipuConfig.setCache(LocalCache.getInstance());
         zhipuConfig.setDisableTokenCache(false);
 
@@ -142,7 +141,8 @@ public class JedgeGlmBridgeService extends JMgbusService {
             return JMgbusUtil.MgbusResult(401,"Empty query string");
         String sid = String.valueOf(eMsg.getInteger("sid", NumberUtils.randomInt(100000)));
         String srcMod = JMgbusUtil.GetMgModSource(eMsg);
-
+        if(StringUtils.isNotValidStr(srcMod))
+            srcMod = module.getName();
         // url
         Map<String, String> pathParams = new HashMap<>();
         pathParams.put("model", intentModel);

+ 17 - 0
app/src/main/java/com/ch/jedge/glm/JedgeGlmDriver.java

@@ -0,0 +1,17 @@
+package com.ch.jedge.glm;
+
+import com.ch.jedge.jbot2.intent.bot.JBotAppBase;
+
+import static com.ch.jedge.utils.JedgeBotConst.sval_default_glm6b_service;
+
+public class JedgeGlmDriver extends JBotAppBase {
+
+    public JedgeGlmDriver(String botName) {
+        super(botName);
+    }
+
+    public static void glm_main(String[] args) {
+          run("llm", sval_default_glm6b_service, JedgeGlmBridgeService.class, args);
+    }
+
+}

+ 0 - 25
app/src/main/java/com/ch/jedge/glm/JedgeGlmDriverClient.java

@@ -1,25 +0,0 @@
-package com.ch.jedge.glm;
-
-import com.changhong.jedge.JMgbusClient;
-
-import static com.ch.jedge.jbot.JEJBotLLMConst.sval_default_glm6b_service;
-import static com.ch.jedge.jbot.JEJBotLLMConst.sval_modual_glm_llm;
-
-public class JedgeGlmDriverClient extends JMgbusClient {
-
-    static private JedgeGlmDriverClient glmDriverClient;
-
-    public JedgeGlmDriverClient(String subnet, String mgc_name, int threadCount, boolean tryLocal) {
-        super(subnet, mgc_name, threadCount, tryLocal);
-    }
-
-    public static JedgeGlmDriverClient getInstance() {
-        if(glmDriverClient == null) {
-            glmDriverClient = new JedgeGlmDriverClient("#0", sval_modual_glm_llm, 10, true);
-            JedgeGlmBridgeService service = new JedgeGlmBridgeService(glmDriverClient);
-            glmDriverClient.bindService(sval_default_glm6b_service, service);
-        }
-        return glmDriverClient;
-    }
-
-}

+ 1 - 1
app/src/main/java/com/ch/jedge/glm/zhipuai/SseMeta.java

@@ -51,4 +51,4 @@ public class SseMeta {
     public void setUsage(Usage usage) {
         this.usage = usage;
     }
-}
+}

+ 1 - 2
app/src/main/java/com/ch/jedge/glm/zhipuai/StandardEventSourceListener.java

@@ -60,8 +60,7 @@ public class StandardEventSourceListener extends ModelEventSourceListener {
         qData.putString("~m", srcMod);
         qData.putString("delta", formatData);
         qData.putBoolean("finished", is_finish);
-//        service.putMgbusMessage(qData);
-        service.postServiceMessage(srcMod, "/gpt/LocalStream", qData);
+        service.putMgbusMessage(qData);
         if (this.isIncremental()) {
             outputText += data;
         } else {

+ 0 - 1
app/src/main/java/com/ch/jedge/glm/zhipuai/TokenManagerV3.java

@@ -1,7 +1,6 @@
 package com.ch.jedge.glm.zhipuai;
 
 import com.auth0.jwt.JWT;
-import com.auth0.jwt.JWTCreator;
 import com.auth0.jwt.algorithms.Algorithm;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

+ 1 - 1
app/src/main/java/com/ch/jedge/glm/zhipuai/Usage.java

@@ -64,4 +64,4 @@ public class Usage {
         this.totalChars = totalChars;
     }
 
-}
+}

+ 0 - 1
app/src/main/java/com/ch/jedge/glm/zhipuai/ZhipuStringUtils.java

@@ -1,6 +1,5 @@
 package com.ch.jedge.glm.zhipuai;
 
-import java.util.Comparator;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;

+ 0 - 61
app/src/main/java/com/ch/jedge/jbot/JBotJava.java

@@ -1,61 +0,0 @@
-package com.ch.jedge.jbot;
-
-import com.ch.jedge.utils.JEVdbConfigUtil;
-import com.changhong.qlib.QData;
-import com.changhong.qlib.intf.QIData;
-import com.changhong.qlib.util.cmdline.ArgUtils;
-import com.changhong.qlib.util.cmdline.CmdUtils;
-import com.changhong.qlib.util.sync.SystemUtils;
-
-import static com.ch.jedge.jbot.JEJBotLLMConst.sval_default_jbot_jedge;
-public class JBotJava  extends QData implements CmdUtils.CmdController {
-
-    private static final JBotJava instance = new JBotJava(sval_default_jbot_jedge);
-
-    public JBotJava(String botName) {
-        setName(botName);
-    }
-
-    @Override
-    public String getControllerName() {
-        return getName();
-    }
-
-    @Override
-    public void setControllerName(String s) {
-        setName(s);
-    }
-
-
-    public static void jbot_main(String[] args) {
-
-        JEVdbConfigUtil.loadConfigs();
-
-        JedgeLlmBotClient jbot = JedgeLlmBotClient.getInstance();
-
-        QIData param = ArgUtils.handleArgVList(args);
-        boolean runBack = JEVdbConfigUtil.setupInitConfigs(jbot, param, sval_default_jbot_jedge);
-
-        if(!jbot.start()) {
-            jbot.errLog("Fail to start ap app : " + jbot.getName());
-            return;
-        }
-
-        while(!jbot.isActive()) {
-            //等待接入成功
-            jbot.warnLog("Wait for apApp to connect to mgbus : " + jbot.getName());
-            SystemUtils.tryWait(2000);
-        }
-//
-//        try {
-//            botService = (JedgeBotGptService) jbot.findService(sval_default_gpt_service);
-//        } catch (Exception ignored) {}
-
-        CmdUtils.run(instance, runBack, param);
-
-        jbot.shutdown();
-
-        JEVdbConfigUtil.releaseConfigs();
-    }
-
-}

+ 23 - 0
app/src/main/java/com/ch/jedge/jbot/JBotNewJava.java

@@ -0,0 +1,23 @@
+package com.ch.jedge.jbot;
+
+import com.ch.jedge.jbot2.JedgeBotGptService;
+import com.ch.jedge.jbot2.intent.bot.JBotAppBase;
+import com.changhong.jedge.JMgbusService;
+
+import static com.ch.jedge.utils.JedgeBotConst.sval_default_gpt_service;
+import static com.ch.jedge.utils.JedgeBotConst.sval_default_gpt_voice_service;
+
+public class JBotNewJava extends JBotAppBase {
+
+    public JBotNewJava(String botName) {
+        super(botName);
+    }
+
+    public static void main(String[] args) {
+        Class<? extends JMgbusService>[] classes =
+                (Class<? extends JMgbusService>[]) new Class<?>[]{JedgeBotGptService.class};
+        run("jbot",
+                new String[] {sval_default_gpt_service},
+                classes, args);
+    }
+}

+ 0 - 67
app/src/main/java/com/ch/jedge/jbot/JEJBotLLMConst.java

@@ -1,67 +0,0 @@
-package com.ch.jedge.jbot;
-
-import com.changhong.qlib.util.file.FileUtils;
-public class JEJBotLLMConst {
-
-    public static final String sval_sub_dir_cfg = "cfg";
-    public static final String sval_sub_dir_glm = "glm";
-    public static final String sval_sub_dir_field_cfg = "cols";
-
-    // public static final String sval_panel_class_base_path = (new File(ConfigUtil.class.getResource("/").getFile())).getPath();
-    public static final String sval_panel_class_base_path = "/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/";//"./";
-    public static final String sval_server_db_cfg_filename = FileUtils.contactPath(sval_panel_class_base_path, sval_sub_dir_cfg, "db.json");
-
-    public static final String sval_milvus_col_def_filename = FileUtils.contactPath(sval_panel_class_base_path, sval_sub_dir_cfg,"_col_def.json");
-    public static final String sval_milvus_msg_def_filename = FileUtils.contactPath(sval_panel_class_base_path, sval_sub_dir_cfg,"_msg_add.json");
-    public static final String sval_glm_config_filename = FileUtils.contactPath(sval_panel_class_base_path, sval_sub_dir_glm,"glm.json");
-
-    public static final String sval_milvus_cfg_path = FileUtils.contactPath(sval_panel_class_base_path, sval_sub_dir_cfg);
-
-    public static final String sval_corpus_cache_path_debug_ = FileUtils.contactPath(sval_panel_class_base_path, "jbot/unit/jbot/cache/corpus");
-
-    public static final String sval_module_llm = "llm";
-
-    public static final String sval_modual_word_cut = "wcut";
-
-    public static final String sval_modual_vec_db = "vdb";
-    public static final String sval_default_vector_service = "gv";
-    public static final String sval_modual_glm_llm = "llm";
-
-    public static final String sval_default_jbot_jedge = "jbot";
-    public static final String sval_default_gpt_service = "gpt";
-    public static final String sval_default_llm_call_service = "lmc";
-    public static final String sval_default_gpt_voice_service = "gptv";
-    public static final String sval_default_glm6b_service = "glm6b";
-
-    public static final String default_vs_domain_ = "_knDefault";
-    public static final String default_vs_domain_local = "tc";
-
-
-    public static final long ival_timeout_session_ = 3 * 60 * 1000 * 10;
-    public static final int  max_history_size = 25;
-    public static final int  ival_mufis_text_message_gap_time_ = 100;
-    public static final int  ival_max_timeout_count = 180;
-
-    public static final String sval_prompt_intentJudge =
-            "意图领域范围:%s,根据对话内容,提取问题的意图范围和知识关键字、意图领域只能在上述意图领域范围内、用如下json格式输出%s";
-    public static final String sval_prompt_kn_build = "就如下内容用提出总共%d个咨询类的问题和答案。每个问题聚焦不超过12字,答案尽可能丰富。问答对的输出格式: Q:这是一个问题A:这是答案";
-    public static final String sval_prompt_kn_talk = "用户希望:%s, 回答内容全部在 %s 中,你需要扮演角色:%s,回答从上述内容中回答下面的问题(只输出答案):%s";
-    public static final String sval_prompt_kn_explain = "用如下内容生成精简的一句话回答:%s";
-
-
-    public static final boolean old_vdb_mode_ = true;
-    public static final boolean local_corpus_ = true;
-
-    public static final int  ival_max_kn_items = 80;
-
-    public static final String sval_verb_type_user_defined_relation_noun = "nur";
-    public static final String sval_verb_type_user_defined_join_noun = "nuj";
-    public static final String val_verb_type_user_defined_noun = "nud";
-    public static final String val_verb_type_user_defined_verb = "vud";
-    public static final String sval_verb_type_user_defined_inference = "nugr";      //需要推理预测结果的词,不是直接命中答案。
-    public static final int lval_min_time_gap = 5000; //每5S添加一条向量数据,防止添加过快导致milvus崩溃
-
-    public static final String sval_predict_split = "$$$";
-    public static final String sval_predict_sign = "@@@";
-    public static final int sval_predict_sign_size = sval_predict_sign.length();
-}

+ 38 - 52
app/src/main/java/com/ch/jedge/jbot/JedgeBotGptService.java

@@ -2,15 +2,19 @@ package com.ch.jedge.jbot;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.ch.jedge.jbot.corpus.CorpusTask;
-import com.ch.jedge.jbot.dict.JEDictUtil;
-import com.ch.jedge.jbot.dict.JedgeWordDict;
-import com.ch.jedge.jbot.intent.JedgeIntentTester;
-import com.ch.jedge.jbot.knbase.JedgeGptApp;
-import com.ch.jedge.jbot.knbase.JedgeGptDialogEngine;
-import com.ch.jedge.jbot.session.JedgeGdeKeywordPool;
+import com.ch.jedge.jbot.other.corpus.CorpusTask;
+import com.ch.jedge.jbot.other.knbase.JedgeGptApp;
+import com.ch.jedge.jbot.other.knbase.JedgeGptDialogEngine;
+import com.ch.jedge.jbot.other.session.JedgeGdeKeywordPool;
+import com.ch.jedge.jbot2.dict.JEDictUtil;
+import com.ch.jedge.jbot2.dict.JedgeWordDict;
 import com.ch.jedge.jbot.session.JedgeServiceSession;
-import com.changhong.jedge.*;
+import com.ch.jedge.utils.JedgeBotConst;
+import com.ch.jedge.utils.JedgeLlmUtil;
+import com.changhong.jedge.JMgbusModual;
+import com.changhong.jedge.JMgbusService;
+import com.changhong.jedge.JMgbusUtil;
+import com.changhong.jedge.MgbusApi;
 import com.changhong.qlib.QData;
 import com.changhong.qlib.intf.QIData;
 import com.changhong.qlib.intf.QIDataList;
@@ -24,8 +28,8 @@ import java.io.File;
 import java.math.BigDecimal;
 import java.util.*;
 
-import static com.ch.jedge.jbot.agent.JedgeGdeConsts.sval_default_app;
-import static com.ch.jedge.jbot.JEJBotLLMConst.*;
+import static com.ch.jedge.jbot.other.agent.JedgeGdeConsts.sval_default_app;
+import static com.ch.jedge.utils.JedgeBotConst.*;
 
 public class JedgeBotGptService extends JMgbusService {
 
@@ -42,7 +46,7 @@ public class JedgeBotGptService extends JMgbusService {
     protected int vecSize = 1536;
     protected int chatMode = 2;
     String knAsk_prompt;
-    private final JedgeIntentTester domainTester;
+    private final JedgeDomainTesterOld domainTester;
 
     private String corpusPath = sval_corpus_cache_path_debug_;
 
@@ -57,7 +61,7 @@ public class JedgeBotGptService extends JMgbusService {
     public JedgeBotGptService(JMgbusModual holder) {
         super(holder);
 
-        domainTester = new JedgeIntentTester(module, this);
+        domainTester = new JedgeDomainTesterOld(module, this);
 
         auto_remove_call_info = false;
         String promptPath = FileUtils.contactPath("./", "cache", "prompt");
@@ -480,10 +484,6 @@ public class JedgeBotGptService extends JMgbusService {
             }
         }
 
-        QIData msg = new QData();
-        msg.putString("text", prompt);
-        postServiceMessage("tvmufis", "/tvmfs/usermsg", msg);
-
         JedgeServiceSession s = findSession(req, prompt);
 
         if(!s.isStream) {  //非流式请求,目前只针对chatGPT
@@ -491,19 +491,15 @@ public class JedgeBotGptService extends JMgbusService {
         }
 
         String finalPrompt = prompt;
-//        module.postThread(() -> {
-////            if(GdeTalk(s, finalPrompt)) {
-////                return;
-////            }
-////
+        module.postThread(() -> {
             if(s.knTalk) {
                 module.highLog(String.format("GPT Prompt>>%s", finalPrompt));
-//                if (JedgeGptApp.isDebugMode())
-//                    returnMgbusMessage(s.srcMod, s.cbUri, "正在处理...\n", false);
                 //第一步、提取意图和知识关键字;
                 QIData intent = checkWordsOfIntent(s, s.currentPrompt);
                 knTalkLog(finalPrompt);
                 if (intent != null) {
+                    //记录聊天历史,只记录发出的请求,不记录返回
+                    s.buildLastHistory();
                     if (JMgbusUtil.isMgbusResultOk(intent)) {
                         String returnPrompt = String.format("你是一个人工智能助手,用户输入:%s,请只根据系统的返回内容:%s,为用户输入生成一个直接的极简答复,不要生成其它内容。", finalPrompt, intent.getString("msg"));
 //                        makeRealGptStreamCall(s, returnPrompt);
@@ -512,20 +508,21 @@ public class JedgeBotGptService extends JMgbusService {
                     } else if(intent.getInteger("code") == 601)  {
                         if (JedgeGptApp.isDebugMode() && !s.voiceTalk)
                             returnMgbusMessage(s.srcMod, s.cbUri, "[模型直问]", true);
-                        // makeRealGptStreamCall(s, finalPrompt);
+                         makeRealGptStreamCall(s, finalPrompt);
                     } else
                         returnMgbusMessage(s.srcMod, s.cbUri, "[动作失败]", true);
                 } else {
                     if (JedgeGptApp.isDebugMode() && !s.voiceTalk)
                         returnMgbusMessage(s.srcMod, s.cbUri, "[模型直问]", true);
-                        //makeRealGptStreamCall(s, finalPrompt);
+                     makeRealGptStreamCall(s, finalPrompt);
                 }
             } else {
                 knTalkLog(finalPrompt);
                 makeRealGptStreamCall(s, finalPrompt);
             }
             s.getGdtSession().refreshQARange();     //刷新聊天距离
-//        });
+        });
+
 
         QIData resp = JedgeLlmUtil.simpleOk();
         resp.put("sid", s.sid);
@@ -533,17 +530,19 @@ public class JedgeBotGptService extends JMgbusService {
     }
 
     private QIData checkWordsOfIntent(JedgeServiceSession s, String finalPrompt) {
-        JedgeIntentTester dmTester = domainTester;
-        String lastDomain = null;
-        JedgeIntentTester lastDmTester = null;
+        JedgeDomainTesterOld dmTester = domainTester;
+        String lastDomain = s.getLastDomain();
+        JedgeDomainTesterOld lastDmTester = null;
         QIData domainResult = null;
         int failCount = 0;
         while(dmTester!=null) {
-            String newPrompt = domainTester.getIntentTestPrompt(finalPrompt);
+            String history = s.history_.toJSONString();
+            String newPrompt = domainTester.getIntentTestPrompt(finalPrompt, history);
             domainResult = getJsonResultForPrompt(s, newPrompt);
             lastDmTester = dmTester;
             if(domainResult!=null && domainResult.containsKey("domain")) {  //子分类为其它时,直接在当前的domin
                 String domain = domainResult.getString("domain");
+                s.addLastDomain(domain);
                 if (JedgeGptApp.isDebugMode() && !s.voiceTalk)
                     returnMgbusMessage(s.srcMod, s.cbUri, String.format("你想要:%s\n", domain), false);
                 lastDomain = domain;
@@ -559,13 +558,13 @@ public class JedgeBotGptService extends JMgbusService {
         }
 
         if(StringUtils.isValidStr(lastDomain)) {
-            JedgeIntentTester.JedgeDomainDef tester = lastDmTester.getIntentTester(lastDomain);
+            JedgeDomainTesterOld.JedgeDomainDef tester = lastDmTester.getIntentTester(lastDomain);
             //获得知识增强(通过domain中的Key)
             //可通过额外的知识获得增强
             //获取意图领域,并识别准确的意图
             if(tester!=null) {
                 // 获得子分类器,如果有则继续分类,如果没有,则调用intent生成器来完成生成。
-                String newPrompt = tester.getIntentClassificationTemplate(finalPrompt);
+                String newPrompt = tester.getIntentClassificationTemplate(finalPrompt, "");
                 QIData finalResult = getJsonResultForPrompt(s, newPrompt);      //提取参数
                 if(finalResult instanceof QIDataList) {
                     QIData p = null;
@@ -677,13 +676,13 @@ public class JedgeBotGptService extends JMgbusService {
         if(session != null) {
             if(session.printSingle) {
                 module.infoLog(String.format("Gpt>>%s(%s)", text, isEnd));
-
                 if (isEnd) {
 //                    pullKnowledgeFromResponse(session, session.currentResponse);
                     session.buildLastHistory();
                 } else {
                     //text = text.trim();
-                    if(StringUtils.isValidStr(text))
+                    if(StringUtils.isValidStr(text) &&
+                            StringUtils.isValidStr(session.currentPrompt))
                         session.append2LastQA(text);
                 }
                 if (session.srcMod != null && session.cbUri != null) {
@@ -710,7 +709,7 @@ public class JedgeBotGptService extends JMgbusService {
         //解决
         for(String mkey : knKeyList) {
 //            String content =
-            pool.getKnowledgeFromMilvus(s, mkey, false);
+                    pool.getKnowledgeFromMilvus(s, mkey, false);
 //            module.highLog(String.format("Recall info from answer(%s) : %s", mkey, content));
         }
     }
@@ -967,18 +966,10 @@ public class JedgeBotGptService extends JMgbusService {
                 for(String k : keys) {
                     JedgeServiceSession s = sessions_.get(k);
                     s.ttl ++;
-                    if(s.ttl > JEJBotLLMConst.ival_timeout_session_ ) {        //会话3分钟没有任何返回,清空
+                    if(s.ttl > JedgeBotConst.ival_timeout_session_ ) {        //会话3分钟没有任何返回,清空
                         toDel.add(k);
                         module.highLog(String.format("Timeout talk session %s from %s", k, s.srcMod));
                         // returnMgbusMessage(s.srcMod, s.cbUri, "会话超时", true, true);
-                    } else {
-                        //会话池心跳
-                        try {
-                            if(s.ttl % 5 ==0 )
-                                s.getGdtSession().knItemPoolHeartBeat();
-                        }catch (Exception e) {
-                            e.printStackTrace();
-                        }
                     }
                 }
                 for(String key : toDel)
@@ -1008,15 +999,10 @@ public class JedgeBotGptService extends JMgbusService {
         d.put("nb",true);
         msg.put("~c", d);
         postServiceMessage(srcMod, cbUri, msg);
-
-        QIData msg2 = new QData();
-        msg2.putString("msg", txtMessage);
-        msg2.putBoolean("end", isEndMsg);
-        postServiceMessage("tvmufis", "/tvmfs/glmmsg", msg2);
     }
 
     public void returnMgbusMessageWithKey(String key, String jeMod, String jeUriCb, String txtMessage,
-                                          boolean isEndMsg , boolean isErr ) {
+                                                 boolean isEndMsg , boolean isErr ) {
         module.exMarkLog(String.format("Corpus More >>%s",txtMessage));
         QIData msg = new QData();
         msg.setKey(key);
@@ -1114,7 +1100,7 @@ public class JedgeBotGptService extends JMgbusService {
 
     public String makeRealGptChatCall(JedgeServiceSession s, String realPrompt) {
         QIData gr = new QData();
-        gr.put("history", s.history_);
+//        gr.put("history", s.history_);
         gr.put("query", realPrompt);
         gr.put("cb",  "/gpt/LocalStream");//本地stream返回
         gr.put("sid", s.sid);
@@ -1341,7 +1327,7 @@ public class JedgeBotGptService extends JMgbusService {
     private void knTalkLog(String prompt, boolean succ) {
         String log =  "["+ TimeUtils.getNowShortStrWithMillis()+"] ["+(succ?"SUC":"FAL")+"]>>" + prompt;
         log = log.replaceAll( "\n","");
-//        FileUtils.appendLine(kn_talk_log_file, log+"\n", "UTF-8");
+        FileUtils.appendLine(kn_talk_log_file, log+"\n", "UTF-8");
     }
 
     protected JedgeServiceSession findSession(QIData req, String prompt) {

+ 15 - 16
app/src/main/java/com/ch/jedge/jbot/intent/JedgeIntentTester.java → app/src/main/java/com/ch/jedge/jbot/JedgeDomainTesterOld.java

@@ -1,8 +1,9 @@
-package com.ch.jedge.jbot.intent;
+package com.ch.jedge.jbot;
+
 
 import com.alibaba.fastjson.JSONArray;
-import com.ch.jedge.jbot.intent.param.JedgeDataSetter;
-import com.ch.jedge.jbot.knbase.JedgeGptApp;
+import com.ch.jedge.jbot2.intent.param.JedgeDataSetter;
+import com.ch.jedge.jbot.other.knbase.JedgeGptApp;
 import com.changhong.jedge.JMgbusModual;
 import com.changhong.jedge.JMgbusService;
 import com.changhong.jedge.JMgbusUtil;
@@ -12,25 +13,25 @@ import com.changhong.qlib.util.StringUtils;
 
 import java.util.*;
 
-import static com.ch.jedge.jbot.JEJBotLLMConst.ival_max_timeout_count;
+import static com.ch.jedge.utils.JedgeBotConst.ival_max_timeout_count;
 
 /**
  *  判断用户意图
  */
-public class JedgeIntentTester {
+public class JedgeDomainTesterOld {
     private final JMgbusModual module;
     private final JMgbusService service;
 
-    public static final String sval_cmd_test_domain_ = "%s,从用户文本中抽取实体,从:\"%s\"中判断用户最可能的唯一一个意图领域,用结构化方式的json格式输出,格式:%s.只输出json内容,不输出其他。用户输入:{query}, 你的输出是:";
-    //    public static final String sval_cmd_pick_params_ = "你的角色是 %s, 基于提供的数据,对用户语句提取参数值并替换为对应的参数取值,根据需要尽量分成多条指令,所提取的参数项及其取值范围只能在上述操作操作项列表范围内, 从用户文本中抽取实体参数,用结构化方式的json格式输出,只输出json部分,输出格式如下:%s。:\"{query}\"";
-    public static final String sval_cmd_pick_params_ = "你的角色是 %s, 从用户文本中抽取实体参数,用结构化方式的json格式输出,只输出json部分,输出格式如下:%s。只输出json内容,不输出其他。准确区分用户的意图,一个动作意图只生成一条数据,多个动作意图尽量拆分为多条结构数据。:用户输入:{query}, 你的输出是:";
+    public static final String sval_cmd_test_domain_ = "%s,从用户文本中抽取实体,从:\"%s\"中判断用户最可能的唯一一个意图领域,用结构化方式的json格式输出,格式:%s.只输出json内容,不输出其他。用户输入历史:{history},用户输入:{query},你的输出是:";
+//    public static final String sval_cmd_pick_params_ = "你的角色是 %s, 基于提供的数据,对用户语句提取参数值并替换为对应的参数取值,根据需要尽量分成多条指令,所提取的参数项及其取值范围只能在上述操作操作项列表范围内, 从用户文本中抽取实体参数,用结构化方式的json格式输出,只输出json部分,输出格式如下:%s。:\"{query}\"";
+    public static final String sval_cmd_pick_params_ = "你的角色是 %s, 从用户文本中抽取实体参数,用结构化方式的json格式输出,只输出json部分,输出格式如下:%s。只输出json内容,不输出其他。准确区分用户的意图,一个动作意图只生成一条数据,多个动作意图尽量拆分为多条结构数据。用户输入历史:{history},用户输入:{query}, 你的输出是:";
     public static final String sval_default_out_format_ =  "{\"domain\":\"意图领域\",\"exKeyWords\":[\"知识关键字1\",\"知识关键字2\",...]}";
     public String donmainTestTemplateString = "";
     public String jsonIntentFormat = sval_default_out_format_;
 
     protected final Map<String, JedgeDomainDef> domainDefMap = new HashMap<>();
 
-    public JedgeIntentTester getSubDomainTester(String domain) {
+    public JedgeDomainTesterOld getSubDomainTester(String domain) {
         return null;
     }
 
@@ -102,9 +103,8 @@ public class JedgeIntentTester {
 //            JESocketClient.exMarkLogSt("意图的template:\n"+intentClassificationTemplate);
         }
 
-        public String getIntentClassificationTemplate(String finalPrompt) {
-//            return intentClassifyTemplateString.replaceAll("\\{query}", finalPrompt);
-            return intentClassifyTemplateString.replace("{query}", finalPrompt);
+        public String getIntentClassificationTemplate(String finalPrompt, String history) {
+            return intentClassifyTemplateString.replaceAll("\\{query}", finalPrompt).replaceAll("\\{history}", history);
         }
 
         private String prepareDataset() {
@@ -154,7 +154,7 @@ public class JedgeIntentTester {
         }
     }
 
-    public JedgeIntentTester(JMgbusModual module, JMgbusService service) {
+    public JedgeDomainTesterOld(JMgbusModual module, JMgbusService service) {
         this.module = module;
         this.service = service;
     }
@@ -194,9 +194,8 @@ public class JedgeIntentTester {
         }
     }
 
-    public String getIntentTestPrompt(String query) {
-//        return donmainTestTemplateString.replaceAll("\\{query}", query);
-        return donmainTestTemplateString.replace("{query}", query);
+    public String getIntentTestPrompt(String query, String history) {
+        return donmainTestTemplateString.replaceAll("\\{query}", query).replaceAll("\\{history}", history);
     }
 
     public QIData addNewDataSet(QIData req) {

+ 0 - 25
app/src/main/java/com/ch/jedge/jbot/JedgeLlmBotClient.java

@@ -1,25 +0,0 @@
-package com.ch.jedge.jbot;
-
-import com.changhong.jedge.JMgbusClient;
-
-import static com.ch.jedge.jbot.JEJBotLLMConst.*;
-
-public class JedgeLlmBotClient extends JMgbusClient {
-
-    static private JedgeLlmBotClient glLlmBot;
-
-    public JedgeLlmBotClient(String subnet, String mgc_name, int threadCount, boolean tryLocal) {
-        super(subnet, mgc_name, threadCount, tryLocal);
-    }
-
-    public static JedgeLlmBotClient getInstance() {
-        if(glLlmBot == null) {
-            glLlmBot = new JedgeLlmBotClient("#0", sval_default_jbot_jedge, 10, true);
-            JedgeBotGptService service = new JedgeBotGptService(glLlmBot);
-            glLlmBot.bindService(sval_default_gpt_service, service);
-//            glLlmBot.bindService(sval_default_gpt_voice_service, new JedgeVoiceBotService(glLlmBot));
-        }
-        return glLlmBot;
-    }
-
-}

+ 0 - 125
app/src/main/java/com/ch/jedge/jbot/JedgeLlmUtil.java

@@ -1,125 +0,0 @@
-package com.ch.jedge.jbot;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.alibaba.fastjson.parser.Feature;
-import com.changhong.jedge.JMgbusUtil;
-import com.changhong.qlib.intf.QIData;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
-
-public class JedgeLlmUtil {
-    public static QIData simpleOk() {
-        return JMgbusUtil.MgbusResult(200,"ok");
-    }
-
-    public static QIData simpleFail(String formatStr, Object... vals) {
-        return JMgbusUtil.MgbusResult(200,String.format(formatStr, vals));
-    }
-
-    public static String getFirstRandomKey(Set<String> keySet) {
-        if(keySet!=null)
-            for(String key : keySet)
-                return key;
-        return null;
-    }
-
-    public static String unescapeString(String input) {
-        if (input == null) {
-            return null;
-        }
-
-        StringBuilder result = new StringBuilder();
-        int length = input.length();
-        boolean isEscaped = false;
-
-        for (int i = 0; i < length; i++) {
-            char currentChar = input.charAt(i);
-
-            if (isEscaped) {
-                switch (currentChar) {
-                    case 'n':
-                        result.append('\n');
-                        break;
-                    case 'r':
-                        result.append('\r');
-                        break;
-                    case 't':
-                        result.append('\t');
-                        break;
-                    case 'b':
-                        result.append('\b');
-                        break;
-                    case 'f':
-                        result.append('\f');
-                        break;
-                    case '\'':
-                        result.append('\'');
-                        break;
-                    case '\"':
-                        result.append('\"');
-                        break;
-                    case '\\':
-                        result.append('\\');
-                        break;
-                    default:
-                        result.append(currentChar);
-                        break;
-                }
-                isEscaped = false;
-            } else {
-                if (currentChar == '\\') {
-                    isEscaped = true;
-                } else {
-                    result.append(currentChar);
-                }
-            }
-        }
-
-        return result.toString();
-    }
-
-    public static JSONArray JsonArrayFromStringArray(String[] split) {
-        JSONArray re = new JSONArray();
-        re.addAll(Arrays.asList(split));
-        return re;
-    }
-
-    public static JSONArray JsonArrayFromJsonString(String initVal) {
-        try {
-            Object target = JSON.parse(initVal, Feature.OrderedField);
-            if (target instanceof JSONObject) {
-                JSONArray re = new JSONArray();
-                re.add(target);
-                return re;
-            } else if(target instanceof JSONArray){
-                return (JSONArray) target;
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return new JSONArray();
-    }
-
-    public static JSONArray JsonArrayFromStringList(List<String> items) {
-        JSONArray re = new JSONArray();
-        re.addAll(items);
-        return re;
-    }
-
-    public static String StringFromStringJSONArray(JSONArray ds) {
-        if(ds!=null) {
-            StringBuilder r=new StringBuilder();
-            for(Object d : ds) {
-                if(d instanceof String)
-                    if(r.length()>0) r.append(",");
-                r.append(d);
-            }
-            return r.toString();
-        }
-        return null;
-    }
-}

+ 0 - 308
app/src/main/java/com/ch/jedge/jbot/JedgeVoiceBotService.java

@@ -1,308 +0,0 @@
-package com.ch.jedge.jbot;
-
-import com.ch.jedge.utils.JEVdbConfigUtil;
-import com.changhong.jedge.JMgbusService;
-import com.changhong.jedge.MgbusApi;
-import com.changhong.qlib.QData;
-import com.changhong.qlib.intf.QIData;
-import com.changhong.qlib.util.StringUtils;
-import com.changhong.qlib.util.sync.SystemUtils;
-
-import java.util.LinkedList;
-
-public class JedgeVoiceBotService  extends JMgbusService  {
-    protected String inputVoiceMode;
-    protected String talkUri = "/gpt/knTalk";;
-    private static final String vkey_voice_event_text_ = "textOk";
-    private static final String vkey_voice_event_wakeup_ = "wakeUp";
-    private static final String vkey_voice_text_handle_text_ = "text";
-    private static final String vkey_voice_text_handle_end_ = "end";
-    private static final String vkey_voice_text_handle_result_type_ = "result";
-    private static final String vkey_voice_text_handle_result_response_ = "text";
-    private static final String vkey_voice_text_handle_result_sessoin_ = "edge_session";
-    private static final String sval_uri_text_handle_result_ = "/dds/textHandleResult";
-
-
-    boolean vui_going_ = false;
-    private boolean quit_ = false;
-    private boolean active_ = false;
-    private final LinkedList<String> gptSpeakList = new LinkedList<>();
-
-    int timeOutCount = 0;
-    int speakCount = 0;
-    private final SentenceSplitter sentSpliter = new SentenceSplitter();
-
-    public JedgeVoiceBotService(JedgeLlmBotClient glLlmBot) {
-        super(glLlmBot);
-        auto_remove_call_info = false;
-
-        if(StringUtils.isNotValidStr(inputVoiceMode))
-            inputVoiceMode = JEVdbConfigUtil.getConfigObjSimpleFmtString("jbot","vw", "vui");
-        if(StringUtils.isNotValidStr(inputVoiceMode))
-            inputVoiceMode="vui";
-
-        module.postThread(this::post2TextSpeech);
-        module.postThread(this::checkChatTimeout);
-    }
-
-    private void checkChatTimeout() {
-        while(!quit_) {
-            if(vui_going_) {
-                timeOutCount++;
-                if(timeOutCount > 30) {
-                    module.warnLog("Warning!!! chat return timeout.");
-                    vui_going_ = false;
-                }
-            }
-            SystemUtils.tryWait(1000);
-        }
-    }
-
-    private void post2TextSpeech() {
-        while(!quit_) {
-            speakCount-=250;
-//            QDWarn("speakCount:%d", speakCount);
-            if (speakCount < 1) {
-                //从队列中提取一个消息发送阅读
-                String tts;
-                {
-                    boolean isEmpty;
-                    synchronized (gptSpeakList){
-                        isEmpty = gptSpeakList.isEmpty();
-                    }
-                    if (isEmpty) {
-                        SystemUtils.tryWait(250);
-                        speakCount = 0;
-                        continue;
-                    }
-                    synchronized (gptSpeakList) {
-                        tts = gptSpeakList.pop();
-                    }
-                }
-
-                if(StringUtils.isNotValidStr(tts))
-                    continue;
-                if("[DONE]".equals(tts)) {
-//                    speakText("完毕");
-                    vui_going_ = false;
-                    continue;
-                } else if (StringUtils.isValidStr(tts)) {
-                    //计算speakCount长度
-                    speakCount = tts.length() * 71 * 3;
-                    module.warnLog(String.format("Reset speakCount:%d", speakCount));
-                    speakText(tts);
-                    timeOutCount = 0;
-                }
-            }
-            SystemUtils.tryWait(250);
-        }
-        active_ = false;
-    }
-
-    private void speakText(String text) {
-        module.exMarkLog(String.format("TO SPEECH=>>:%s", text));
-        QIData d = new QData();
-        d.putString("text", text).putInteger("p",1);
-        postServiceMessage(inputVoiceMode, "/dds/speakText", d);
-    }
-
-    @Override
-    public void onServiceStart() {
-        super.onServiceStart();
-
-        watchLocalEvent("OnModuleConnected", (w, keyVal, msg) -> {
-            String host = msg.getString("host");
-            int port = msg.getInteger("port");
-            this.onMgbusConnected(host, port);
-            return true;
-        });
-
-        watchLocalEvent("OnModuleDisconnected", (w, keyVal, msg) -> {
-            String host = msg.getString("host");
-            int port = msg.getInteger("port");
-            this.onMgbusDisconnected(host, port);
-            return true;
-        });
-    }
-
-    //module掉线,啥也不做
-    private void onMgbusConnected(String host, int port) {
-        watchMgbusEvent("online", "vui", msg -> {
-            String mode = msg.getString("module");
-            String mgnet = msg.getString("mgnet");
-            boolean isLocal = msg.getBoolean("local", false);
-            if(isLocal && mode.contains(mgnet))
-                mode = "vui";
-            if (inputVoiceMode.equals(mode) || isLocal) {
-                watchVoiceModule();
-            }
-        });
-        watchMgbusEvent("offline", "vui", msg -> {
-            String mode = msg.getString("module");
-            if (inputVoiceMode.equals(mode)) {
-                removeVoiceWatch();
-            }
-        });
-    }
-
-    private void onMgbusDisconnected(String host, int port) {
-
-    }
-
-    private void removeVoiceWatch() {
-        clearEventWatcher(inputVoiceMode, "textOk","/@c/_ecb" ,"@");
-    }
-
-    private void watchVoiceModule() {
-        watchServiceEvent(inputVoiceMode, vkey_voice_event_text_, eMsg -> {
-            boolean isFinal = eMsg.getBoolean(vkey_voice_text_handle_end_, false);
-            int session = eMsg.getInteger(vkey_voice_text_handle_result_sessoin_);  //可能为空,则单独创建一个对话ID
-            String text = eMsg.getString(vkey_voice_text_handle_text_);
-            module.exMarkLog(String.format("...>>[text]: %s", text));
-            if (isFinal) {
-                //auto mod = GetEventSrc(eMsg); //GetEventSrc(eMsg);
-                /* !mod.empty() && mod == (inputVoiceMode) &&  */
-                if (StringUtils.isValidStr(text) ) {
-                    handleGptVoiceText(session, text);
-                }
-            }
-        });
-
-        watchServiceEvent(inputVoiceMode, vkey_voice_event_wakeup_, eMsg -> {
-            String deviceId = eMsg.getString("deviceId");
-            if(module.getHostSn().contains(deviceId)) {
-                //本地唤醒
-//                module.exMarkLog(String.format("...>>[wakeupEvent]: %s", deviceId));
-                vui_going_ = false;
-                synchronized (this.gptSpeakList) {
-                    gptSpeakList.clear();
-                }
-            }
-        });
-
-    }
-
-    private void handleGptVoiceText(int session, String text) {
-        module.exMarkLog(String.format("[%d]:Voice Text pushed incoming = %s", session, text));    //中间数据
-        //设置返回参数
-        //处理流程 找到对话,再在对话的处理流程中、处理语义的应答信息。根据不同的语境,做出不同的应答。
-        {
-            if ((text.startsWith("退出") || text.startsWith("停止"))) {
-                synchronized (gptSpeakList) {
-                    gptSpeakList.clear();
-                }
-                //快速回答,接管语义处理
-                returnVoiceResult(inputVoiceMode, session, 0, "好的、再见");
-
-                vui_going_ = false;
-                timeOutCount = 0;
-                return;
-            } else if(vui_going_) {
-                module.exMarkLog("已在对话中……");
-                return;
-            } else {
-                timeOutCount = 0;
-                vui_going_ = true;
-                //快速回答,接管语义处理
-                returnVoiceResult(inputVoiceMode, session, 0, "稍等");
-            }
-        }
-        QIData r = new QData();
-        //发送talk请求到mgs,并将分别返回的结果进入队列
-        r.putString("text", text);
-        r.putString("knn", "testGPT");
-        r.putBoolean("stream", true);
-        r.putBoolean("k", true);
-        r.putBoolean("v", true);
-        r.putString("cb", "/gptv/streamBack");
-        r.putBoolean("talkStream", true);     //按句回推
-        postServiceMessage("jbot", talkUri, r);
-    }
-
-    private void returnVoiceResult(String mod, int session, int type, String answerText) {
-        QIData eMsg = new QData();
-        eMsg.putInteger(vkey_voice_text_handle_result_type_, type);  //继续对话
-        eMsg.putString(vkey_voice_text_handle_result_response_, answerText);
-        eMsg.putInteger(vkey_voice_text_handle_result_sessoin_, session);
-        postServiceMessage(mod, sval_uri_text_handle_result_, eMsg);
-        module.exMarkLog(String.format("Post2Speech:%s", answerText));
-    }
-
-    @Override
-    public void onServiceStop() {
-        this.quit_ = true;
-        while(active_) {
-            SystemUtils.tryWait(20);
-        }
-        super.onServiceStop();
-    }
-
-
-    //组装成正常的语句
-    @MgbusApi
-    public QIData streamBack(QIData req) {
-        timeOutCount = 0;
-        boolean next_vui_going_ = !req.getBoolean("end", false);
-        String streamText = req.getString("msg");
-        module.printClientLog(String.format("GPT>>(Going:%s):%s", next_vui_going_?"true":"false", streamText));
-        if(StringUtils.isValidStr(streamText) && !streamText.startsWith("[") && !streamText.startsWith("$")) {
-            streamText = streamText.replaceAll("\n", ""); //去掉空行
-            if (vui_going_ && !streamText.isEmpty()) {
-                synchronized (gptSpeakList) {
-                    String str = sentSpliter.pushChars(streamText);
-                    while (StringUtils.isValidStr(str)) {
-                        module.highLog(String.format("GPT>>(Going:%s):%s", vui_going_ ? "true" : "false", str));
-                        gptSpeakList.add(str);
-                        str = sentSpliter.getNextString();
-                    }
-                }
-            }
-        }
-        if(!next_vui_going_) {
-            String str = sentSpliter.getNextString();
-            synchronized (gptSpeakList) {
-                if(StringUtils.isValidStr(str)) {
-                    gptSpeakList.add(str);
-                }
-                gptSpeakList.add("[DONE]");
-            }
-        }
-        return null;
-    }
-
-    private static class SentenceSplitter {
-        StringBuilder buffer = new StringBuilder();
-        String leftStr = null;
-        public String pushChars(String streamText) {
-            int streamTextLen = streamText.length();
-            for(int i=0;i<streamTextLen;i++) {
-                char subChar = streamText.charAt(i);
-                switch (subChar) {
-                    case ',':
-//                    case '.':
-                    case '!':
-                    case ';':
-                    case '?':
-                    case ',':
-                    case '。':
-                    case '!':
-                    case '?':
-                        leftStr = streamText.substring(i+1);
-                        String result = buffer.toString();
-                        buffer = new StringBuilder();
-                        return result;
-                    default:
-                        buffer.append(subChar);
-                }
-            }
-            return null;
-        }
-
-        public String getNextString() {
-            if(StringUtils.isValidStr(leftStr))
-                return pushChars(leftStr);
-            else
-                return null;
-        }
-    }
-}

+ 0 - 61
app/src/main/java/com/ch/jedge/jbot/dict/JEDictUtil.java

@@ -1,61 +0,0 @@
-package com.ch.jedge.jbot.dict;
-
-import com.changhong.qlib.util.StringUtils;
-import com.changhong.qlib.util.file.FileUtils;
-
-import java.io.File;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 词库工具
- *      扫描词库目录下的通用词库文件,并动态添加到Jieba分词词库中
- *
- */
-public class JEDictUtil {
-
-    public static void loadStaticCommonDicts(final Map<String, JedgeWordDict> dictMap, String dictPath) {
-
-        FileUtils.listDirFiles(dictPath, file -> {
-            JedgeWordDict dict = loadStaticCommonDict(dictPath, file);
-            if(dict!=null) {
-                synchronized (dictMap) {
-                    dictMap.put(dict.getName(), dict);
-                }
-            }
-            return null;
-        });
-    }
-
-    public static JedgeWordDict loadStaticCommonDict(String dictPath, File file) {
-        if(file==null || !file.getName().endsWith(".dic") || !file.exists())
-            return null;
-        List<String> lines = StringUtils.readStringLinesFromFile(file);
-        JedgeWordDict dict = new JedgeWordDict(file.getAbsolutePath());
-        String[] defaultWordDef = "100 nz".split(" ");
-        for(String l : lines) {
-            //添加词汇
-            if(StringUtils.isNotValidStr(l) || l.charAt(0) == '#')
-                continue;
-            if(l.startsWith("$")) {
-                defaultWordDef = l.substring(1).trim().split(" ");
-                continue;
-            }
-            String[] disc = l.split(" ");
-            int idx = 0;
-            String[] realWord = new String[3];
-            for(String d : disc) {
-                if(d.isEmpty()) continue;
-                realWord[idx++] = d;
-                if(idx==3) break;
-            }
-            String word = realWord[0],
-                    freq = realWord[1]==null?defaultWordDef[0]:realWord[1],
-                    type = realWord[2]==null?defaultWordDef[1]:realWord[2];
-            if(StringUtils.isNotValidStr(word)) continue;
-            dict.appendWordItem(new JedgeWordItem(word, type, freq, false));
-        }
-        if(!dict.isEmpty()) return dict;
-        return null;
-    }
-}

+ 0 - 82
app/src/main/java/com/ch/jedge/jbot/dict/JedgeWordDict.java

@@ -1,82 +0,0 @@
-package com.ch.jedge.jbot.dict;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.ch.jedge.jbot.knbase.JedgeGptDomain;
-import com.changhong.qlib.util.file.FileUtils;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- *  词库:
- *      动态加载,可从知识切片、领域或通用预置词库中加载
- */
-public class JedgeWordDict {
-    private final String name_;
-
-    public String dictPath;
-
-    public int ttl;     //对话一旦进入非专业领域后,在一定时间内自动清理。
-
-    protected final Map<String, JedgeWordItem> wordItems = new HashMap<>();
-
-    public JedgeWordDict(String path) {
-        this.dictPath = path;
-        this.name_ = FileUtils.getFilenameWithoutExt(path);
-    }
-
-    public JedgeWordDict(JedgeGptDomain domain) {
-        this.dictPath = domain.getFilePath();
-        this.name_ = domain.getDomainName();
-    }
-
-    public void appendWordItem(JedgeWordItem jedgeWordItem) {
-        synchronized (wordItems) {
-            JedgeWordItem old = wordItems.get(jedgeWordItem.word);
-            if(old!=null) {
-                old.freq += jedgeWordItem.freq;
-                old.isGated = old.isGated || jedgeWordItem.isGated;
-            } else
-                wordItems.put(jedgeWordItem.word, jedgeWordItem);   //覆盖前面的重复词汇
-        }
-    }
-
-    public String getName() {
-        return name_;
-    }
-
-    public boolean isEmpty() {
-        synchronized (wordItems) {
-            return wordItems.isEmpty();
-        }
-    }
-
-    public JSONArray getWordItemsInJson(boolean gated) {
-        JSONArray re = new JSONArray();
-        synchronized (wordItems) {
-            for (JedgeWordItem entry : wordItems.values()) {
-                if(gated!=entry.isGated) continue;
-                JSONObject obj = new JSONObject();
-                obj.put("w", entry.word);
-                obj.put("t", entry.type);
-                obj.put("f", entry.freq);
-                re.add(obj);
-            }
-        }
-        return re;
-    }
-
-    public Collection<JedgeWordItem> getWordItems() {
-        synchronized (wordItems) {
-            return wordItems.values();
-        }
-    }
-
-    public JedgeWordItem getWordItem(String word) {
-        synchronized (wordItems) {
-            return wordItems.get(word);
-        }
-    }
-}

+ 0 - 17
app/src/main/java/com/ch/jedge/jbot/dict/JedgeWordItem.java

@@ -1,17 +0,0 @@
-package com.ch.jedge.jbot.dict;
-
-import com.changhong.qlib.util.StringUtils;
-
-public class JedgeWordItem {
-    public String word;
-    public String type;
-    public int freq;
-    public boolean isGated;
-
-    public JedgeWordItem(String word, String type, String freq, boolean isGateWord) {
-        this.word = word;
-        this.type = type;
-        this.freq = StringUtils.toInteger(freq,100);
-        this.isGated = isGateWord;
-    }
-}

+ 0 - 12
app/src/main/java/com/ch/jedge/jbot/intent/JDataGetter.java

@@ -1,12 +0,0 @@
-package com.ch.jedge.jbot.intent;
-
-
-import java.lang.annotation.*;
-
-@Inherited
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface JDataGetter {
-    String mod() default "";
-    String uri() default "";
-}

+ 0 - 15
app/src/main/java/com/ch/jedge/jbot/intent/JbotApi.java

@@ -1,15 +0,0 @@
-package com.ch.jedge.jbot.intent;
-
-
-import java.lang.annotation.*;
-
-@Inherited
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface JbotApi {
-    String domain();
-    String disc() default "";
-    String dataset() default "";
-    String msgFmt() default "";
-    String role() default "安全实验室智能助手";
-}

+ 0 - 15
app/src/main/java/com/ch/jedge/jbot/intent/JbotData.java

@@ -1,15 +0,0 @@
-package com.ch.jedge.jbot.intent;
-
-
-import com.alibaba.fastjson.JSONArray;
-
-import java.lang.annotation.*;
-
-@Inherited
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.METHOD})
-public @interface JbotData {
-    String domain();
-    String words();
-    boolean nullable() default true;
-}

+ 0 - 320
app/src/main/java/com/ch/jedge/jbot/intent/JedgeJBotCBService.java

@@ -1,320 +0,0 @@
-package com.ch.jedge.jbot.intent;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.ch.jedge.jbot.JedgeLlmUtil;
-import com.changhong.jedge.JMgbusModual;
-import com.changhong.jedge.JMgbusService;
-import com.changhong.jedge.JMgbusUtil;
-import com.changhong.jedge.MgbusApi;
-import com.changhong.qlib.QData;
-import com.changhong.qlib.intf.QIData;
-import com.changhong.qlib.intf.QIDataList;
-import com.changhong.qlib.util.StringUtils;
-import com.changhong.qlib.util.sync.SystemUtils;
-
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static com.ch.jedge.jbot.JEJBotLLMConst.sval_default_jbot_jedge;
-
-public class JedgeJBotCBService extends JMgbusService {
-
-    private boolean is_active_ = false;
-    private boolean is_online_ = false;
-    private final Object quitCtrl = new Object();
-    private final Map<String, Integer> registeredDomainMap = new HashMap<>();
-    private final Map<String, Integer> registeredDataSetMap = new HashMap<>();
-    private final Map<String, Method> DataGetterMap = new HashMap<>();
-
-    public JedgeJBotCBService(JMgbusModual holder) {
-        super(holder);
-        auto_remove_call_info = false;
-        watchLocalEvent("OnModuleConnected", (w, keyVal, msg) -> {
-            String host = msg.getString("host");
-            int port = msg.getInteger("port");
-            is_online_ = true;
-            watchMgbusEvent("online", "jbot", qiData -> {
-                synchronized (quitCtrl) {
-                    if (!is_active_) {
-                        is_active_= true;
-                        module.postThread(this::refreshJBotRegister);
-                    }
-                }
-                synchronized (quitCtrl) {
-                    quitCtrl.notifyAll();
-                }
-            });
-            //要注意定时刷新
-            return true;
-        });
-
-        watchLocalEvent("OnModuleDisconnected", (w, keyVal, msg) -> {
-            String host = msg.getString("host");
-            int port = msg.getInteger("port");
-            is_online_ = false;
-            synchronized (quitCtrl) {
-                quitCtrl.notifyAll();
-            }
-            return true;
-        });
-    }
-
-    @Override
-    public void onServiceStop() {
-        is_online_ = false;
-        quitCtrl.notifyAll();
-        super.onServiceStop();
-    }
-
-    private void refreshJBotRegister() {
-        while(is_online_) {
-            prepareDataSetMethods();
-            autoRegisterJBotAPIDomains();
-            autoRegisterJBotDataSets();
-            SystemUtils.tryWaitforSingal(quitCtrl, 90 * 1000);
-        }
-        is_active_ = false;
-    }
-
-    private void prepareDataSetMethods() {
-        Class<?> cls = this.getClass();
-        while(JMgbusService.class.isAssignableFrom(cls)) {
-            Method[] methods = cls.getDeclaredMethods();
-            for (Method m : methods) {
-                JDataGetter a = m.getAnnotation(JDataGetter.class);
-                if (a != null) {
-                    Class<?> r = m.getReturnType();
-                    Class<?>[] pm = m.getParameterTypes();
-                    if (List.class.isAssignableFrom(r) && pm.length == 0) {
-                        registerJBotDataGetter(a, m.getName(), m);
-                    }
-                }
-            }
-            cls = cls.getSuperclass();
-        }
-    }
-
-    private void autoRegisterJBotDataSets() {
-        Class<?> cls = this.getClass();
-        while(JedgeJBotCBService.class.isAssignableFrom(cls)) {
-            Method[] methods = cls.getDeclaredMethods();
-            for (Method m : methods) {
-                JbotData a = m.getAnnotation(JbotData.class);
-                if (a != null) {
-                    Class<?> r = m.getReturnType();
-                    Class<?>[] pm = m.getParameterTypes();
-                    if (List.class.isAssignableFrom(r) && pm.length == 0) {
-                        String cbUri = String.format("/%s/%s", getName(), m.getName());
-                        registerJBotDataSet(a, m.getName(), module.getName(), cbUri);
-                    }
-                }
-            }
-            cls = cls.getSuperclass();
-        }
-    }
-
-
-    protected void autoRegisterJBotAPIDomains() {
-        Class<?> cls = this.getClass();
-        while(JMgbusService.class.isAssignableFrom(cls)) {
-            Method[] methods = cls.getDeclaredMethods();
-            for (Method m : methods) {
-                JbotApi a = m.getAnnotation(JbotApi.class);
-                if (a != null) {
-                    Class<?> r = m.getReturnType();
-                    Class<?>[] pm = m.getParameterTypes();
-                    if (QIData.class.isAssignableFrom(r) && pm.length == 1 && QIData.class.isAssignableFrom(pm[0])) {
-                        String cbUri = String.format("/%s/%s", getName(), m.getName());
-                        registerJBotAPIDomain(a, module.getName(), cbUri);
-                    }
-                }
-            }
-            cls = cls.getSuperclass();
-        }
-    }
-
-    private void registerJBotAPIDomain(JbotApi a, String moduleName, String cbUri) {
-        String domain = a.domain();
-        String dataset = a.dataset();   //创建API时需要的数据集
-        String disc = a.disc();
-        String role = a.role();
-        String format = a.msgFmt();     //消息格式,其中字段,需要对应于数据集
-        QIData req = new QData().putString("cbUri", cbUri).putString("src", moduleName)
-                .putString("key", domain).putString("dmd", disc).putString("rl", role)
-                .putString("pf", format).putString("ds", dataset);
-        synchronized (registeredDomainMap){
-            if(registeredDomainMap.containsKey(domain)) {
-                req.putInteger("dmid", registeredDomainMap.get(domain));
-            }
-        }
-        QIData re = postServiceRequest(sval_default_jbot_jedge, "/gpt/registerDomain", req);
-        if(!JMgbusUtil.isMgbusResultOk(re)) {
-            module.errLog(String.format("Fail to register Domain (%s) to %s : %s " , domain, sval_default_jbot_jedge, re.getString("msg")));
-        } else {
-            int dmId = re.getInteger("dmid");
-            if(dmId>-1) {
-                synchronized (registeredDomainMap) {
-                    registeredDomainMap.put(domain, dmId);  //也可能更新module
-                }
-            }
-            module.highLog(String.format("领域模块注册成功:%s (%d)", domain, dmId));
-        }
-    }
-
-    private void updateJBotDataSet(String domain, String words, JSONArray dataset) {
-        //更新数据集
-        QIData req = new QData().putString("domain", domain).putString("key", words).put("payload",dataset);
-        synchronized (registeredDomainMap) {
-            if(!registeredDomainMap.containsKey(domain)) {
-                module.errLog(String.format("Fail to register DataSet (%s) to %s : domain %s 尚未注册 " , words, sval_default_jbot_jedge, domain));
-                return;
-            }
-            req.putInteger("dmid", registeredDomainMap.get(domain));
-        }
-
-        int dsId;
-        synchronized (registeredDataSetMap){
-            if(!registeredDataSetMap.containsKey(words)) {
-                module.errLog(String.format("Fail to register DataSet (%s) to %s : domain %s 尚未注册 " , words, sval_default_jbot_jedge, domain));
-                return;
-            }
-            dsId = registeredDomainMap.get(words);
-            req.putInteger("dsid", dsId);
-        }
-        QIData re = postServiceRequest(sval_default_jbot_jedge, "/gpt/updateDataset", req);
-        if(!JMgbusUtil.isMgbusResultOk(re)) {
-            module.errLog(String.format("Fail to update DataSet (%s) to %s : %s " , words, sval_default_jbot_jedge, re.getString("msg")));
-        } else {
-            module.highLog(String.format("数据集更新成功:%s(%d)", words, dsId));
-        }
-    }
-
-    private void registerJBotDataSet(JbotData a, String initSet, String moduleName, String cbUri) {
-        String words = a.words();
-        String domain = a.domain();
-        boolean isNullable = a.nullable();
-        // 调用初始化函数得到
-        JSONArray initData = null;
-        synchronized (DataGetterMap) {
-            Method m = DataGetterMap.get(initSet);
-            if (m != null) {
-                try {
-                    Object re = m.invoke(this);
-                    if(re instanceof List) {
-                        initData =JedgeLlmUtil.JsonArrayFromStringList((List<String>)re);
-                    }
-                } catch (IllegalAccessException | InvocationTargetException e) {
-                    e.printStackTrace();
-                }
-            }
-        }
-
-        QIData req = new QData().putString("domain", domain).putString("cbUri", cbUri)
-                .putString("src", moduleName).putString("key", words)
-                .putBoolean("na", isNullable);
-        if(initData!=null) req.put("payload", initData);
-        synchronized (registeredDomainMap){
-            if(registeredDomainMap.containsKey(domain)) {
-                req.putInteger("dmid", registeredDomainMap.get(domain));
-            } else {
-                module.errLog(String.format("Fail to register DataSet (%s) to %s : domain %s 尚未注册 " , words, sval_default_jbot_jedge, domain));
-                return;
-            }
-        }
-        synchronized (registeredDataSetMap) {
-            if(registeredDataSetMap.containsKey(words)) {
-                req.putInteger("dsid", registeredDataSetMap.get(words));
-            }
-        }
-        QIData re = postServiceRequest(sval_default_jbot_jedge, "/gpt/registerDataset", req);
-        if(!JMgbusUtil.isMgbusResultOk(re)) {
-            module.errLog(String.format("Fail to register DataSet (%s) to %s : %s " , words, sval_default_jbot_jedge, re.getString("msg")));
-        } else {
-            int dsId = re.getInteger("dsid");
-            if(dsId>-1) {
-                synchronized (registeredDataSetMap) {
-                    registeredDataSetMap.put(words, dsId);  //也可能更新module
-                }
-            }
-            module.highLog(String.format("数据集注册成功:%s(%d)", words, dsId));
-        }
-    }
-
-
-    //刷新数据集(从Jbot向本地重新请求数据)
-    @MgbusApi
-    public QIData refreshDataSet(QIData eMsg) {
-        String dsKey = eMsg.getKey();
-        module.warnLog("Fresh Data set by : %s", dsKey);    //从数据集名称到dsKey名称
-        if(StringUtils.isValidStr(dsKey)) {
-            JSONArray initData = null;
-            synchronized (DataGetterMap) {
-                Method m = DataGetterMap.get(dsKey);
-                if (m != null) {
-                    try {
-                        Object re = m.invoke(this);
-                        if(re instanceof List) {
-                            initData =JedgeLlmUtil.JsonArrayFromStringList((List<String>)re);
-                        }
-                    } catch (IllegalAccessException | InvocationTargetException e) {
-                        e.printStackTrace();
-                    }
-                }
-            }
-            return JMgbusUtil.MgbusResult(200, "").put("payload", initData);
-        }
-        //
-        return JMgbusUtil.MgbusResult(401, "No Key");
-    }
-
-
-    private void registerJBotDataGetter(JDataGetter a, String DGetterKey, Method m) {
-        synchronized (DataGetterMap) {
-            DataGetterMap.put(DGetterKey, m);
-        }
-    }
-
-    public static List<String> loadDataSetFromString(String dsStr) {
-        List<String> re = new ArrayList<>();
-        QIData d  = QData.fromString(dsStr);
-        if(d instanceof QIDataList) {
-            for(Object o : ((QIDataList) d).asJsonArray()) {
-                if(o instanceof JSONObject) {
-                    re.add(((JSONObject) o).toJSONString());
-                }
-            }
-        } else {
-            re.add(d.toJSONString());
-        }
-        return re;
-    }
-
-    //两种情况,一种是json,一种是每行是json
-    public static List<String> loadDataSetFromFile(String fn) {
-        File dsFile = new File(fn);
-        if(dsFile.exists()) {
-            if(fn.endsWith(".ds")) {
-                List<String> lines = StringUtils.readStringLinesFromFile(fn);
-                List<String> re = new ArrayList<>();
-                for(String l : lines) {
-                    l = l.trim();
-                    if(StringUtils.isNotValidStr(l) || l.charAt(0) == '#') continue;
-                    QIData d = QData.fromString(l);
-                    re.add(d.toJSONString());
-                }
-                return re;
-            } else if(fn.endsWith(".json")) {
-                String dsStr = StringUtils.readStringFromFile(dsFile);
-                return loadDataSetFromString(dsStr);
-            }
-        }
-        return new ArrayList<>();
-    }
-
-}

+ 0 - 64
app/src/main/java/com/ch/jedge/jbot/intent/bot/JBotAppBase.java

@@ -1,64 +0,0 @@
-package com.ch.jedge.jbot.intent.bot;
-
-import com.ch.jedge.jbot.intent.JedgeJBotCBService;
-import com.ch.jedge.utils.JEVdbConfigUtil;
-import com.changhong.jedge.JESocketClient;
-import com.changhong.qlib.QData;
-import com.changhong.qlib.intf.QIData;
-import com.changhong.qlib.util.cmdline.ArgUtils;
-import com.changhong.qlib.util.cmdline.CmdUtils;
-import com.changhong.qlib.util.sync.SystemUtils;
-
-public class JBotAppBase  extends QData implements CmdUtils.CmdController {
-
-    public JBotAppBase(String botName) {
-        setName(botName);
-    }
-
-    @Override
-    public String getControllerName() {
-        return getName();
-    }
-
-    @Override
-    public void setControllerName(String s) {
-        setName(s);
-    }
-
-
-    public static void run(String appName, Class<? extends JedgeJBotCBService> serviceCls , String[] args) {
-
-        final JBotAppBase instance =
-                new JBotAppBase(appName);
-
-        JEVdbConfigUtil.loadConfigs();
-
-        JBotAppClient jsBot = JBotAppClient.getInstance(appName, serviceCls);
-        if(jsBot==null) {
-            JESocketClient.markLogSt("应用 [%s] 创建服务 (%s) 失败,退出!",appName, serviceCls.getSimpleName());
-            JEVdbConfigUtil.releaseConfigs();
-            return;
-        }
-        QIData param = ArgUtils.handleArgVList(args);
-
-        boolean runBack = JEVdbConfigUtil.setupInitConfigs(jsBot, param, appName);
-
-        if(!jsBot.start()) {
-            jsBot.errLog("Fail to start ap app : " + jsBot.getName());
-            return;
-        }
-
-        while(!jsBot.isActive()) {
-            //等待接入成功
-            jsBot.warnLog("Wait for apApp to connect to mgbus : " + jsBot.getName());
-            SystemUtils.tryWait(2000);
-        }
-
-        CmdUtils.run(instance, runBack, param);
-
-        jsBot.shutdown();
-
-        JEVdbConfigUtil.releaseConfigs();
-    }
-
-}

+ 0 - 30
app/src/main/java/com/ch/jedge/jbot/intent/bot/JBotAppClient.java

@@ -1,30 +0,0 @@
-package com.ch.jedge.jbot.intent.bot;
-
-import com.ch.jedge.jbot.intent.JedgeJBotCBService;
-import com.changhong.jedge.JMgbusClient;
-import com.changhong.jedge.JMgbusModual;
-
-import java.lang.reflect.Constructor;
-
-import static com.ch.jedge.jbot.JEJBotLLMConst.sval_default_llm_call_service;
-
-
-public class JBotAppClient extends JMgbusClient {
-
-    public JBotAppClient(String subnet, String mgc_name, int threadCount, boolean tryLocal) {
-        super(subnet, mgc_name, threadCount, tryLocal);
-    }
-
-    public static JBotAppClient getInstance(String botName, Class<? extends JedgeJBotCBService> serviceCls) {
-        JBotAppClient jLlmBot = new JBotAppClient("#0", botName, 10, true);
-        try {
-            Constructor<? extends JedgeJBotCBService> constructor = serviceCls.getConstructor(JMgbusModual.class);
-            JedgeJBotCBService service = constructor.newInstance(jLlmBot);
-            jLlmBot.bindService(sval_default_llm_call_service, service);
-        }catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
-        return jLlmBot;
-    }
-}

+ 0 - 189
app/src/main/java/com/ch/jedge/jbot/intent/param/JedgeDataSetter.java

@@ -1,189 +0,0 @@
-package com.ch.jedge.jbot.intent.param;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.ch.jedge.jbot.JedgeLlmUtil;
-import com.ch.jedge.jbot.knbase.JedgeGptApp;
-import com.changhong.jedge.JESocketClient;
-import com.changhong.jedge.JMgbusService;
-import com.changhong.qlib.QData;
-import com.changhong.qlib.util.NumberUtils;
-
-import java.util.*;
-
-import static com.ch.jedge.jbot.JEJBotLLMConst.ival_max_timeout_count;
-
-/**
- *  大模型的中文语义参数提取器
- *      结构:
- *      (1) 参数表, 参数取值表
- *      (2) 输入文字
- *      (3) 备选参数
- *      (4) 输出格式
- *      (5) 附加说明
- *
- *
- */
-public class JedgeDataSetter {
-
-    private static class JedgeDataSet {
-        public final int dsId;
-        private final boolean isNullable;
-        private final String srcMod;
-        private final String cbUri;
-        protected final JSONArray words = new JSONArray();
-        int ttl = 0;
-
-        public JedgeDataSet(JSONArray words) {
-            updateWords(words);
-            this.dsId = NumberUtils.randomInt(0x7FFFFFF);
-            this.isNullable = true;
-            this.srcMod = "";
-            this.cbUri = "";
-        }
-
-        public JedgeDataSet(String srcMod, String cbUri, JSONArray words, boolean nullable) {
-            updateWords(words);
-            this.dsId = NumberUtils.randomInt(0x7FFFFFF);
-            this.isNullable = nullable;
-            this.srcMod = srcMod;
-            this.cbUri = cbUri;
-        }
-
-        //mediaSearch:查询媒体咨询相关功能,根据用户提供的信息提取关键字,并查找对应的影片信息;
-        //mediaPlay:播放媒体,根据已经命中的媒体信息,去播放队对应的影片或歌曲,并设置对应的播放参数;
-        //mediaSave:记录用户的个性化喜好,根据已经播放的历史或内容,记住用户的一些播放参数;
-        public String getDatasetValueDef() {
-            StringBuilder re = new StringBuilder();
-            synchronized (words) {
-                for (Object w : this.words) {
-                    String disc = ((JSONObject) w).getString("disc");
-                    String valDisc = (disc!=null)?
-                            String.format("\"%s\"(%s);",((JSONObject)w).getString("key"), disc):
-                            String.format("\"%s\";",((JSONObject)w).getString("key"));
-                    re.append(valDisc);
-                }
-            }
-            return re.toString();
-        }
-
-        public String getValueKeyList() {
-            StringBuilder re = new StringBuilder();
-            synchronized (this.words) {
-                for (Object w : words) {
-                    String key = ((JSONObject) w).getString("key");
-                    if (re.length() > 0) re.append(',');
-                    re.append(key);
-                }
-            }
-            return re.toString();
-        }
-
-        public void updateWords(JSONArray words) {
-            this.ttl = 0;
-            synchronized (this.words) {
-                this.words.clear();
-                for (Object w : words) {
-                    if (w instanceof String) {
-                        w = QData.fromString((String) w).asJsonObject();
-                        this.words.add(w);
-                    } else if (w instanceof JSONObject)
-                        this.words.add(w);
-                }
-            }
-        }
-
-    }
-
-    private final JMgbusService service;
-    protected final String targetMessageFormat;
-    private final Map<String, JedgeDataSet> dataSetCache = new HashMap<>();
-    protected final JedgeLLMParamPicker dsPicker = new JedgeLLMParamPicker();
-
-    public JedgeDataSetter(JMgbusService service, String paramFormat) {
-        this.service = service;
-        this.targetMessageFormat = paramFormat;
-    }
-
-    //获取词库
-    public String getDatasetValueDefine(String pmKey) {
-        synchronized (dataSetCache) {
-            JedgeDataSet ds = dataSetCache.get(pmKey);
-            if(ds!=null) {
-                String dsStr = ds.getDatasetValueDef();
-                if(ds.isNullable) { dsStr += ",若无法取值,则字段为空;";}
-                return dsStr;
-            }
-        }
-        return "";
-    }
-
-    public String getDatasetValList(String dsKey) {
-        //"媒体指令"的取值列表:mediaSearch,mediaPlay,mediaSave;
-        synchronized (dataSetCache) {
-            JedgeDataSet ds = dataSetCache.get(dsKey);
-            if(ds!=null) {
-                String dsStr = String.format("\"%s\"的取值范围:%s",dsKey, ds.getValueKeyList());
-                if(ds.isNullable) { dsStr += ",若无法取值,则字段为空;";}
-                return dsStr;
-            }
-        }
-        return "";
-    }
-
-    public int updateDataset2Cache(int dsid, String dsKey, JSONArray words) {
-        if(JedgeGptApp.isDebugMode())
-            JESocketClient.LogSt("数据集更新(%s):%s",dsKey, words);
-        synchronized (dataSetCache) {
-            JedgeDataSet old = dataSetCache.get(dsKey);
-            if(old==null) {
-                old =  new JedgeDataSet(words);
-                dataSetCache.put(dsKey, old);
-                return old.dsId;
-            } else {
-                old.updateWords(words);
-            }
-        }
-        return dsid;
-    }
-
-    public int addDataSet(int dsid, String srcMod, String cbUri, String dsKey,
-                          JSONArray words, boolean nullable) {
-        //添加数据集
-//        if(JedgeGptApp.isDebugMode()) {
-//            JESocketClient.LogSt("创建数据集(%s):%s", dsKey, words);
-//        }
-        synchronized (dataSetCache) {
-            JedgeDataSet old = dataSetCache.get(dsKey);
-            if(old==null) {
-                old =  new JedgeDataSet(srcMod, cbUri, words, nullable);
-                dataSetCache.put(dsKey, old);
-                return old.dsId;
-            } else {
-                old.updateWords(words);
-            }
-        }
-        return dsid;
-    }
-
-
-    public void onHeartbeat() {
-        synchronized (dataSetCache) {
-            List<String> toDel = new ArrayList<>();
-            for(String key : dataSetCache.keySet()) {
-                JedgeDataSet dsCache = dataSetCache.get(key);
-                if(dsCache!=null) {
-                    if(dsCache.ttl>-1) dsCache.ttl ++;
-                    if(dsCache.ttl > ival_max_timeout_count ) {
-                        //超时退出
-                        toDel.add(key);
-                    }
-                }
-            }
-            for(String dmKey :toDel) {
-                dataSetCache.remove(dmKey);
-            }
-        }
-    }
-
-}

+ 0 - 11
app/src/main/java/com/ch/jedge/jbot/intent/param/JedgeLLMParamPicker.java

@@ -1,11 +0,0 @@
-package com.ch.jedge.jbot.intent.param;
-
-/**
- *  数据集数据提取:
- *  (1) 方式1:本地向service发起请求提取数据;
- *  (2) 方式2: service定时向本地service推送数据集。
- */
-
-
-public class JedgeLLMParamPicker {
-}

+ 3 - 3
app/src/main/java/com/ch/jedge/jbot/agent/JedgeGdeAgentRunner.java → app/src/main/java/com/ch/jedge/jbot/other/agent/JedgeGdeAgentRunner.java

@@ -1,7 +1,7 @@
-package com.ch.jedge.jbot.agent;
+package com.ch.jedge.jbot.other.agent;
 
-import com.ch.jedge.jbot.knbase.JedgeGptApp;
-import com.ch.jedge.jbot.knbase.intent.JedgeGdeQuery;
+import com.ch.jedge.jbot.other.knbase.JedgeGptApp;
+import com.ch.jedge.jbot.other.knbase.intent.JedgeGdeQuery;
 
 import java.util.HashMap;
 import java.util.Map;

+ 1 - 1
app/src/main/java/com/ch/jedge/jbot/agent/JedgeGdeConsts.java → app/src/main/java/com/ch/jedge/jbot/other/agent/JedgeGdeConsts.java

@@ -1,4 +1,4 @@
-package com.ch.jedge.jbot.agent;
+package com.ch.jedge.jbot.other.agent;
 
 public class JedgeGdeConsts {
     public static final String sval_default_app = "ChisLab";

+ 9 - 0
app/src/main/java/com/ch/jedge/jbot/other/agent/JedgeGdeObjective.java

@@ -0,0 +1,9 @@
+package com.ch.jedge.jbot.other.agent;
+
+/**
+ *  意图: 对应于某个目标:
+ *
+ */
+public class JedgeGdeObjective {
+
+}

+ 15 - 15
app/src/main/java/com/ch/jedge/jbot/agent/JedgeGdeSession.java → app/src/main/java/com/ch/jedge/jbot/other/agent/JedgeGdeSession.java

@@ -1,14 +1,14 @@
-package com.ch.jedge.jbot.agent;
+package com.ch.jedge.jbot.other.agent;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.ch.jedge.jbot.dict.JedgeWordItem;
-import com.ch.jedge.jbot.knbase.JedgeGptApp;
-import com.ch.jedge.jbot.knbase.JedgeGptDomain;
-import com.ch.jedge.jbot.knbase.JedgeLlmIntent;
-import com.ch.jedge.jbot.knbase.intent.JedgeGdeQuery;
-import com.ch.jedge.jbot.knbase.pool.JedgeGdeKnItemPool;
-import com.ch.jedge.jbot.session.JedgeGdeKeywordPool;
+import com.ch.jedge.jbot2.dict.JedgeWordItem;
+import com.ch.jedge.jbot.other.knbase.JedgeGptApp;
+import com.ch.jedge.jbot.other.knbase.JedgeGptDomain;
+import com.ch.jedge.jbot.other.knbase.JedgeLlmIntent;
+import com.ch.jedge.jbot.other.knbase.intent.JedgeGdeQuery;
+import com.ch.jedge.jbot.other.knbase.pool.JedgeGdeKnItemPool;
+import com.ch.jedge.jbot.other.session.JedgeGdeKeywordPool;
 import com.ch.jedge.jbot.session.JedgeServiceSession;
 import com.changhong.qlib.util.StringUtils;
 
@@ -17,8 +17,8 @@ import java.util.LinkedList;
 import java.util.Map;
 import java.util.Queue;
 
-import static com.ch.jedge.jbot.agent.JedgeGdeConsts.ival_max_active_domain_count;
-import static com.ch.jedge.jbot.agent.JedgeGdeConsts.sval_default_sys_role;
+import static com.ch.jedge.jbot.other.agent.JedgeGdeConsts.ival_max_active_domain_count;
+import static com.ch.jedge.jbot.other.agent.JedgeGdeConsts.sval_default_sys_role;
 
 /**
  *  核心的对话管理器,维护当前与用户的聊天状态:
@@ -74,11 +74,11 @@ public class JedgeGdeSession {
     }
 
     public void returnGptResponseMessage(String msg) {
-        mGdeApp.getBotService().returnGptResponseMessage(srcMod, cbUri, msg, false, false);
+         mGdeApp.getBotService().returnGptResponseMessage(srcMod, cbUri, msg, false, false);
     }
 
     public void returnGptErrorMessage(String msg) {
-        mGdeApp.getBotService().returnGptResponseMessage(srcMod, cbUri, msg, true, true);
+         mGdeApp.getBotService().returnGptResponseMessage(srcMod, cbUri, msg, true, true);
     }
 
     public void returnGptFinalMessage(String msg) {
@@ -286,7 +286,7 @@ public class JedgeGdeSession {
         //分析意图,利用关键动作+词性的匹配模式,在上下文中,去匹配意图
         //简单的意图匹配,当前的query的意图,是否复合当前的知识领域。
         if(!matchIntents(gdeQuery)) {
-            return null;
+                return null;
         }
         return gdeQuery;
     }
@@ -295,8 +295,8 @@ public class JedgeGdeSession {
         //增强知识到session缓存中,
         for( Object word : intent.words_ ) {
             if(word instanceof JSONObject
-                //专有名词,去检索内容
-            ) {
+                    //专有名词,去检索内容
+                    ) {
                 String wt = ((JSONObject) word).getString("t");
                 if("n".equals(wt) || "nz".equals(wt) || wt.startsWith("nr")) {
                     String keyText = ((JSONObject) word).getString("w");

+ 4 - 0
app/src/main/java/com/ch/jedge/jbot/other/base/JedgeLLMObject.java

@@ -0,0 +1,4 @@
+package com.ch.jedge.jbot.other.base;
+
+public class JedgeLLMObject {
+}

+ 4 - 0
app/src/main/java/com/ch/jedge/jbot/other/base/data/JedgeCacheAction.java

@@ -0,0 +1,4 @@
+package com.ch.jedge.jbot.other.base.data;
+
+public class JedgeCacheAction {
+}

+ 4 - 0
app/src/main/java/com/ch/jedge/jbot/other/base/data/JedgeCacheCard.java

@@ -0,0 +1,4 @@
+package com.ch.jedge.jbot.other.base.data;
+
+public class JedgeCacheCard {
+}

+ 4 - 0
app/src/main/java/com/ch/jedge/jbot/other/base/data/JedgeCacheObject.java

@@ -0,0 +1,4 @@
+package com.ch.jedge.jbot.other.base.data;
+
+public class JedgeCacheObject {
+}

+ 4 - 0
app/src/main/java/com/ch/jedge/jbot/other/base/data/JedgeNextModule.java

@@ -0,0 +1,4 @@
+package com.ch.jedge.jbot.other.base.data;
+
+public class JedgeNextModule {
+}

+ 4 - 0
app/src/main/java/com/ch/jedge/jbot/other/base/handler/JedgeInforGetter.java

@@ -0,0 +1,4 @@
+package com.ch.jedge.jbot.other.base.handler;
+
+public class JedgeInforGetter {
+}

+ 4 - 0
app/src/main/java/com/ch/jedge/jbot/other/base/handler/JedgeIntentComparor.java

@@ -0,0 +1,4 @@
+package com.ch.jedge.jbot.other.base.handler;
+
+public class JedgeIntentComparor {
+}

+ 4 - 0
app/src/main/java/com/ch/jedge/jbot/other/base/handler/JedgeIntentParser.java

@@ -0,0 +1,4 @@
+package com.ch.jedge.jbot.other.base.handler;
+
+public class JedgeIntentParser {
+}

+ 12 - 0
app/src/main/java/com/ch/jedge/jbot/other/base/handler/JedgeLLMCall.java

@@ -0,0 +1,12 @@
+package com.ch.jedge.jbot.other.base.handler;
+
+
+/**
+ *  对大模型的调用:
+ *      · 可以通过mgbus和http两种方式
+ *      · 支持chat式和Stream式两种方式
+ *      · 重点是chat式快速调用模式, 包括准备提示词,以及对返回文本的处理
+ */
+
+public class JedgeLLMCall {
+}

+ 8 - 0
app/src/main/java/com/ch/jedge/jbot/other/base/handler/JedgeStringHandler.java

@@ -0,0 +1,8 @@
+package com.ch.jedge.jbot.other.base.handler;
+
+/**
+ *  基础类, 对基本的字符串进行处理
+ *
+ */
+public class JedgeStringHandler {
+}

+ 4 - 0
app/src/main/java/com/ch/jedge/jbot/other/base/handler/JedgeWordCutter.java

@@ -0,0 +1,4 @@
+package com.ch.jedge.jbot.other.base.handler;
+
+public class JedgeWordCutter {
+}

+ 37 - 0
app/src/main/java/com/ch/jedge/jbot/other/base/readme.txt

@@ -0,0 +1,37 @@
+
+这里涉及到一些对基本的缓存对象和算法调用对象
+1、缓存对象
+(1) 知识卡片
+(2) 行动卡片/意图
+(3) 任务卡片/意图: 描述如何进行任务推理
+(4) 对话主题向量。   当前对话与当前对话主题归纳向量的距离,需要在一定范围之内,否则是一个新的对话。并且如果当前的对话在模型中没用答案,必须给出一定的提示。
+    ::如何判断当前的对话,与缓存中的知识均没有相关性?
+    ::
+
+2、算法调用接口
+(1) 分词
+(2) 实体词提取
+(3) 意图识别
+(4) 领域识别
+(5) 对话相关性
+
+
+
+
+对给定文本的处理逻辑关系列举:
+(1) 从给定文本集合及给定的参数提取要求,提取出必要的参数;
+    例如: 买张去成都的机票,     根据上下文周知识,获得地名等名称,
+(2) 对多个给定文本、问题短语和输出格式约束,给出指定的输出;
+(3) 遍历归纳多个文本分段中的内容,给出最终的统计学处理;
+(4) 通过给定文本,补齐任务规划过程中的缺失项。
+
+
+知识库+微调的方式。
+
+
+
+从语义或复杂文本中,提取出来的知识,被存放到指定的相似度文本库,或者知识图谱中;
+然后用复杂语义的理解,在一个语义执行器中,去命中各种意图,然后开始
+
+
+

+ 2 - 2
app/src/main/java/com/ch/jedge/jbot/corpus/CorpusTask.java → app/src/main/java/com/ch/jedge/jbot/other/corpus/CorpusTask.java

@@ -1,4 +1,4 @@
-package com.ch.jedge.jbot.corpus;
+package com.ch.jedge.jbot.other.corpus;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -199,7 +199,7 @@ public class CorpusTask {
         StringUtils.writeStringToFile(new File(fn), kl, null);
         if(kl.isEmpty())
             FileUtils.deleteDir(fn,"qa", false);
-        //FileUtils.deleteDir(fn,"", false);
+            //FileUtils.deleteDir(fn,"", false);
     }
 
     public void loadQuestions(String basePath) {

+ 13 - 13
app/src/main/java/com/ch/jedge/jbot/knbase/JedgeGptApp.java → app/src/main/java/com/ch/jedge/jbot/other/knbase/JedgeGptApp.java

@@ -1,16 +1,16 @@
-package com.ch.jedge.jbot.knbase;
+package com.ch.jedge.jbot.other.knbase;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ch.jedge.jbot.JedgeBotGptService;
-import com.ch.jedge.jbot.JedgeLlmUtil;
-import com.ch.jedge.jbot.agent.JedgeGdeSession;
-import com.ch.jedge.jbot.dict.JEDictUtil;
-import com.ch.jedge.jbot.dict.JedgeWordDict;
-import com.ch.jedge.jbot.knbase.domain.JedgeGdeDomainParer;
-import com.ch.jedge.jbot.knbase.intent.JedgeGdeQuery;
+import com.ch.jedge.utils.JedgeLlmUtil;
+import com.ch.jedge.jbot.other.agent.JedgeGdeSession;
+import com.ch.jedge.jbot2.dict.JEDictUtil;
+import com.ch.jedge.jbot2.dict.JedgeWordDict;
+import com.ch.jedge.jbot.other.knbase.domain.JedgeGdeDomainParer;
+import com.ch.jedge.jbot.other.knbase.intent.JedgeGdeQuery;
 import com.ch.jedge.jbot.session.JedgeServiceSession;
-import com.ch.jedge.utils.JEVdbConfigUtil;
+import com.ch.jedge.utils.JedgeBotConfigUtil;
 import com.changhong.jedge.JMgbusModual;
 import com.changhong.qlib.util.StringUtils;
 import com.changhong.qlib.util.file.FileUtils;
@@ -21,13 +21,13 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import static com.ch.jedge.jbot.agent.JedgeGdeConsts.ival_default_vector_size;
-import static com.ch.jedge.jbot.agent.JedgeGdeConsts.sval_default_domain;
+import static com.ch.jedge.jbot.other.agent.JedgeGdeConsts.ival_default_vector_size;
+import static com.ch.jedge.jbot.other.agent.JedgeGdeConsts.sval_default_domain;
 
 public class JedgeGptApp {
-    private static final boolean _debugActive = JEVdbConfigUtil.getConfigBoolean("vdb", "debug", false);
-    private static final boolean _gptHistoryEnabled = JEVdbConfigUtil.getConfigBoolean("vdb", "history", false);;
-    private static final int _vectorSize = JEVdbConfigUtil.getConfigInteger("vdb", "vectorSize", ival_default_vector_size);
+    private static final boolean _debugActive = JedgeBotConfigUtil.getConfigBoolean("vdb", "debug", false);
+    private static final boolean _gptHistoryEnabled = JedgeBotConfigUtil.getConfigBoolean("vdb", "history", false);;
+    private static final int _vectorSize = JedgeBotConfigUtil.getConfigInteger("vdb", "vectorSize", ival_default_vector_size);
 
     protected final Map<String, JedgeGptDomain> domains_ = new HashMap<>();
     private final String mAppName;

+ 2 - 2
app/src/main/java/com/ch/jedge/jbot/knbase/JedgeGptDialogEngine.java → app/src/main/java/com/ch/jedge/jbot/other/knbase/JedgeGptDialogEngine.java

@@ -1,4 +1,4 @@
-package com.ch.jedge.jbot.knbase;
+package com.ch.jedge.jbot.other.knbase;
 
 import com.alibaba.fastjson.JSONArray;
 import com.ch.jedge.jbot.JedgeBotGptService;
@@ -13,7 +13,7 @@ import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 
-import static com.ch.jedge.jbot.agent.JedgeGdeConsts.sval_default_domain_fn;
+import static com.ch.jedge.jbot.other.agent.JedgeGdeConsts.sval_default_domain_fn;
 
 /**
  *  这是一个对话引擎:

+ 6 - 6
app/src/main/java/com/ch/jedge/jbot/knbase/JedgeGptDomain.java → app/src/main/java/com/ch/jedge/jbot/other/knbase/JedgeGptDomain.java

@@ -1,17 +1,17 @@
-package com.ch.jedge.jbot.knbase;
+package com.ch.jedge.jbot.other.knbase;
 
 import com.alibaba.fastjson.JSONArray;
-import com.ch.jedge.jbot.dict.JedgeWordDict;
-import com.ch.jedge.jbot.dict.JedgeWordItem;
-import com.ch.jedge.jbot.knbase.domain.JedgeGdeDomainBlock;
+import com.ch.jedge.jbot2.dict.JedgeWordDict;
+import com.ch.jedge.jbot2.dict.JedgeWordItem;
+import com.ch.jedge.jbot.other.knbase.domain.JedgeGdeDomainBlock;
 import com.changhong.qlib.QData;
 import com.changhong.qlib.util.StringUtils;
 
 import java.util.HashMap;
 import java.util.Map;
 
-import static com.ch.jedge.jbot.agent.JedgeGdeConsts.sval_default_sys_role;
-import static com.ch.jedge.jbot.JEJBotLLMConst.sval_modual_word_cut;
+import static com.ch.jedge.jbot.other.agent.JedgeGdeConsts.sval_default_sys_role;
+import static com.ch.jedge.utils.JedgeBotConst.sval_modual_word_cut;
 
 /**
  *  动态领域,

+ 4 - 4
app/src/main/java/com/ch/jedge/jbot/knbase/JedgeLlmIntent.java → app/src/main/java/com/ch/jedge/jbot/other/knbase/JedgeLlmIntent.java

@@ -1,9 +1,9 @@
-package com.ch.jedge.jbot.knbase;
+package com.ch.jedge.jbot.other.knbase;
 
 import com.alibaba.fastjson.JSONArray;
-import com.ch.jedge.jbot.agent.JedgeGdeSession;
-import com.ch.jedge.jbot.knbase.intent.JedgeGdeQuery;
-import com.ch.jedge.jbot.knbase.query.JedgeGptQueryIntent;
+import com.ch.jedge.jbot.other.agent.JedgeGdeSession;
+import com.ch.jedge.jbot.other.knbase.intent.JedgeGdeQuery;
+import com.ch.jedge.jbot.other.knbase.query.JedgeGptQueryIntent;
 import com.ch.jedge.jbot.session.JedgeServiceSession;
 import com.changhong.qlib.util.StringUtils;
 

+ 1 - 1
app/src/main/java/com/ch/jedge/jbot/knbase/domain/JedgeGdeDomainBlock.java → app/src/main/java/com/ch/jedge/jbot/other/knbase/domain/JedgeGdeDomainBlock.java

@@ -1,4 +1,4 @@
-package com.ch.jedge.jbot.knbase.domain;
+package com.ch.jedge.jbot.other.knbase.domain;
 
 import com.changhong.qlib.util.StringUtils;
 

+ 3 - 3
app/src/main/java/com/ch/jedge/jbot/knbase/domain/JedgeGdeDomainParer.java → app/src/main/java/com/ch/jedge/jbot/other/knbase/domain/JedgeGdeDomainParer.java

@@ -1,7 +1,7 @@
-package com.ch.jedge.jbot.knbase.domain;
+package com.ch.jedge.jbot.other.knbase.domain;
 
-import com.ch.jedge.jbot.knbase.JedgeGptApp;
-import com.ch.jedge.jbot.knbase.JedgeGptDomain;
+import com.ch.jedge.jbot.other.knbase.JedgeGptApp;
+import com.ch.jedge.jbot.other.knbase.JedgeGptDomain;
 import com.changhong.qlib.util.StringUtils;
 import com.changhong.qlib.util.file.FileUtils;
 

+ 9 - 0
app/src/main/java/com/ch/jedge/jbot/other/knbase/intent/JedgeGdeIntentParser.java

@@ -0,0 +1,9 @@
+package com.ch.jedge.jbot.other.knbase.intent;
+
+
+/**
+ *
+ */
+public class JedgeGdeIntentParser {
+
+}

+ 4 - 3
app/src/main/java/com/ch/jedge/jbot/knbase/intent/JedgeGdeQuery.java → app/src/main/java/com/ch/jedge/jbot/other/knbase/intent/JedgeGdeQuery.java

@@ -1,9 +1,10 @@
-package com.ch.jedge.jbot.knbase.intent;
+package com.ch.jedge.jbot.other.knbase.intent;
+
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.ch.jedge.jbot.agent.JedgeGdeSession;
-import com.ch.jedge.jbot.knbase.JedgeGptApp;
+import com.ch.jedge.jbot.other.agent.JedgeGdeSession;
+import com.ch.jedge.jbot.other.knbase.JedgeGptApp;
 
 import java.util.ArrayList;
 import java.util.List;

+ 17 - 0
app/src/main/java/com/ch/jedge/jbot/other/knbase/intent/readme.txt

@@ -0,0 +1,17 @@
+
+
+将:
+  · parser 用于:
+    (1) 分词
+    (2) 处理短语,去掉短语动词的影响
+    (3) 依靠动词+名词的意图,和领域来进行意图匹配
+    (4) 对没有动词的短语,依靠名词性短语,根据名词在特定领域或意图
+    (5)
+  · intent,相当于一个query转化后的query结构
+    表现一个对话的语义。一个新的短语,可能给原有的intent添加新的参数或状态。
+    一个复合的语义,也可能是多段话,分析出多个intent来。
+
+  · 一个总体intent,也可能分析出多个子的intent出来,然后intent被分发时,可能时本地执行,也可能去调用其它的大模型。
+    调用后,可能是立即返回,也可能是stream返回。
+    返回的数据,可能直接呈现,也可能被缓存后呈现。那么缓存需要一定的时间,来进行过滤。
+  ·

+ 11 - 0
app/src/main/java/com/ch/jedge/jbot/other/knbase/pool/JedgeGdeIntentPool.java

@@ -0,0 +1,11 @@
+package com.ch.jedge.jbot.other.knbase.pool;
+
+
+/**
+ *  当前领域的意图池
+ *      · 允许用户通过意图,来切换对话领域。
+ *      · 在用户没用词汇表达意图时,可根据上次对话的意图,推测下次语言的意图。
+ */
+public class JedgeGdeIntentPool {
+
+}

+ 8 - 8
app/src/main/java/com/ch/jedge/jbot/knbase/pool/JedgeGdeKnItemPool.java → app/src/main/java/com/ch/jedge/jbot/other/knbase/pool/JedgeGdeKnItemPool.java

@@ -1,12 +1,12 @@
-package com.ch.jedge.jbot.knbase.pool;
+package com.ch.jedge.jbot.other.knbase.pool;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.ch.jedge.jbot.agent.JedgeGdeSession;
-import com.ch.jedge.jbot.knbase.JedgeGptApp;
-import com.ch.jedge.jbot.knbase.JedgeGptDomain;
-import com.ch.jedge.jbot.knbase.domain.JedgeGdeDomainBlock;
-import com.ch.jedge.jbot.knbase.intent.JedgeGdeQuery;
+import com.ch.jedge.jbot.other.agent.JedgeGdeSession;
+import com.ch.jedge.jbot.other.knbase.JedgeGptApp;
+import com.ch.jedge.jbot.other.knbase.JedgeGptDomain;
+import com.ch.jedge.jbot.other.knbase.domain.JedgeGdeDomainBlock;
+import com.ch.jedge.jbot.other.knbase.intent.JedgeGdeQuery;
 import com.changhong.jedge.JMgbusUtil;
 import com.changhong.qlib.QData;
 import com.changhong.qlib.intf.QIData;
@@ -15,8 +15,8 @@ import com.changhong.qlib.util.StringUtils;
 import java.math.BigDecimal;
 import java.util.*;
 
-import static com.ch.jedge.jbot.agent.JedgeGdeConsts.ival_max_hotLevel_val;
-import static com.ch.jedge.jbot.JEJBotLLMConst.*;
+import static com.ch.jedge.jbot.other.agent.JedgeGdeConsts.ival_max_hotLevel_val;
+import static com.ch.jedge.utils.JedgeBotConst.*;
 
 
 public class JedgeGdeKnItemPool {

+ 6 - 6
app/src/main/java/com/ch/jedge/jbot/knbase/query/JedgeGptQueryIntent.java → app/src/main/java/com/ch/jedge/jbot/other/knbase/query/JedgeGptQueryIntent.java

@@ -1,15 +1,15 @@
-package com.ch.jedge.jbot.knbase.query;
+package com.ch.jedge.jbot.other.knbase.query;
 
-import com.ch.jedge.jbot.agent.JedgeGdeSession;
-import com.ch.jedge.jbot.knbase.JedgeGptApp;
-import com.ch.jedge.jbot.knbase.JedgeLlmIntent;
-import com.ch.jedge.jbot.knbase.intent.JedgeGdeQuery;
+import com.ch.jedge.jbot.other.agent.JedgeGdeSession;
+import com.ch.jedge.jbot.other.knbase.JedgeGptApp;
+import com.ch.jedge.jbot.other.knbase.JedgeLlmIntent;
+import com.ch.jedge.jbot.other.knbase.intent.JedgeGdeQuery;
 import com.ch.jedge.jbot.session.JedgeServiceSession;
 import com.changhong.jedge.JMgbusUtil;
 import com.changhong.qlib.QData;
 import com.changhong.qlib.intf.QIData;
 
-import static com.ch.jedge.jbot.JEJBotLLMConst.sval_module_llm;
+import static com.ch.jedge.utils.JedgeBotConst.sval_module_llm;
 
 public class JedgeGptQueryIntent extends JedgeLlmIntent {
 

+ 5 - 0
app/src/main/java/com/ch/jedge/jbot/other/llm/JedgeGdeLLMCall.java

@@ -0,0 +1,5 @@
+package com.ch.jedge.jbot.other.llm;
+
+public class JedgeGdeLLMCall {
+
+}

+ 5 - 4
app/src/main/java/com/ch/jedge/jbot/session/JedgeGdeKeywordPool.java → app/src/main/java/com/ch/jedge/jbot/other/session/JedgeGdeKeywordPool.java

@@ -1,15 +1,16 @@
-package com.ch.jedge.jbot.session;
+package com.ch.jedge.jbot.other.session;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ch.jedge.jbot.JedgeBotGptService;
-import com.ch.jedge.jbot.agent.JedgeGdeSession;
-import com.ch.jedge.jbot.knbase.JedgeGptApp;
+import com.ch.jedge.jbot.other.agent.JedgeGdeSession;
+import com.ch.jedge.jbot.other.knbase.JedgeGptApp;
+import com.ch.jedge.jbot.session.JedgeServiceSession;
 import com.changhong.qlib.util.StringUtils;
 
 import java.util.*;
 
-import static com.ch.jedge.jbot.JEJBotLLMConst.*;
+import static com.ch.jedge.utils.JedgeBotConst.*;
 
 public class JedgeGdeKeywordPool {
 

+ 7 - 0
app/src/main/java/com/ch/jedge/jbot/other/session/JedgeGptTopic.java

@@ -0,0 +1,7 @@
+package com.ch.jedge.jbot.other.session;
+
+
+
+public class JedgeGptTopic {
+
+}

+ 13 - 4
app/src/main/java/com/ch/jedge/jbot/session/JedgeServiceSession.java

@@ -2,11 +2,12 @@ package com.ch.jedge.jbot.session;
 
 import com.alibaba.fastjson.JSONArray;
 import com.ch.jedge.jbot.JedgeBotGptService;
-import com.ch.jedge.jbot.agent.JedgeGdeSession;
-import com.ch.jedge.jbot.knbase.JedgeGptApp;
+import com.ch.jedge.jbot.other.agent.JedgeGdeSession;
+import com.ch.jedge.jbot.other.knbase.JedgeGptApp;
 import com.changhong.qlib.util.Log.ISLog;
 
-import static com.ch.jedge.jbot.JEJBotLLMConst.max_history_size;
+import static com.ch.jedge.utils.JedgeBotConst.max_history_size;
+import static com.ch.jedge.utils.JedgeBotConst.max_history_total_size;
 
 
 /**
@@ -77,7 +78,7 @@ public class JedgeServiceSession {
         }
         String log;
         log =  history_.toJSONString();
-        while (log.length()>1460) {
+        while (log.length()>max_history_total_size) {  //指令缓存最大256个
             history_.remove(0); //移除第0个聊天历史
             log =  (history_.toJSONString());
         }
@@ -101,4 +102,12 @@ public class JedgeServiceSession {
     public JedgeBotGptService getGptBotService() {
         return mBotService;
     }
+
+    public void addLastDomain(String domain) {
+
+    }
+
+    public String getLastDomain() {
+        return null;
+    }
 }

+ 11 - 6
app/src/main/java/com/ch/jedge/jbot2/JBot2Java.java

@@ -11,11 +11,16 @@ public class JBot2Java extends JBotAppBase {
         super(botName);
     }
 
-    public static void main(String[] args) {
-        Class<? extends JMgbusService>[] classes =
-                (Class<? extends JMgbusService>[]) new Class<?>[]{JedgeBotGptService.class, JedgeVoiceBotService.class, JedgeGlmBridgeService.class};
-        run("jbot",
-                new String[] {sval_default_gpt_service,sval_default_gpt_voice_service, sval_default_glm6b_service},
-                classes, args);
+//    public static void main(String[] args) {
+//        Class<? extends JMgbusService>[] classes =
+//                (Class<? extends JMgbusService>[]) new Class<?>[]{JedgeBotGptService.class, JedgeVoiceBotService.class, JedgeGlmBridgeService.class};
+//        run("jbot",
+//                new String[] {sval_default_gpt_service,sval_default_gpt_voice_service, sval_default_glm6b_service},
+//                classes, args);
+//    }
+
+    public static void jbot_main(String[] args) {
+        run("jbot", sval_default_gpt_service,
+                JedgeBotGptService.class, args);
     }
 }

+ 20 - 10
app/src/main/java/com/ch/jedge/jbot2/JedgeBotGptService.java

@@ -48,15 +48,15 @@ public class JedgeBotGptService extends JMgbusService {
         smartTaskContext = new JedgeSmartTaskContext(llmCtx);
         auto_remove_call_info = false;
 
-        kn_talk_log_file = talk_log_org_ = FileUtils.contactPath("./", "logs");
-        try {
-            new File(talk_log_org_).mkdirs();
-        } catch (Exception ignored) {}
-        talk_log_org_ = FileUtils.contactPath(talk_log_org_,"userAsk.log");
-        kn_talk_log_file = FileUtils.contactPath(kn_talk_log_file,"knTalk.log");
+//        kn_talk_log_file = talk_log_org_ = FileUtils.contactPath("./", "logs");
+//        try {
+//            new File(talk_log_org_).mkdirs();
+//        } catch (Exception ignored) {}
+//        talk_log_org_ = FileUtils.contactPath(talk_log_org_,"userAsk.log");
+//        kn_talk_log_file = FileUtils.contactPath(kn_talk_log_file,"knTalk.log");
 
         //加载动态词库
-        JEDictUtil.loadStaticCommonDicts(dict_, FileUtils.contactPath("./", "cfg", "dict", "common"));
+//        JEDictUtil.loadStaticCommonDicts(dict_, FileUtils.contactPath("./", "cfg", "dict", "common"));
 
         watchLocalEvent("OnModuleConnected", (w, keyVal, msg) -> {
             String host = msg.getString("host");
@@ -150,6 +150,10 @@ public class JedgeBotGptService extends JMgbusService {
             }
         }
 
+        QIData msg = new QData();
+        msg.putString("text", prompt);
+        postServiceMessage("tvmufis", "/tvmfs/usermsg", msg);
+
         JedgeTalkSession s = findSession(req, prompt);
 
         if(!s.isStream) {  //非流式请求,目前只针对chatGPT
@@ -157,7 +161,7 @@ public class JedgeBotGptService extends JMgbusService {
         }
 
         String finalPrompt = prompt;
-        module.postThread(() -> {
+//        module.postThread(() -> {
             if(s.knTalk) {
                 module.highLog(String.format("GPT Prompt>>%s", finalPrompt));
                 //根据各种类对象,完成对 提示词的多级划分。
@@ -167,7 +171,7 @@ public class JedgeBotGptService extends JMgbusService {
                 knTalkLog(finalPrompt);
                 makeRealGptStreamCall(s, finalPrompt);
             }
-        });
+//        });
 
         QIData resp = JedgeLlmUtil.simpleOk();
         resp.put("sid", s.sid);
@@ -332,6 +336,12 @@ public class JedgeBotGptService extends JMgbusService {
         }
         d.put("nb",true);
         msg.put("~c", d);
+
+        QIData msg2 = new QData();
+        msg2.putString("msg", txtMessage);
+        msg2.putBoolean("end", isEndMsg);
+        postServiceMessage("tvmufis", "/tvmfs/glmmsg", msg2);
+
         return msg;
     }
 
@@ -407,7 +417,7 @@ public class JedgeBotGptService extends JMgbusService {
     private void knTalkLog(String prompt, boolean succ) {
         String log =  "["+ TimeUtils.getNowShortStrWithMillis()+"] ["+(succ?"SUC":"FAL")+"]>>" + prompt;
         log = log.replaceAll( "\n","");
-        FileUtils.appendLine(kn_talk_log_file, log+"\n", "UTF-8");
+//        FileUtils.appendLine(kn_talk_log_file, log+"\n", "UTF-8");
     }
 
     protected JedgeTalkSession findSession(QIData req, String prompt) {

+ 1 - 1
app/src/main/java/com/ch/jedge/jbot2/context/JedgeSmartTaskContext.java

@@ -19,7 +19,7 @@ public class JedgeSmartTaskContext extends JedgeLLMBaseObject {
         //世界模型
         dmWorld = new JedgeLLMDmWorld(llmCtx);
         //加载系统默认的领域
-        dmWorld.loadStaticWorldDefs("./cfg/llm/world");
+        dmWorld.loadStaticWorldDefs("/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/llm/world");
         //世界任务池
         taskPool = new JedgeLLMTaskPool(llmCtx, KnWorld, dmWorld);
         //启动任务池

+ 1 - 1
app/src/main/java/com/ch/jedge/jbot2/llm/pickers/JedgeSmartHomeActionPicker.java

@@ -10,6 +10,6 @@ public class JedgeSmartHomeActionPicker extends JedgeLLMParamPicker {
 
     public JedgeSmartHomeActionPicker(JedgeLLMContext llmCtx) {
         super(llmCtx);
-        loadPickerFromFile("./cfg/picker/action/index.json");
+        loadPickerFromFile("/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/picker/action/index.json");
     }
 }

+ 3 - 0
app/src/main/java/com/ch/jedge/jbot2/llm/request/JedgeLLMCOTRequest.java

@@ -1,6 +1,7 @@
 package com.ch.jedge.jbot2.llm.request;
 
 
+import com.ch.jedge.jbot2.intent.bot.JBotAppBase;
 import com.ch.jedge.jbot2.llm.JedgeLLMContext;
 import com.changhong.qlib.util.StringUtils;
 
@@ -42,6 +43,8 @@ public class JedgeLLMCOTRequest extends JedgeLLMRequest {
                         "用户输入:{query},让我们一步一步地分析:", role, targets, cmd ,fmt);
         if(StringUtils.isValidStr(prefix))
             this.template_ = prefix + "," + this.template_;
+//        if(JBotAppBase.isDebugMode())
+            llmContext.module.warnLog("template reset to : %s", template_);
     }
 }
 

+ 2 - 1
app/src/main/java/com/ch/jedge/jbot2/llm/request/JedgeLLMFilterRequest.java

@@ -48,7 +48,8 @@ public class JedgeLLMFilterRequest extends JedgeLLMRequest {
     @Override
     public String getRealPrompt(JedgeTalkSession s, String query, String[] para) {
         String p = super.getRealPrompt(s, query, para);
-        return p.replaceAll("\\{domain}", para[0]);
+//        return p.replaceAll("\\{domain}", para[0]);
+        return p.replace("{domain}", para[0]);
     }
 }
 

+ 3 - 2
app/src/main/java/com/ch/jedge/jbot2/llm/request/JedgeLLMRequest.java

@@ -47,7 +47,8 @@ public class JedgeLLMRequest extends JedgeLLMBaseObject {
 //    }
 
     public String getRealPrompt(JedgeTalkSession s, String query, String[] para) {
-        return template_.replaceAll("\\{query}", query);
+//        return template_.replaceAll("\\{query}", query);
+        return template_.replace("{query}", query);
     }
 
     public QIData makeChatRequest(JedgeTalkSession s, String realQuery) {
@@ -106,7 +107,7 @@ public class JedgeLLMRequest extends JedgeLLMBaseObject {
         if(StringUtils.isValidStr(prefix))
             this.template_ = prefix + "," + this.template_;
 //        if(JBotAppBase.isDebugMode())
-//            llmContext.module.warnLog("template reset to : %s", template_);
+            llmContext.module.warnLog("template reset to : %s", template_);
     }
 
 }

+ 1 - 1
app/src/main/java/com/ch/jedge/jbot2/llm/world/knl/JedgeDomainSelector.java

@@ -9,7 +9,7 @@ public class JedgeDomainSelector extends JedgeLLMParamPicker {
 
     public JedgeDomainSelector(JedgeLLMContext llmContext) {
         super(llmContext, JedgeLLMRequest.class);
-        loadPickerFromFile("./cfg/picker/system/domain.json");
+        loadPickerFromFile("/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/picker/system/domain.json");
     }
 
 }

+ 1 - 1
app/src/main/java/com/ch/jedge/jbot2/llm/world/knl/JedgeLLMKnWorld.java

@@ -46,7 +46,7 @@ public class JedgeLLMKnWorld extends JedgeLLMBaseObject {
         domainSelector = new JedgeDomainSelector(llmCtx);
 //        domainContentFilter = new JedgeContentCutter(llmCtx);
         if(JedgeBotConst.enableSmartTaskCreate) {
-            String sdPath = "./cfg/domains/system";
+            String sdPath = "/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/domains/system";
             domainSystem = new JedgeSystemKnDomain(llmCtx, sdPath);
             if (domainSystem.isEmpty()) {
                 llmCtx.module.errLog("系统领域加载失败!", sdPath);

+ 1 - 1
app/src/main/java/com/ch/jedge/jbot2/llm/world/knl/task/JedgeContentCutter.java

@@ -8,6 +8,6 @@ public class JedgeContentCutter extends JedgeLLMParamPicker {
 
     public JedgeContentCutter(JedgeLLMContext llmContext) {
         super(llmContext, JedgeLLMFilterRequest.class);
-        loadPickerFromFile("./cfg/picker/system/cutter.json");
+        loadPickerFromFile("/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/picker/system/cutter.json");
     }
 }

+ 1 - 1
app/src/main/java/com/ch/jedge/jbot2/llm/world/model/JedgeMdDomain.java

@@ -25,7 +25,7 @@ public class JedgeMdDomain extends JedgeKnObject  {
     public JedgeMdDomain(JedgeLLMContext llmContext, QIData initData) {
         super(llmContext, initData);
         objectSelector = new JedgeLLMParamPicker(llmContext);
-        objectSelector.loadPickerFromFile("./cfg/picker/system/objectSel.json");
+        objectSelector.loadPickerFromFile("/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/picker/system/objectSel.json");
     }
 
     //自动移除对象等数据

+ 1 - 1
app/src/main/java/com/ch/jedge/jbot2/llm/world/task/JedgeTaskTester.java

@@ -8,7 +8,7 @@ public class JedgeTaskTester extends JedgeLLMParamPicker {
 
     public JedgeTaskTester(JedgeLLMContext llmContext) {
         super(llmContext);
-        loadPickerFromFile("./cfg/picker/system/task.json");
+        loadPickerFromFile("/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/cfg/picker/system/task.json");
     }
 
     public String checkTaskType(JedgeTalkSession s, String query) {

+ 1 - 1
app/src/main/java/com/ch/jedge/llm/filter/glm/MainActivity.java

@@ -69,7 +69,7 @@ public class MainActivity extends AppCompatActivity {
         BaseJedgeService.startJedgeService(this , dir, jedgeBasePath, "llm", JGlmService.class);
         BaseJedgeService.startJedgeService(this , dir, jedgeBasePath, "tvass", TVAgentService.class);
         BaseJedgeService.startJedgeService(this , dir, jedgeBasePath, "tvmufis", TVMufisService.class);
-        BaseJedgeService.startJedgeService(this , dir, jedgeBasePath, "jsmart", PanleAgentService.class);
+//        BaseJedgeService.startJedgeService(this , dir, jedgeBasePath, "jsmart", PanleAgentService.class);
 
         //注册广播
         registerReceiver(new AsrMsgReceiver(), asr_filter);

+ 3 - 2
app/src/main/java/com/ch/jedge/llm/filter/glm/service/JBotService.java

@@ -1,6 +1,6 @@
 package com.ch.jedge.llm.filter.glm.service;
 
-import com.ch.jedge.jbot.JBotJava;
+import com.ch.jedge.jbot2.JBot2Java;
 
 public class JBotService extends BaseJedgeService {
 
@@ -16,7 +16,8 @@ public class JBotService extends BaseJedgeService {
     public void handleStartService(String dir, String dir_cache){
         String[] args = new String[1];
         args[0] = "ppp";
-        JBotJava.jbot_main(args);
+//        JBotJava.jbot_main(args);
+        JBot2Java.jbot_main(args);
     }
 
 }

+ 2 - 2
app/src/main/java/com/ch/jedge/llm/filter/glm/service/JGlmService.java

@@ -1,6 +1,6 @@
 package com.ch.jedge.llm.filter.glm.service;
 
-import com.ch.jedge.glm.JGlmJava;
+import com.ch.jedge.glm.JedgeGlmDriver;
 
 public class JGlmService extends BaseJedgeService {
 
@@ -16,7 +16,7 @@ public class JGlmService extends BaseJedgeService {
     public void handleStartService(String dir, String dir_cache){
         String[] args = new String[1];
         args[0] = "ppp";
-        JGlmJava.glm_main(args);
+        JedgeGlmDriver.glm_main(args);
     }
 
 }

+ 8 - 2
app/src/main/java/com/ch/jedge/tvmufis/JeageTVBridge.java

@@ -106,6 +106,9 @@ public class JeageTVBridge {
         }
     }
     public void TVsetSoundMode(String mode) {
+        if(mode.isEmpty())
+            return;
+
         TVManager tvm = TVManager.getInstance(tvMufisService);
         boolean ret = false;
         try {
@@ -125,6 +128,9 @@ public class JeageTVBridge {
         }
     }
     public void TVsetPictureMode(String mode) {
+        if(mode.isEmpty())
+            return;
+
         TVManager tvm = TVManager.getInstance(tvMufisService);
         boolean ret = false;
         try {
@@ -186,8 +192,8 @@ public class JeageTVBridge {
 //
 //        if(file.isEmpty())
 //            return;
-//        String file = "/storage/8688-F2B5/vedio/视频2.mp4";
-        String file = "/sdcard/Movies/5.mp4";
+        String file = "/storage/8688-F2B5/vedio/视频2.mp4";
+//        String file = "/sdcard/Movies/5.mp4";
         TVManager tvm = TVManager.getInstance(tvMufisService);
         try {
 

+ 4 - 8
app/src/main/java/com/ch/jedge/tvmufis/TvMufis.java

@@ -1,10 +1,6 @@
 package com.ch.jedge.tvmufis;
 
-import static com.ch.jedge.jbot.JEJBotLLMConst.sval_modual_glm_llm;
-
-import com.ch.jedge.glm.JGlmJava;
-import com.ch.jedge.glm.JedgeGlmDriverClient;
-import com.ch.jedge.utils.JEVdbConfigUtil;
+import com.ch.jedge.utils.JedgeBotConfigUtil;
 import com.changhong.qlib.QData;
 import com.changhong.qlib.intf.QIData;
 import com.changhong.qlib.util.cmdline.ArgUtils;
@@ -34,14 +30,14 @@ public class TvMufis extends QData implements CmdUtils.CmdController {
 
     public static void TvMufis_main(String[] args) {
 
-        JEVdbConfigUtil.loadConfigs();
+        JedgeBotConfigUtil.loadConfigs();
 
         JedgeTvMufisClient tvMufisClient = JedgeTvMufisClient.getInstance();
 
         QIData param = ArgUtils.handleArgVList(args);
 
         //加载mgbus的服务器配置参数
-        boolean runBack = JEVdbConfigUtil.setupInitConfigs(tvMufisClient, param, tvmufisName);
+        boolean runBack = JedgeBotConfigUtil.setupInitConfigs(tvMufisClient, param, tvmufisName);
 
         if(!tvMufisClient.start()) {
             tvMufisClient.errLog("Fail to start ap app : " + tvMufisClient.getName());
@@ -58,7 +54,7 @@ public class TvMufis extends QData implements CmdUtils.CmdController {
 
         tvMufisClient.shutdown();
 
-        JEVdbConfigUtil.releaseConfigs();
+        JedgeBotConfigUtil.releaseConfigs();
     }
 
 }

+ 0 - 128
app/src/main/java/com/ch/jedge/utils/JEVdbConfigUtil.java

@@ -1,128 +0,0 @@
-package com.ch.jedge.utils;
-
-import com.changhong.jedge.JMgbusClient;
-import com.changhong.qlib.QData;
-import com.changhong.qlib.intf.QIData;
-import com.changhong.qlib.util.StringUtils;
-import com.changhong.qlib.util.file.FileUtils;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static com.ch.jedge.jbot.JEJBotLLMConst.sval_milvus_cfg_path;
-
-public class JEVdbConfigUtil {
-    protected static final Map<String, QIData> mConfigs= new HashMap<>();
-
-    public static void loadConfigs() {
-        FileUtils.listDirFiles(sval_milvus_cfg_path, file -> {
-            if(!file.getName().endsWith(".json"))
-                return null;
-            QIData cfgData = QData.fromFile(file);
-            if(cfgData.isEmpty()) return null;
-            synchronized (mConfigs) {
-                String fn = FileUtils.getFilenameWithoutExt(file.getName());
-                mConfigs.put(fn, cfgData);
-            }
-            return null;
-        });
-    }
-
-    public static void releaseConfigs() {
-        synchronized (mConfigs) {
-            mConfigs.clear();
-        }
-    }
-
-    public static void setConfigProp(String cfgKey, String prop, Object val) {
-        synchronized (mConfigs) {
-            if(!mConfigs.containsKey(cfgKey))
-                return;
-            QIData cfgData=mConfigs.get(cfgKey);
-            cfgData.put(prop, val);
-        }
-    }
-
-    public static Object getConfigProp(String cfgKey, String prop, Object defVal) {
-        synchronized (mConfigs) {
-            if(!mConfigs.containsKey(cfgKey))
-                return defVal;
-            QIData cfgData=mConfigs.get(cfgKey);
-            return cfgData.containsKey(prop) ?
-                    cfgData.get(prop) : defVal;
-        }
-    }
-
-    public static boolean getConfigBoolean(String cfgKey, String prop, boolean defVal) {
-        synchronized (mConfigs) {
-            if(!mConfigs.containsKey(cfgKey))
-                return defVal;
-            QIData cfgData=mConfigs.get(cfgKey);
-            Object obj = cfgData.containsKey(prop) ?
-                    cfgData.get(prop) : defVal;
-            return obj instanceof Boolean? (boolean) obj: defVal;
-        }
-    }
-
-    public static int getConfigInteger(String cfgKey, String prop, int defVal) {
-        synchronized (mConfigs) {
-            if(!mConfigs.containsKey(cfgKey))
-                return defVal;
-            QIData cfgData=mConfigs.get(cfgKey);
-            Object obj = cfgData.containsKey(prop) ?
-                    cfgData.get(prop) : defVal;
-            return obj instanceof Integer? (int) obj: defVal;
-        }
-    }
-
-    public static String getConfigObjSimpleFmtString(String cfgKey, String prop, String defVal) {
-        synchronized (mConfigs) {
-            if(!mConfigs.containsKey(cfgKey))
-                return null;
-            QIData cfgData=mConfigs.get(cfgKey);
-            return cfgData.getObjSimpleFmtString(prop, defVal);
-        }
-    }
-
-    public static QIData getConfig(String cfgKey) {
-        synchronized (mConfigs) {
-            return mConfigs.get(cfgKey);
-        }
-    }
-
-    public static void saveConfig(String cfgKey) {
-        synchronized (mConfigs) {
-            QIData cfg = mConfigs.get(cfgKey);
-            if(cfg!=null) {
-                cfg.saveToFile(FileUtils.contactPath(sval_milvus_cfg_path, cfgKey+".json"));
-            }
-        }
-    }
-
-    public static boolean setupInitConfigs(JMgbusClient mgClient, QIData param, String defaultClientName) {
-
-        String host = param.getString("host");
-        int port = param.getInteger("port");
-        String jam = param.getString("jam");
-
-        if(StringUtils.isNotValidStr(host))
-            host = JEVdbConfigUtil.getConfigObjSimpleFmtString(defaultClientName, "jedge.host", null);
-        if(StringUtils.isNotValidStr(host)) host = "127.0.0.1";
-        if(StringUtils.isNotValidStr(jam))
-            jam = JEVdbConfigUtil.getConfigObjSimpleFmtString(defaultClientName, "jedge.name", defaultClientName);
-        if(port<0) {
-            Object oport = JEVdbConfigUtil.getConfigProp(defaultClientName, "jedge.port", 8877);
-            if (!(oport instanceof Integer))
-                port = 8877;
-            else
-                port = (int) oport;
-        }
-        //设置默认启动接入的站点
-
-        mgClient.setDefaultHost(host, port);
-        mgClient.resetClientName(jam);
-
-        //后台运行 -p
-        return !param.getBoolean("p", false);
-    }
-}

+ 1 - 1
app/src/main/java/com/ch/jedge/utils/JedgeBotConst.java

@@ -9,7 +9,7 @@ public class JedgeBotConst {
     public static final String sval_sub_dir_field_cfg = "cols";
 
     // public static final String sval_panel_class_base_path = (new File(ConfigUtil.class.getResource("/").getFile())).getPath();
-    public static final String sval_panel_class_base_path = "./";
+    public static final String sval_panel_class_base_path = "/storage/emulated/0/Android/data/com.ch.jedge.llm.filter.glm/cache/";
     public static final String sval_server_db_cfg_filename = FileUtils.contactPath(sval_panel_class_base_path, sval_sub_dir_cfg, "db.json");
 
     public static final String sval_milvus_col_def_filename = FileUtils.contactPath(sval_panel_class_base_path, sval_sub_dir_cfg,"_col_def.json");