feat:1.推荐接口入参、回调结果中增加request_summary、occasions字段

2.推荐outfit数量修改为1(快推荐模式)
This commit is contained in:
zcr
2025-12-19 16:06:36 +08:00
parent 3910c07c40
commit 2db36e2c1d
4 changed files with 2164 additions and 17 deletions

1
.gitignore vendored
View File

@@ -8,4 +8,5 @@ data/
.prod_env
google_application_credentials.json
*.bash
test
app/google_application_credentials.json

View File

@@ -2,7 +2,7 @@ import asyncio
import logging
import uuid
from enum import Enum
from typing import List
from typing import List, Optional
from pydantic import Field
import time
@@ -56,6 +56,8 @@ class AgentRequestModel(BaseModel):
batch_sources: List[str]
callback_url: str
gender: str
occasions: Optional[list] = None
request_summary: Optional[str] = None
class LCAgent(ls.LitAPI):
@@ -105,7 +107,11 @@ class LCAgent(ls.LitAPI):
async def background_run(self, request: AgentRequestModel, outfit_ids):
# 1. 根据用户ID查询对话历史总结对话内容
request_summary, occasions = await self.get_conversation_summary(request.session_id)
if request.request_summary and request.occasions:
request_summary = request.request_summary
occasions = request.occasions
else:
request_summary, occasions = await self.get_conversation_summary(request.session_id)
logger.info(f"request_summary: {request_summary}")
# 2.根据对话总结推荐搭配
@@ -188,12 +194,13 @@ class LCAgent(ls.LitAPI):
stylist_agent_kwages = self.stylist_agent_kwages.copy()
if num_outfits == 1:
logger.info(f"fast request outfit_id is : {outfit_ids[0]}")
# 通过请求数量判断 num == 1 单个outfit刷新
stylist_agent_kwages['outfit_id'] = outfit_ids[0]
stylist_agent_kwages['stylist_name'] = stylist_name
stylist_agent_kwages['gender'] = gender
agent = AsyncStylistAgent(**stylist_agent_kwages)
task = agent.run_iterative_styling(
task = agent.run_quick_batch_styling(
request_summary=request_summary,
occasions=occasions,
start_outfit=start_outfit,
@@ -324,7 +331,7 @@ if __name__ == "__main__":
request_file_path = "./data/2025_q4/request_test.json"
else:
request_file_path = "/mnt/data/workspace/Code/lc_stylist_agent/data/2025_q4/request_test.json"
with open(request_file_path, "r") as f:
request_data = json.load(f)
@@ -338,7 +345,7 @@ if __name__ == "__main__":
stylist_agent_kwages['gender'] = "female"
agent = AsyncStylistAgent(**stylist_agent_kwages)
coro = agent.run_iterative_styling(
# coro = agent.run_quick_batch_styling(
# coro = agent.run_quick_batch_styling(
request_summary=request_summary,
occasions=occasions,
start_outfit=[],

View File

@@ -240,7 +240,7 @@ class AsyncStylistAgent:
context += "\nRecommend a **complete, full outfit**, including all items (clothing, shoes, bags, and accessories), strictly following the Request Summary and Style Guide. Output the **complete list** of items in a single JSON response."
return context
def post_operation(self, status: str, message: str, callback_url: str, img_path: str):
def post_operation(self, status: str, message: str, callback_url: str, img_path: str, request_summary=None, occasions=None):
"""处理完成后的回调操作。"""
if settings.LOCAL == 0:
# 生产回调请求数据处理
@@ -257,7 +257,9 @@ class AsyncStylistAgent:
'status': status,
# 'message': message,
'path': img_path,
'outfit_id': self.outfit_id
'outfit_id': self.outfit_id,
"request_summary": request_summary,
"occasions": occasions
}
response = post_request(url=callback_url, data=json.dumps(response_data), headers=self.headers)
logger.info(f"request data {json.dumps(response_data, ensure_ascii=False, indent=2)} | JAVA callback info -> status:{response.status_code} | message:{response.text}")
@@ -465,18 +467,20 @@ class AsyncStylistAgent:
)
final_image_path, _ = await self._merge_images(self.outfit_id, user_id, self.stylist_name)
# 推荐完成返回
response_data = self.post_operation(
status="stop",
message=reason,
callback_url=url,
img_path=final_image_path
img_path=final_image_path,
request_summary=request_summary,
occasions=occasions
)
if settings.LOCAL == 1:
with open(os.path.join(settings.OUTFIT_OUTPUT_DIR, self.stylist_name, f'{self.outfit_id}.json'), 'w') as f:
json.dump({"request_summary": request_summary, "occasions": occasions, "items": self.outfit_items}, f, indent=2)
end_time = time.monotonic()
total_duration = end_time - start_time
if settings.LOCAL == 1:
with open(os.path.join(settings.OUTFIT_OUTPUT_DIR, self.stylist_name, f'{self.outfit_id}.json'), 'w') as f:
json.dump({"request_summary": request_summary, "occasions": occasions, "items": self.outfit_items, "total_duration": total_duration}, f, indent=2)
return response_data, total_duration
@@ -509,14 +513,15 @@ class AsyncStylistAgent:
status="stop",
message=reason,
callback_url=url,
img_path=final_image_path
img_path=final_image_path,
request_summary=request_summary,
occasions=occasions
)
if settings.LOCAL == 1:
with open(os.path.join(settings.OUTFIT_OUTPUT_DIR, self.stylist_name, f'{self.outfit_id}.json'), 'w') as f:
json.dump({"request_summary": request_summary, "occasions": occasions, "items": self.outfit_items}, f, indent=2)
end_time = time.monotonic()
total_duration = end_time - start_time
if settings.LOCAL == 1:
with open(os.path.join(settings.OUTFIT_OUTPUT_DIR, self.stylist_name, f'{self.outfit_id}.json'), 'w') as f:
json.dump({"request_summary": request_summary, "occasions": occasions, "items": self.outfit_items, "total_duration": total_duration}, f, indent=2)
return response_data, total_duration

2134
uv.lock generated Normal file

File diff suppressed because it is too large Load Diff