From 38af75077d3dc9062a50efc64396015d41035714 Mon Sep 17 00:00:00 2001 From: zhh Date: Fri, 21 Nov 2025 11:19:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E5=8F=96=E6=B6=88agent?= =?UTF-8?q?=E9=85=8D=E9=A5=B0=EF=BC=88=E4=BF=9D=E7=95=99=E9=9E=8B=E5=AD=90?= =?UTF-8?q?=EF=BC=89=E6=8E=A8=E8=8D=90=EF=BC=8C=E6=94=B9=E4=B8=BA=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E9=9A=8F=E6=9C=BA=E9=85=8D=E9=A5=B0=E6=90=AD=E9=85=8D?= =?UTF-8?q?=20=E4=BD=BF=E7=94=A8json=E6=96=87=E4=BB=B6=E8=A1=A5=E5=85=85st?= =?UTF-8?q?ylist=E5=88=A0=E9=99=A4=E6=8E=89=E7=9A=84=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E9=85=8D=E9=A5=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ChatbotAgent/core/stylist_agent_server.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/server/ChatbotAgent/core/stylist_agent_server.py b/app/server/ChatbotAgent/core/stylist_agent_server.py index 64d2202..38a6f4e 100644 --- a/app/server/ChatbotAgent/core/stylist_agent_server.py +++ b/app/server/ChatbotAgent/core/stylist_agent_server.py @@ -293,7 +293,7 @@ class AsyncStylistAgent: print(f"An error occurred during item retrieval: {e}") return None - async def _get_random_accessories(self, stylist): + async def _get_random_accessories(self, stylist, item_count): stylist_item = [] stylist_item_ids = [] for i in stylist: @@ -303,12 +303,16 @@ class AsyncStylistAgent: stylist_item += random.choices(stylist_results['metadatas'][0], k=i['count']) stylist_item_ids += [item_id['item_id'] for item_id in stylist_item] - accessories_count = 2 + accessories_count = 9 - item_count - len(stylist_item) - # 2. 在配饰池中过滤掉已经选中的item ,然后抽两个item - random_single_ids = random.choices(list(set(self.local_db.cache_filtered_ids) - set([f"{i}_img" for i in stylist_item_ids])), k=accessories_count) - random_items = self.local_db.random_get_accessories(random_single_ids)['metadatas'] - all_items = stylist_item + random_items + if accessories_count > 0: + accessories_count = random.randint(1, accessories_count) + # 2. 在配饰池中过滤掉已经选中的item ,然后抽两个item + random_single_ids = random.choices(list(set(self.local_db.cache_filtered_ids) - set([f"{i}_img" for i in stylist_item_ids])), k=accessories_count) + random_items = self.local_db.random_get_accessories(random_single_ids)['metadatas'] + all_items = stylist_item + random_items + else: + all_items = stylist_item items_data = [] @@ -393,7 +397,7 @@ class AsyncStylistAgent: logger.info(f"request data :{response_data} | JAVA callback info -> status:{response.status_code} | message:{response.text}") # 根据stylist要求随机增加配饰 3-4个配饰 - new_item = await self._get_random_accessories(self.style_accessories_guide) + new_item = await self._get_random_accessories(self.style_accessories_guide, len(self.outfit_items)) for item in new_item: self.outfit_items.append(item) response_data['items'].append({"item_id": item.get('item_id'), "category": item.get('category')}) @@ -476,7 +480,7 @@ class AsyncStylistAgent: logger.info(f"request data :{response_data} | JAVA callback info -> status:{response.status_code} | message:{response.text}") # 根据stylist要求随机增加配饰 3-4个配饰 - new_item = await self._get_random_accessories(self.style_accessories_guide) + new_item = await self._get_random_accessories(self.style_accessories_guide, len(self.outfit_items)) for item in new_item: self.outfit_items.append(item) response_data['items'].append({"item_id": item.get('item_id'), "category": item.get('category')})