feat:1.通过请求数量区分刷新(num=1)和正常推荐(num>1)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,3 +7,4 @@ data/
|
|||||||
*.toml
|
*.toml
|
||||||
.prod_env
|
.prod_env
|
||||||
google_application_credentials.json
|
google_application_credentials.json
|
||||||
|
*.bash
|
||||||
@@ -56,7 +56,6 @@ class AgentRequestModel(BaseModel):
|
|||||||
batch_sources: List[str]
|
batch_sources: List[str]
|
||||||
callback_url: str
|
callback_url: str
|
||||||
gender: str
|
gender: str
|
||||||
is_first_request: bool
|
|
||||||
|
|
||||||
|
|
||||||
class LCAgent(ls.LitAPI):
|
class LCAgent(ls.LitAPI):
|
||||||
@@ -120,8 +119,7 @@ class LCAgent(ls.LitAPI):
|
|||||||
user_id=request.user_id,
|
user_id=request.user_id,
|
||||||
gender=request.gender,
|
gender=request.gender,
|
||||||
callback_url=request.callback_url,
|
callback_url=request.callback_url,
|
||||||
outfit_ids=outfit_ids,
|
outfit_ids=outfit_ids
|
||||||
is_first_request=request.is_first_request
|
|
||||||
)
|
)
|
||||||
logger.info("--- Final Recommendation Results ---")
|
logger.info("--- Final Recommendation Results ---")
|
||||||
for i, path in enumerate(recommendation_results.get("successful_outfits", [])):
|
for i, path in enumerate(recommendation_results.get("successful_outfits", [])):
|
||||||
@@ -174,8 +172,7 @@ class LCAgent(ls.LitAPI):
|
|||||||
user_id: str = "test",
|
user_id: str = "test",
|
||||||
gender: str = "male",
|
gender: str = "male",
|
||||||
callback_url: str = None,
|
callback_url: str = None,
|
||||||
outfit_ids=None,
|
outfit_ids=None
|
||||||
is_first_request=False
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
基于用户的对话历史和需求,推荐一套搭配。
|
基于用户的对话历史和需求,推荐一套搭配。
|
||||||
@@ -190,33 +187,52 @@ class LCAgent(ls.LitAPI):
|
|||||||
task_map = {}
|
task_map = {}
|
||||||
|
|
||||||
stylist_agent_kwages = self.stylist_agent_kwages.copy()
|
stylist_agent_kwages = self.stylist_agent_kwages.copy()
|
||||||
for i in range(num_outfits):
|
if num_outfits == 1:
|
||||||
stylist_agent_kwages['outfit_id'] = outfit_ids[i]
|
# 通过请求数量判断 num == 1 单个outfit刷新
|
||||||
|
stylist_agent_kwages['outfit_id'] = outfit_ids[0]
|
||||||
stylist_agent_kwages['stylist_name'] = stylist_name
|
stylist_agent_kwages['stylist_name'] = stylist_name
|
||||||
stylist_agent_kwages['gender'] = gender
|
stylist_agent_kwages['gender'] = gender
|
||||||
agent = AsyncStylistAgent(**stylist_agent_kwages)
|
agent = AsyncStylistAgent(**stylist_agent_kwages)
|
||||||
if is_first_request:
|
task = agent.run_iterative_styling(
|
||||||
# 第一套搭配使用快速方法 一次跑出所有单品
|
request_summary=request_summary,
|
||||||
task = agent.run_quick_batch_styling(
|
occasions=occasions,
|
||||||
request_summary=request_summary,
|
start_outfit=start_outfit,
|
||||||
occasions=occasions,
|
batch_sources=batch_sources,
|
||||||
start_outfit=start_outfit,
|
user_id=user_id,
|
||||||
batch_sources=batch_sources,
|
callback_url=callback_url,
|
||||||
user_id=user_id,
|
)
|
||||||
callback_url=callback_url,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# 后续
|
|
||||||
task = agent.run_iterative_styling(
|
|
||||||
request_summary=request_summary,
|
|
||||||
occasions=occasions,
|
|
||||||
start_outfit=start_outfit,
|
|
||||||
batch_sources=batch_sources,
|
|
||||||
user_id=user_id,
|
|
||||||
callback_url=callback_url,
|
|
||||||
)
|
|
||||||
tasks.append(task)
|
tasks.append(task)
|
||||||
task_map[task] = {"outfit_id": outfit_ids[i], "retries": 0}
|
task_map[task] = {"outfit_id": outfit_ids[0], "retries": 0}
|
||||||
|
elif num_outfits > 1:
|
||||||
|
# 通过请求数量判断 num > 1 四套搭配推荐 (1快 , num-1慢)
|
||||||
|
for i in range(num_outfits):
|
||||||
|
stylist_agent_kwages['outfit_id'] = outfit_ids[i]
|
||||||
|
stylist_agent_kwages['stylist_name'] = stylist_name
|
||||||
|
stylist_agent_kwages['gender'] = gender
|
||||||
|
agent = AsyncStylistAgent(**stylist_agent_kwages)
|
||||||
|
if i == 0:
|
||||||
|
# 第一套搭配使用快速方法 一次跑出所有单品
|
||||||
|
logger.info(f"fast request outfit_id is : {outfit_ids[i]}")
|
||||||
|
task = agent.run_quick_batch_styling(
|
||||||
|
request_summary=request_summary,
|
||||||
|
occasions=occasions,
|
||||||
|
start_outfit=start_outfit,
|
||||||
|
batch_sources=batch_sources,
|
||||||
|
user_id=user_id,
|
||||||
|
callback_url=callback_url,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# 后续
|
||||||
|
task = agent.run_iterative_styling(
|
||||||
|
request_summary=request_summary,
|
||||||
|
occasions=occasions,
|
||||||
|
start_outfit=start_outfit,
|
||||||
|
batch_sources=batch_sources,
|
||||||
|
user_id=user_id,
|
||||||
|
callback_url=callback_url,
|
||||||
|
)
|
||||||
|
tasks.append(task)
|
||||||
|
task_map[task] = {"outfit_id": outfit_ids[i], "retries": 0}
|
||||||
logger.info(f"--- Starting {num_outfits} concurrent outfit generation tasks. ---")
|
logger.info(f"--- Starting {num_outfits} concurrent outfit generation tasks. ---")
|
||||||
|
|
||||||
# 2. 任务执行与重试循环
|
# 2. 任务执行与重试循环
|
||||||
|
|||||||
Reference in New Issue
Block a user