feat: 生图增加商品尺寸填报
This commit is contained in:
+27
-5
@@ -50,6 +50,27 @@ from services.suite_service import texts_to_raw, validate_model
|
||||
router = APIRouter(prefix="/api", tags=["suite"])
|
||||
|
||||
|
||||
def _with_dimensions(raw: dict, dimensions, *, required: bool = False) -> dict:
|
||||
"""将表单长宽高放入提示词上下文,不依赖采集参数是否已有尺寸字段。"""
|
||||
if dimensions is None:
|
||||
if required:
|
||||
raise HTTPException(status_code=400, detail="生成尺寸标注图需要完整填写商品长、宽、高")
|
||||
return raw
|
||||
values = (dimensions.length, dimensions.width, dimensions.height)
|
||||
if not all(value is not None and value > 0 for value in values):
|
||||
if required:
|
||||
raise HTTPException(status_code=400, detail="生成尺寸标注图需要完整填写商品长、宽、高")
|
||||
return raw
|
||||
enriched = dict(raw)
|
||||
enriched["dimensions"] = {
|
||||
"length": dimensions.length,
|
||||
"width": dimensions.width,
|
||||
"height": dimensions.height,
|
||||
"unit": dimensions.unit,
|
||||
}
|
||||
return enriched
|
||||
|
||||
|
||||
def _stream_file(handle: io.BufferedRandom, chunk_size: int = 64 * 1024) -> Iterator[bytes]:
|
||||
"""以固定块返回临时 ZIP,释放响应完成后的临时文件。"""
|
||||
try:
|
||||
@@ -64,7 +85,7 @@ def _stream_file(handle: io.BufferedRandom, chunk_size: int = 64 * 1024) -> Iter
|
||||
@router.post("/suite/plan", response_model=PlanResponse)
|
||||
async def plan_suite(req: SuitePlanRequest) -> PlanResponse:
|
||||
"""DeepSeek 根据商品信息生成出图方案(同步接口,数秒级)。"""
|
||||
product_info = texts_to_raw(req.texts)
|
||||
product_info = _with_dimensions(texts_to_raw(req.texts), req.dimensions)
|
||||
if not product_info.get("title"):
|
||||
raise HTTPException(status_code=400, detail="缺少商品标题,无法规划")
|
||||
try:
|
||||
@@ -140,7 +161,7 @@ async def generate_suite(req: SuiteGenerateRequest) -> SuiteCreateResponse:
|
||||
ratio=spec["ratio"],
|
||||
style_set=req.style_set,
|
||||
request_payload={
|
||||
"context": texts_to_raw(req.texts),
|
||||
"context": _with_dimensions(texts_to_raw(req.texts), req.dimensions),
|
||||
"style_prompt": req.style_prompt,
|
||||
"requirements": req.requirements,
|
||||
"watermark": req.watermark.model_dump() if req.watermark else None,
|
||||
@@ -295,6 +316,7 @@ async def suite_image_edit(req: ImageEditSingleRequest) -> ImageEditTaskResponse
|
||||
raise HTTPException(status_code=400, detail="product_id 不是合法 UUID") from exc
|
||||
|
||||
# 单图编辑优先级高于套图;prompt_extra 清空展示文案,避免中文 UI 文案进入模型 prompt。
|
||||
is_size_chart = bool(req.generate_size_chart)
|
||||
task = await create_image_job(
|
||||
product_id=product_id,
|
||||
kind="image_edit",
|
||||
@@ -306,7 +328,7 @@ async def suite_image_edit(req: ImageEditSingleRequest) -> ImageEditTaskResponse
|
||||
ratio=spec["ratio"],
|
||||
style_set=5,
|
||||
request_payload={
|
||||
"context": {"title": "AI 精修"},
|
||||
"context": _with_dimensions({"title": "AI 精修"}, req.dimensions, required=is_size_chart),
|
||||
"style_prompt": None,
|
||||
"requirements": req.prompt,
|
||||
"watermark": req.watermark.model_dump() if req.watermark else None,
|
||||
@@ -316,8 +338,8 @@ async def suite_image_edit(req: ImageEditSingleRequest) -> ImageEditTaskResponse
|
||||
},
|
||||
item_payloads=[{
|
||||
"position": 0,
|
||||
"kind": "custom",
|
||||
"title": "AI生图",
|
||||
"kind": "size_chart" if is_size_chart else "custom",
|
||||
"title": "尺寸标注图" if is_size_chart else "AI生图",
|
||||
"detail": "",
|
||||
"prompt_hint": "",
|
||||
"variant_name": None,
|
||||
|
||||
Reference in New Issue
Block a user