Explorar o código

修复判断未授权生产的bug

Sherlock1011 hai 11 meses
pai
achega
676b470cce
Modificáronse 3 ficheiros con 41 adicións e 33 borrados
  1. 23 8
      agent/agent.py
  2. 0 14
      agent/config.py
  3. 18 11
      webui.py

+ 23 - 8
agent/agent.py

@@ -24,19 +24,34 @@ class Agent:
         response = self.glm.text_response(prompt)
         return response.content
     
-    def license_product_judgement(self, title, license_list):
+    def license_product_judgement(self, title, license_list_str):
         """判断是否为未授权商品"""
         self.glm.set_modelname("glm-4-plus")
         prompt = KeyWordPrompt.LICENSE_LIST_FILTER + f"""
-            请根据上述逻辑,分析以下商品是否为授权生产的,并输出结果:
-            商品标题: {title}
-            已生产的产品清单:
-            ```json
-            {license_list}
-            ```
+        请根据上述逻辑,分析以下商品是否为授权生产的,并输出结果:
+        商品标题: {title}
+        已生产的产品清单:
+        {license_list_str}
+            
+        输出结果:
+        - 如果找到匹配项则输出:
+        ```json
+        {{
+            "in_list": true,"产品名称": 匹配到的产品名称
+        }}
+        ```
+            
+        - 如果没找到匹配项则输出:
+        ```json
+        {{
+            "in_list": false,
+        }}
+        ```
         """
         response = self.glm.text_response(prompt)
-        return response.content
+        response = response.content.replace(' ', '').replace('\n', '').replace('\t', '').replace(":", ": ")
+        print(response)
+        return response
 
 if __name__ == "__main__":
     agent = Agent()

+ 0 - 14
agent/config.py

@@ -36,21 +36,7 @@ class KeyWordPrompt:
         1. 关键词匹配:输入的商品名称和产品名称中包含相同的关键词(如“运动卫衣”、“套头衫”等)。
         2. 语义相似性:输入的商品名称和产品名称描述的是同一类产品,即使表达方式不同(如“男子运动卫衣”和“男士休闲运动上衣”)。
         3. 如果找到匹配项,输出True并返回匹配的产品信息;否则输出False。
-        输出结果:
-        - 如果找到匹配项
-        ```json
-        {{
-            "in_list": True,
-            "产品名称": 匹配到的产品名称
-        }}
-        ```
         
-        - 如果没找到匹配项
-        ```json
-        {{
-            "in_list": False,
-        }}
-        ```
     """
     
     

+ 18 - 11
webui.py

@@ -58,14 +58,17 @@ def get_license_list():
     records = license_dao.get_records_by_query({"BrandName":"李宁"})
     for record in records:
         if "ProductSeries" not in record.keys():
-            record["ProductSeries"] = "无"
-        license_list.append(
-            {
-                "产品名称":record["ProductTitle"],
-                "产品分类":record["Category"],
-                "产品系列":record["ProductSeries"]
-            }
-        )
+            record["ProductSeries"] = ""
+        # license_list.append(
+        #     {
+        #         "产品名称":record["ProductTitle"],
+        #         "产品分类":record["Category"],
+        #         "产品系列":record["ProductSeries"]
+        #     }
+        # )
+        product = f"{record['ProductSeries']} {record['Category']}"
+        if product not in license_list:
+            license_list.append(product)
     return license_list
     
 
@@ -80,8 +83,10 @@ def check_infringement(title, brandname):
             key_word_falg = False
         
     key_word_judgement = json.loads(agent.brand_key_word_judgement(brandname, title))
-    print(type(agent.license_product_judgement(title, license_list)))
-    license_judgement = json.loads(agent.license_product_judgement(title, license_list))
+    
+    res = agent.license_product_judgement(title, license_list_str)
+    print(res)
+    license_judgement = json.loads(res)
     key_word_falg = key_word_judgement["key_word_flag"]
     license_judgement_flag = license_judgement["in_list"]
     # license_flag = license_judgement["in_list"]
@@ -107,7 +112,9 @@ default_merchant = merchant_list_titles[0] if merchant_list_titles else None
 default_cust_info, default_image = get_cust_info(default_merchant)
 
 license_list = get_license_list()
-# print(license_list)
+license_list_str = ""
+for product in license_list:
+    license_list_str += f"{product}\n"
 with gr.Blocks() as demo:
     gr.Markdown("## 侵权识别系统", elem_id="header")