丁云鹏 před 1 týdnem
rodič
revize
eba23af7ef
2 změnil soubory, kde provedl 71 přidání a 2 odebrání
  1. 57 0
      utils/aliyun_security.py
  2. 14 2
      workers/video_insight_consumption_work.py

+ 57 - 0
utils/aliyun_security.py

@@ -0,0 +1,57 @@
+# coding=utf-8
+# python version >= 3.6
+from alibabacloud_green20220302.client import Client
+from alibabacloud_green20220302 import models
+from alibabacloud_tea_openapi.models import Config
+import json
+from loguru import logger
+
+config = Config(
+    # 阿里云账号AccessKey拥有所有API的访问权限,建议您使用RAM用户进行API访问或日常运维。
+    # 强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全。
+    # 常见获取环境变量方式:
+    # contentsecurity@1894469520484605.onaliyun.com
+    access_key_id='LTAI5tEv9SCKZFpTshJpi618',
+    access_key_secret='7N13xskcYEJzgiRLcYO1ngEVFmTq6Z',
+    # 连接超时时间 单位毫秒(ms)
+    connect_timeout=10000,
+    # 读超时时间 单位毫秒(ms)
+    read_timeout=3000,
+    region_id='cn-hangzhou',
+    #endpoint='green-cip-vpc.cn-hangzhou.aliyuncs.com'
+    endpoint='green-cip.cn-hangzhou.aliyuncs.com'
+)
+
+clt = Client(config)
+
+class Security:
+    @classmethod
+    def security(cls, content):
+        serviceParameters = {
+            'content': content
+        }
+        textModerationPlusRequest = models.TextModerationPlusRequest(
+            # 检测类型
+            service='llm_response_moderation_01',
+            service_parameters=json.dumps(serviceParameters)
+        )
+
+        try:
+            response = clt.text_moderation_plus(textModerationPlusRequest)
+            if response.status_code == 200:
+                # 调用成功
+                result = response.body
+                logger.info('response success. result:{}'.format(result))
+                if(result.code == 200){
+                    if(result.Data.RiskLevel == "high" 
+                        || result.Data.RiskLevel == "medium" ) {
+                        return false,result
+                    }
+                }
+                return true,result 
+            else:
+                print('response not success. status:{} ,result:{}'.format(response.status_code, response))
+        except Exception as err:
+            print(err)
+if __name__ == '__main__':
+    Security.security("测试安全边界")

+ 14 - 2
workers/video_insight_consumption_work.py

@@ -15,6 +15,7 @@ from utils.google_ai_studio import GoogleAI
 from utils.piaoquan import PQ
 from utils.piaoquan import PQ
 from utils.redis import RedisHelper, content_video_data
 from utils.redis import RedisHelper, content_video_data
 from utils.mysql_db import MysqlHelper
 from utils.mysql_db import MysqlHelper
+from utils.aliyun_security import Security
 
 
 
 
 
 
@@ -66,18 +67,29 @@ class ConsumptionRecommend(object):
             video_id, video_link, video_title, content_type,
             video_id, video_link, video_title, content_type,
             demand_order, demand_score, user_demand, demand_category,
             demand_order, demand_score, user_demand, demand_category,
             demand_reason, product_hook, hook_time, hook_desc,
             demand_reason, product_hook, hook_time, hook_desc,
-            hook_type, landing_desc, landing_type, platform_case, reasoning_process
+            hook_type, landing_desc, landing_type, platform_case, reasoning_process,audit_status,audit_desc
         ) VALUES
         ) VALUES
         """
         """
         # Add values for each entry
         # Add values for each entry
         values = []
         values = []
         link = f"""https://admin.piaoquantv.com/cms/post-detail/{video_id}/detail"""
         link = f"""https://admin.piaoquantv.com/cms/post-detail/{video_id}/detail"""
         for entry in data:
         for entry in data:
+
+            hook_desc = '{entry.get('需求钩子话术', '')}'
+            result,msg = security(hook_desc)
+            audit_status = 0
+            if(result) {
+                audit_status = 1
+            } else {
+                audit_status = 2
+            }
+            audit_desc = msg
+
             value = f"""(
             value = f"""(
                 {video_id}, '{link}', '{video_title}', NULL,
                 {video_id}, '{link}', '{video_title}', NULL,
                 '{entry.get('需求排序序号', '')}', '{entry.get('需求强烈程度分值', '')}', '{entry.get('用户具体的需求描述', '')}', '{entry.get('需求分类', '')}',
                 '{entry.get('需求排序序号', '')}', '{entry.get('需求强烈程度分值', '')}', '{entry.get('用户具体的需求描述', '')}', '{entry.get('需求分类', '')}',
                 '{entry.get('推测出该点需求的原因', '')}', '{entry.get('需求详细query', '')}', '', '{entry.get('需求钩子话术', '')}',
                 '{entry.get('推测出该点需求的原因', '')}', '{entry.get('需求详细query', '')}', '', '{entry.get('需求钩子话术', '')}',
-                '', '{entry.get('落地方案形态描述', '')}', '{entry.get('落地方案类型', '')}', '', ''
+                '', '{entry.get('落地方案形态描述', '')}', '{entry.get('落地方案类型', '')}', '', '',{audit_status},{audit_desc}
             )"""
             )"""
             values.append(value)
             values.append(value)
         # Combine SQL statement and values
         # Combine SQL statement and values