agent.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from agent import Glm, KeyWordPrompt
  2. class Agent:
  3. _instance = None
  4. def __new__(cls):
  5. if not cls._instance:
  6. cls._instance = super(Agent, cls).__new__(cls)
  7. cls._instance._initialized = False
  8. return cls._instance
  9. def __init__(self):
  10. if not self._initialized:
  11. self.glm = Glm()
  12. self._initialized = True
  13. def brand_key_word_judgement(self, brandname, title):
  14. """判断是否为关键词引流"""
  15. self.glm.set_modelname("glm-4-plus")
  16. prompt = KeyWordPrompt.EXTRACT_INFO_FROM_TITLE + f"""
  17. 请根据上述逻辑,分析以下商品标题,并输出结果:
  18. 商品标题:{brandname}
  19. 给定的引流品牌:{title}"""
  20. response = self.glm.text_response(prompt)
  21. return response.content
  22. def license_product_judgement(self, title, license_list):
  23. """判断是否为未授权商品"""
  24. self.glm.set_modelname("glm-4-plus")
  25. prompt = KeyWordPrompt.LICENSE_LIST_FILTER + f"""
  26. 请根据上述逻辑,分析以下商品是否为授权生产的,并输出结果:
  27. 商品标题: {title}
  28. 已生产的产品清单:
  29. ```json
  30. {license_list}
  31. ```
  32. """
  33. response = self.glm.text_response(prompt)
  34. return response.content
  35. if __name__ == "__main__":
  36. agent = Agent()
  37. agent.brand_key_word_judgement("【防泼水】荷叶风衣连帽加绒外套防风外套保暖户外运动服女外套", "李宁")