FIX: Failed to find single item will not terminate whole process
This commit is contained in:
@@ -52,7 +52,8 @@ GENERAL_RULES = """## General Rule
|
|||||||
|
|
||||||
### **Layering:**
|
### **Layering:**
|
||||||
* Style at least 2-3 layers
|
* Style at least 2-3 layers
|
||||||
|
* Show white t-shirt, shirt hem under pull over cardigan and hoodies; Don't show hem in layerinmg except sweaters, cardigan and hoodies (if capable)
|
||||||
|
* Style hoodie under blazer/ bomber jacker, leathe jacket/ trechcoat to create a street style casual look (if capable)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
GENERAL_RULES_DICT = {
|
GENERAL_RULES_DICT = {
|
||||||
@@ -78,6 +79,7 @@ GENERAL_RULES_DICT = {
|
|||||||
* Acceesory wear in a set of same metal colour (gold earrings with gold belt buckle)
|
* Acceesory wear in a set of same metal colour (gold earrings with gold belt buckle)
|
||||||
* Wear chokers or short necklaces with V-necks; wear long pendants with crew necks or turtlenecks.
|
* Wear chokers or short necklaces with V-necks; wear long pendants with crew necks or turtlenecks.
|
||||||
* Wear a belt in tuck-in outfits
|
* Wear a belt in tuck-in outfits
|
||||||
|
* Style silk scarf for the neck; tie it on your bag handle, around your wrist, or use it as a belt for a pop of color.
|
||||||
* No watches, No hats, No sunglasses""",
|
* No watches, No hats, No sunglasses""",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -182,33 +182,28 @@ class AsyncStylistAgent:
|
|||||||
gender=gender,
|
gender=gender,
|
||||||
n_results=1
|
n_results=1
|
||||||
)
|
)
|
||||||
except ValueError as e:
|
|
||||||
print(f"检测到无效参数错误:{e}")
|
|
||||||
results = []
|
|
||||||
|
|
||||||
if not results:
|
if not results:
|
||||||
self.post_operation(
|
print(f"No matching item found for description: {item_description}, category: {category}, subcategory: {subcategory}")
|
||||||
status="failed",
|
return None
|
||||||
message=f"数据库中未找到符合 '{category}/{subcategory}' 和描述的单品。",
|
|
||||||
callback_url=self.callback_url,
|
|
||||||
img_path="",
|
|
||||||
)
|
|
||||||
raise Exception(f"数据库中未找到符合 '{category}/{subcategory}' 和描述的单品。")
|
|
||||||
|
|
||||||
# 3. 模拟 Agent 审核(实际应用中,你需要将图片发回给 Agent进行审核)
|
# 3. 模拟 Agent 审核(实际应用中,你需要将图片发回给 Agent进行审核)
|
||||||
best_meta = results[0] # 第一个 batch 的第一个 metadata
|
best_meta = results[0] # 第一个 batch 的第一个 metadata
|
||||||
item_id = best_meta['item_id'].replace("_img", "")
|
item_id = best_meta['item_id'].replace("_img", "")
|
||||||
batch_source = best_meta['batch_source']
|
batch_source = best_meta['batch_source']
|
||||||
return {
|
return {
|
||||||
"item_id": item_id, # 从 metadata 字典中安全获取
|
"item_id": item_id, # 从 metadata 字典中安全获取
|
||||||
"category": best_meta['category'],
|
"category": best_meta['category'],
|
||||||
'description': best_meta['description'],
|
'description': best_meta['description'],
|
||||||
"subcategory": best_meta['subcategory'],
|
"subcategory": best_meta['subcategory'],
|
||||||
"brand": best_meta['brand'],
|
"brand": best_meta['brand'],
|
||||||
"gpt_description": item_description,
|
"gpt_description": item_description,
|
||||||
"gpt_subcategory": subcategory,
|
"gpt_subcategory": subcategory,
|
||||||
"image_path": os.path.join(settings.DATA_ROOT, batch_source, 'image_data', f"{item_id}.jpg")
|
"image_path": os.path.join(settings.DATA_ROOT, batch_source, 'image_data', f"{item_id}.jpg")
|
||||||
}
|
}
|
||||||
|
except Exception as e:
|
||||||
|
print((f"Internal error in _get_next_item: {str(e)}"))
|
||||||
|
return None
|
||||||
|
|
||||||
def _build_system_prompt(self, template: str, general_rule: str, request_summary: str = "", occasion: str = "", stylist_guide: str = "", current_category: str = "clothing", allowed_subcategories: list = [], max_len: int = 4) -> str:
|
def _build_system_prompt(self, template: str, general_rule: str, request_summary: str = "", occasion: str = "", stylist_guide: str = "", current_category: str = "clothing", allowed_subcategories: list = [], max_len: int = 4) -> str:
|
||||||
# 1. 材质偏好 (Occasion Material Map)
|
# 1. 材质偏好 (Occasion Material Map)
|
||||||
@@ -426,12 +421,6 @@ class AsyncStylistAgent:
|
|||||||
allowed_subcategories = self._get_allowed_subcategories(occasions[0], category)
|
allowed_subcategories = self._get_allowed_subcategories(occasions[0], category)
|
||||||
# 4a. 检查类别是否有效 (重要步骤)
|
# 4a. 检查类别是否有效 (重要步骤)
|
||||||
if subcategory not in allowed_subcategories:
|
if subcategory not in allowed_subcategories:
|
||||||
self.post_operation(
|
|
||||||
status="continue",
|
|
||||||
message=f"Invalid subcategory recommended by Agent: {subcategory} not in allowed subcategory list: {allowed_subcategories}. Ignore and continue",
|
|
||||||
callback_url=url,
|
|
||||||
img_path=merged_image_path,
|
|
||||||
)
|
|
||||||
failed_found_item_count += 1
|
failed_found_item_count += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user