feat:1.推荐接口入参、回调结果中增加request_summary、occasions字段
2.推荐outfit数量修改为1(快推荐模式)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,4 +8,5 @@ data/
|
|||||||
.prod_env
|
.prod_env
|
||||||
google_application_credentials.json
|
google_application_credentials.json
|
||||||
*.bash
|
*.bash
|
||||||
|
test
|
||||||
app/google_application_credentials.json
|
app/google_application_credentials.json
|
||||||
@@ -2,7 +2,7 @@ import asyncio
|
|||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import List
|
from typing import List, Optional
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -56,6 +56,8 @@ class AgentRequestModel(BaseModel):
|
|||||||
batch_sources: List[str]
|
batch_sources: List[str]
|
||||||
callback_url: str
|
callback_url: str
|
||||||
gender: str
|
gender: str
|
||||||
|
occasions: Optional[list] = None
|
||||||
|
request_summary: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class LCAgent(ls.LitAPI):
|
class LCAgent(ls.LitAPI):
|
||||||
@@ -105,6 +107,10 @@ class LCAgent(ls.LitAPI):
|
|||||||
|
|
||||||
async def background_run(self, request: AgentRequestModel, outfit_ids):
|
async def background_run(self, request: AgentRequestModel, outfit_ids):
|
||||||
# 1. 根据用户ID查询对话历史,总结对话内容
|
# 1. 根据用户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)
|
request_summary, occasions = await self.get_conversation_summary(request.session_id)
|
||||||
logger.info(f"request_summary: {request_summary}")
|
logger.info(f"request_summary: {request_summary}")
|
||||||
|
|
||||||
@@ -188,12 +194,13 @@ class LCAgent(ls.LitAPI):
|
|||||||
|
|
||||||
stylist_agent_kwages = self.stylist_agent_kwages.copy()
|
stylist_agent_kwages = self.stylist_agent_kwages.copy()
|
||||||
if num_outfits == 1:
|
if num_outfits == 1:
|
||||||
|
logger.info(f"fast request outfit_id is : {outfit_ids[0]}")
|
||||||
# 通过请求数量判断 num == 1 单个outfit刷新
|
# 通过请求数量判断 num == 1 单个outfit刷新
|
||||||
stylist_agent_kwages['outfit_id'] = outfit_ids[0]
|
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)
|
||||||
task = agent.run_iterative_styling(
|
task = agent.run_quick_batch_styling(
|
||||||
request_summary=request_summary,
|
request_summary=request_summary,
|
||||||
occasions=occasions,
|
occasions=occasions,
|
||||||
start_outfit=start_outfit,
|
start_outfit=start_outfit,
|
||||||
|
|||||||
@@ -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."
|
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
|
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:
|
if settings.LOCAL == 0:
|
||||||
# 生产回调请求数据处理
|
# 生产回调请求数据处理
|
||||||
@@ -257,7 +257,9 @@ class AsyncStylistAgent:
|
|||||||
'status': status,
|
'status': status,
|
||||||
# 'message': message,
|
# 'message': message,
|
||||||
'path': img_path,
|
'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)
|
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}")
|
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)
|
final_image_path, _ = await self._merge_images(self.outfit_id, user_id, self.stylist_name)
|
||||||
|
# 推荐完成返回
|
||||||
response_data = self.post_operation(
|
response_data = self.post_operation(
|
||||||
status="stop",
|
status="stop",
|
||||||
message=reason,
|
message=reason,
|
||||||
callback_url=url,
|
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()
|
end_time = time.monotonic()
|
||||||
total_duration = end_time - start_time
|
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
|
return response_data, total_duration
|
||||||
|
|
||||||
@@ -509,14 +513,15 @@ class AsyncStylistAgent:
|
|||||||
status="stop",
|
status="stop",
|
||||||
message=reason,
|
message=reason,
|
||||||
callback_url=url,
|
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()
|
end_time = time.monotonic()
|
||||||
total_duration = end_time - start_time
|
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
|
return response_data, total_duration
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user