from agent import Glm, KeyWordPrompt class Agent: _instance = None def __new__(cls): if not cls._instance: cls._instance = super(Agent, cls).__new__(cls) cls._instance._initialized = False return cls._instance def __init__(self): if not self._initialized: self.glm = Glm() self._initialized = True def brand_key_word_judgement(self, brandname, title): """判断是否为关键词引流""" self.glm.set_modelname("glm-4-plus") prompt = KeyWordPrompt.EXTRACT_INFO_FROM_TITLE + f""" 请根据上述逻辑,分析以下商品标题,并输出结果: 商品标题:{brandname} 给定的引流品牌:{title}""" response = self.glm.text_response(prompt) return response.content def license_product_judgement(self, title, license_list): """判断是否为未授权商品""" license_list_str = "" for product in license_list: license_list_str += f"{product}\n" self.glm.set_modelname("glm-4-plus") prompt = KeyWordPrompt.LICENSE_LIST_FILTER + f""" 请根据上述逻辑,分析以下商品是否为授权生产的,并输出结果: 商品标题: {title} 已生产的产品清单: {license_list_str} 输出结果: - 如果找到匹配项则输出: ```json {{ "in_list": true,"产品名称": 匹配到的产品名称 }} ``` - 如果没找到匹配项则输出: ```json {{ "in_list": false, }} ``` """ response = self.glm.text_response(prompt) response = response.content.replace(' ', '').replace('\n', '').replace('\t', '').replace(":", ": ") return response def image_logo_judgement(self, logo_path, image_url): """判断图像中是否有指定品牌的logo""" self.glm.set_modelname("glm-4v-plus-0111") prompt = KeyWordPrompt.IMAGE_LOGO_JUDGEMENT response = self.glm.multi_epoch_image_response(logo_path, image_url, prompt) response = response.content return response if __name__ == "__main__": agent = Agent() agent.brand_key_word_judgement("【防泼水】荷叶风衣连帽加绒外套防风外套保暖户外运动服女外套", "李宁")