root 2 viikkoa sitten
vanhempi
commit
b558c2a841
2 muutettua tiedostoa jossa 57 lisäystä ja 43 poistoa
  1. 7 0
      ai-slibra-assistant/data/robot.json
  2. 50 43
      ai-slibra-assistant/util/request_utils.py

+ 7 - 0
ai-slibra-assistant/data/robot.json

@@ -935,6 +935,13 @@
                     ],
                     "next": "2.10",
                     "title": "NO"
+                },
+                {
+                    "commonReply": [
+                        "others"
+                    ],
+                    "next": "100.01",
+                    "title": "others"
                 }
             ],
             "tools": "water_info",

+ 50 - 43
ai-slibra-assistant/util/request_utils.py

@@ -173,27 +173,13 @@ def business_service(session_id, uid, code, tools,  asr):
         else:
             mess = ''
         return mess
-    pattern = r'DTMF(.*?)DTMF'
-    matches = re.findall(pattern, asr, re.DOTALL)
-    if matches:
-        asr = re.sub("[()]", "", matches[-1])
-    else:
-        asr = asr.split("###")[-1]
-    asr = asr.strip(r""""$%&'()*+,,-./:;<=>?@[\]^_`{|}~。??!""")
-    if tools in ["water_loc_info", "fee_user_info", "user_phone_info", "meter_owner_neighbour"] and len(asr)==0:
-        return [{"title": "NO", "isFaq": False, "faqContent": '', "asr": asr, "businessContent": ''}]
-    # parse water_loc_info
-    if tools in ["water_loc_info", "meter_owner_neighbour", "water_info", "meter_owner_phone"]:
-        asr2 = norm_community(asr)
-        logger.info(f"tools:{tools}, session:{session_id}, asr:{asr}, norm_asr:{asr2}")
-        asr = asr2
-    if tools in ["water_info", "meter_owner_phone"]:
-        newtools = "water_loc_info" if tools == "water_info" else "meter_owner_neighbour"
+
+    def buildtools(code, uid, session_id, asr, tools):
         param = json.dumps(dict(nodeId=code,
                                 userId=uid,
                                 sessionId=session_id,
                                 asrText=asr,
-                                method=newtools
+                                method=tools
                                 ), ensure_ascii=False)
         try:
             # 192.168.40.21
@@ -202,7 +188,7 @@ def business_service(session_id, uid, code, tools,  asr):
                                 headers={'Content-Type': 'application/json;charset=utf-8'},
                                 timeout=30)
             resp = json.loads(res.text)
-            logger.info(f"bussiness:{resp}, tools:{tools}, session:{session_id}, asr:{asr}")
+            logger.info(f"bussiness:{resp}, tools:{tools}, session:{session_id},asr:{asr}")
             if resp['code'] == "0":
                 content = resp['data'].get("contents")
                 title = "NO" if content is None or len(content) == 0 else "YES"
@@ -211,34 +197,55 @@ def business_service(session_id, uid, code, tools,  asr):
                     {"title": title, "isFaq": False, "faqContent": '', "asr": asr, "businessContent": businessContent}]
                 logger.info(f"session:{session_id},code:{code},uid:{uid}, tools:{tools},asr:{asr}, opt:{opt}")
                 return opt
+            else:
+                return [{"title": "NO", "isFaq": False, "faqContent": '', "asr": asr, "businessContent": ''}]
         except Exception as e:
             logger.info(f"bussion service服务异常:session:{session_id}, tools:{tools},uid:{uid}:{e}")
-    param = json.dumps(dict(nodeId=code,
-                            userId=uid,
-                            sessionId=session_id,
-                            asrText=asr,
-                            method=tools
-                            ), ensure_ascii=False)
-    try:
-        # 192.168.40.21
-        res = requests.post(f"http://{SERVE_HOST}:8001/bigModel/queryBusinessInfo",
-                            param.encode("UTF-8"),
-                            headers={'Content-Type': 'application/json;charset=utf-8'},
-                            timeout=30)
-        resp = json.loads(res.text)
-        logger.info(f"bussiness:{resp}, tools:{tools}, session:{session_id},asr:{asr}")
-        if resp['code'] == "0":
-            content = resp['data'].get("contents")
-            title = "NO" if content is None or len(content)==0  else "YES"
-            businessContent = getContent(content, tools) if title == "YES" else ''
-            opt = [{"title": title, "isFaq": False, "faqContent": '', "asr": asr, "businessContent": businessContent}]
-            logger.info(f"session:{session_id},code:{code},uid:{uid}, tools:{tools},asr:{asr}, opt:{opt}")
-            return opt
-        else:
             return [{"title": "NO", "isFaq": False, "faqContent": '', "asr": asr, "businessContent": ''}]
-    except Exception as e:
-        logger.info(f"bussion service服务异常:session:{session_id}, tools:{tools},uid:{ uid}:{e}")
-        return [{"title": "NO", "isFaq": False, "faqContent": '', "asr": asr, "businessContent":''}]
+
+    pattern = r'DTMF(.*?)DTMF'
+    matches = re.findall(pattern, asr, re.DOTALL)
+    if matches:
+        asr = re.sub("[()]", "", matches[-1])
+    else:
+        asr = asr.split("###")[-1]
+    asr = asr.strip(r""""$%&'()*+,,-./:;<=>?@[\]^_`{|}~。??!""")
+    if tools in ["water_loc_info", "fee_user_info", "user_phone_info", "meter_owner_neighbour"] and len(asr)==0:
+        return [{"title": "NO", "isFaq": False, "faqContent": '', "asr": asr, "businessContent": ''}]
+    # parse water_loc_info
+    if tools in ["water_loc_info", "meter_owner_neighbour", "water_info", "meter_owner_phone"]:
+        asr2 = norm_community(asr)
+        logger.info(f"tools:{tools}, session:{session_id}, asr:{asr}, norm_asr:{asr2}")
+        asr = asr2
+    if tools in ["water_info", "meter_owner_phone"]:
+        if tools == "water_info":
+            newtools = "water_all"
+            param = json.dumps(dict(nodeId=code,
+                                    userId=uid,
+                                    sessionId=session_id,
+                                    asrText=asr,
+                                    method=newtools
+                                    ), ensure_ascii=False)
+            try:
+                res = requests.post(f"http://{SERVE_HOST}:8001/bigModel/queryBusinessInfo",
+                                    param.encode("UTF-8"),
+                                    headers={'Content-Type': 'application/json;charset=utf-8'},
+                                    timeout=30)
+                resp = json.loads(res.text)
+                logger.info(f"bussiness:{resp}, tools:{newtools}, session:{session_id}, asr:{asr}")
+                if resp['code'] == "0":
+                    content = resp['data'].get("contents")
+                    if content is None or len(content) == 0:
+                        opt = [
+                            {"title": "others", "isFaq": False, "faqContent": '', "asr": asr,
+                             "businessContent": "当前没有停水公告信息"}]
+                        logger.info(f"session:{session_id},code:{code},uid:{uid}, tools:{tools},asr:{asr}, opt:{opt}")
+                        return opt
+            except Exception as e:
+                logger.info(f"business service服务异常:session:{session_id}, tools:{newtools},uid:{uid}:{e}")
+        newtools = "water_loc_info" if tools == "water_info" else "meter_owner_neighbour"
+        buildtools(code, code, uid, session_id, asr, newtools)
+    buildtools(code,code, uid, session_id, asr, tools)
 
 
 @timetic