luojunhui 4 miesięcy temu
rodzic
commit
ed82268fe6
1 zmienionych plików z 20 dodań i 16 usunięć
  1. 20 16
      applications/api/nlp_api.py

+ 20 - 16
applications/api/nlp_api.py

@@ -2,9 +2,11 @@
 @author: luojunhui
 """
 import requests
+import traceback
 from requests.exceptions import RequestException, JSONDecodeError
 
 from applications.feishuBotApi import bot
+from applications.aliyunLogApi import log
 
 
 def similarity_between_title_list(target_title_list: list[str], base_title_list: list[str]) -> list[list[float]]:
@@ -31,20 +33,21 @@ def similarity_between_title_list(target_title_list: list[str], base_title_list:
         if response.status_code != 200:
             response = requests.post(url_backup, json=body, timeout=120)
     except RequestException as e:
-        bot(
-            title='NLP API 网络异常',
-            detail={
-                "error_type": type(e).__name__,
-                "error_msg": str(e)
-            },
-            mention=False
+        log(
+            task="article_exit_with_title",
+            function="similarity_between_title_list",
+            status="fail",
+            data={
+                "e": str(e),
+                "error_msg": traceback.format_exc()
+            }
         )
         # use back up
         response = requests.post(url_backup, json=body, timeout=120)
 
     if response.status_code != 200:
         bot(
-            title='NLP API 业务异常',
+            title='NLP API 接口异常',
             detail={
                 "status_code": response.status_code,
                 "response_text": response.text[:200]  # 截取部分内容避免过大
@@ -57,14 +60,15 @@ def similarity_between_title_list(target_title_list: list[str], base_title_list:
         response_json = response.json()
         score_array = response_json['score_list_list']
     except (JSONDecodeError, KeyError) as e:
-        bot(
-            title='NLP响应数据异常',
-            detail={
-                "error_type": type(e).__name__,
-                "raw_response": response.text[:200]
-            },
-            mention=False
-        )
+        print("NLP响应数据异常")
+        # bot(
+        #     title='NLP响应数据异常',
+        #     detail={
+        #         "error_type": type(e).__name__,
+        #         "raw_response": response.text[:200]
+        #     },
+        #     mention=False
+        # )
         return []
 
     return score_array