yangzeyu 10 ヶ月 前
コミット
5902a46634
4 ファイル変更103 行追加6 行削除
  1. 12 4
      agent/agent.py
  2. 2 2
      agent/config.py
  3. 53 0
      api.py
  4. 36 0
      api_test.py

+ 12 - 4
agent/agent.py

@@ -18,8 +18,8 @@ class Agent:
         self.glm.set_modelname("glm-4-plus")
         prompt = Prompt.EXTRACT_INFO_FROM_TITLE + f"""
             请根据上述逻辑,分析以下商品标题,并输出结果:
-            商品标题:{brandname}
-            给定的引流品牌:{title}"""
+            商品标题:{title}
+            给定的引流品牌:{brandname}"""
             
         response = self.glm.text_response(prompt)
         return response.content
@@ -41,14 +41,22 @@ class Agent:
         - 如果找到匹配项则输出:
         ```json
         {{
-            "in_list": true,"产品名称": 匹配到的产品名称
+            "in_list": true
         }}
         ```
             
-        - 如果没找到匹配项输出:
+        - 如果没找到匹配项,但是判断为相似产品输出:
         ```json
         {{
             "in_list": false,
+            "is_similarity": true
+        }}
+        ```
+        - 如果既不是授权生产的商品,也不是相似产品则输出:
+        ```json
+        {{
+            "in_list": false,
+            "is_similarity": false
         }}
         ```
         """

+ 2 - 2
agent/config.py

@@ -35,7 +35,7 @@ class Prompt:
     
     # 判断是否为授权商品
     LICENSE_LIST_FILTER = f"""
-        你是一个产品过滤助手,你的任务是根据输入的商品名称和提供的商品清单,判断输入的商品名称是否为清单中的产品。如果是,输出True并返回匹配的产品信息;如果不是,输出False。
+        你是一个产品过滤助手,你的任务是根据输入的商品名称和提供的商品清单,判断输入的商品名称是否为清单中的产品。
         判断思路:
         遍历商品清单中的每一个产品。
         检查输入的商品名称是否与商品清单中某个产品的产品名称在语义上匹配,而不仅仅是完全相同的字符串匹配。
@@ -43,7 +43,7 @@ class Prompt:
         匹配规则包括:
         1. 关键词匹配:输入的商品名称和产品名称中包含相同的关键词(如“运动卫衣”、“套头衫”等)。
         2. 语义相似性:输入的商品名称和产品名称描述的是同一类产品,即使表达方式不同(如“男子运动卫衣”和“男士休闲运动上衣”)。
-        3. 如果找到匹配项,输出True并返回匹配的产品信息;否则输出False
+        3. 如果判定为不在产品生产清单中,那么就判断一下是否与清单中的某个商品是相似商品
         
     """
     

+ 53 - 0
api.py

@@ -0,0 +1,53 @@
+from fastapi import FastAPI, Request, status, BackgroundTasks, HTTPException
+import json
+from pydantic import BaseModel
+from utils import Service
+import uvicorn
+
+app = FastAPI()
+
+# 定义请求体
+class KeyWordRequest(BaseModel):
+    brand_name: str                             # 判定品牌名称
+    shop_detail_info_brand_name: str            # 商品详情页的品牌名称
+    title: str                                  # 商品名称
+    
+class LicenseRequest(BaseModel):
+    brand_name: str                             # 判定品牌名称
+    title: str                                  # 商品名称
+    
+class LogoRequest(BaseModel):
+    brand_name: str                             # 判定品牌名称
+    image_url: str                              # 图片链接 
+    
+@app.post("/brandanalysis/api/v1/keyword")
+async def brand_key_word_judgement(request: KeyWordRequest):
+    """关键词引流判定api"""
+    if request.shop_detail_info_brand_name not in request.title:
+        title = request.shop_detail_info_brand_name + request.title
+    else:
+        title = request.title
+        
+    judgement_res = Service.agent.brand_key_word_judgement(request.brand_name, title)
+    
+    result = json.loads(judgement_res)
+    return {"code": 200, "message": "success", "data": {"judgement_info": result}}
+
+@app.post("/brandanalysis/api/v1/license")
+async def license_judgement(request: LicenseRequest):
+    license_list = Service.get_license_list(request.brand_name)
+    license_judgement = json.loads(Service.agent.license_product_judgement(request.title, license_list))
+    return {"code": 200, "message": "success", "data": {"judgement_info": license_judgement}}
+
+@app.post("/brandanalysis/api/v1/logo")
+async def logo_judgement(request: LogoRequest):
+    logo_path_map = {
+        "李宁": "./logo/lining.jpg"
+    }
+    logo_path = logo_path_map[request.brand_name]
+    logo_judgement_res = json.loads(Service.agent.image_logo_judgement(logo_path, request.image_url))
+    
+    return {"code": 200, "message": "success", "data": {"judgement_info": logo_judgement_res}}
+
+if __name__ == "__main__":
+    uvicorn.run(app, host="0.0.0.0", port=7860)

+ 36 - 0
api_test.py

@@ -0,0 +1,36 @@
+import requests
+import json
+
+# url = "http://172.18.1.189:7860/brandanalysis/api/v1/keyword"
+# payload = {
+#     "brand_name": "李宁",
+#     "shop_detail_info_brand_name": "李宇",
+#     "title": "休闲运动短袖T恤速干男子跑步健身圆领半袖上衣",
+# }
+# headers = {'Content-Type': 'application/json'}
+
+# response = requests.post(url, data=json.dumps(payload), headers=headers)
+# print(response.json())
+
+
+
+# url = "http://172.18.1.189:7860/brandanalysis/api/v1/license"
+# payload = {
+#     "brand_name": "李宁",
+#     "title": "李宁烈骏7 PRO V2男子䨻丝高回弹缓震稳定跑鞋",
+# }
+# headers = {'Content-Type': 'application/json'}
+
+# response = requests.post(url, data=json.dumps(payload), headers=headers)
+# print(response.json())
+
+
+url = "http://172.18.1.189:7860/brandanalysis/api/v1/logo"
+payload = {
+    "brand_name": "李宁",
+    "image_url": "http://h2.appsimg.com/a.appsimg.com/upload/merchandise/pdcvis/2024/12/13/131/82a925f9-14af-4be3-bf78-3262f7909482.jpg",
+}
+headers = {'Content-Type': 'application/json'}
+
+response = requests.post(url, data=json.dumps(payload), headers=headers)
+print(response.json())