test: 26项功能落地性复查(综合冒烟52项+23页巡检, 修复6处缺陷)

This commit is contained in:
HHY
2026-09-25 07:11:37 -07:00
parent 543a94609c
commit 7320ac6240
16 changed files with 348 additions and 20 deletions
+25 -3
View File
@@ -24,9 +24,10 @@ class AiRenderBody(BaseModel):
mode: str = Field(default="quick", pattern="^(quick|photo)$")
style: str = Field(default="modern", pattern="^(modern|chinese|european|nordic)$")
time: str = Field(default="day", pattern="^(day|dusk|night)$")
# quick: indoor/outdoor/studio; photo: render/install/erase/indoor/villa/fence/blank
# quick: indoor/outdoor/studio; photo: render/install/erase/indoor/villa/fence/blank/sunroom-*
scene: str = "indoor"
photo_b64: str | None = Field(default=None, description="照片模式参考图(base64, 不带 dataURL 前缀)")
rect: dict | None = Field(default=None, description="照片模式框选窗洞 {x,y,w,h}(原始照片像素坐标)")
async def _resolve_drawing(db, body: AiRenderBody) -> str | dict | None:
@@ -68,7 +69,26 @@ async def generate(body: AiRenderBody, user: CurrentUser, db: DbSession):
return fail("照片模式需要上传参考照片")
try:
info = describe_window(drawing)
prompt = build_prompt(drawing, body.style, body.time, body.scene)
# 照片模式: 把框选洞口位置转成提示词方位描述, 引导 AI 装窗位置
rect_hint = ""
if body.mode == "photo" and body.rect:
try:
r = body.rect
# 由前端提供照片宽高与洞口坐标(像素) → 相对方位词
ph = float(r.get("photo_h") or 0)
pw = float(r.get("photo_w") or 0)
if pw > 0 and ph > 0:
cx = (float(r["x"]) + float(r["w"]) / 2) / pw
cy = (float(r["y"]) + float(r["h"]) / 2) / ph
horiz = "left" if cx < 0.37 else ("right" if cx > 0.63 else "center")
vert = "upper" if cy < 0.37 else ("lower" if cy > 0.63 else "middle")
area_pct = round((float(r["w"]) * float(r["h"])) / (pw * ph) * 100)
rect_hint = (f"Install the window into the existing window opening located in the "
f"{vert}-{horiz} part of the image (opening covers about {area_pct}% of the frame), "
f"replacing whatever old window or opening is there.")
except Exception:
rect_hint = ""
prompt = build_prompt(drawing, body.style, body.time, body.scene, rect_hint=rect_hint)
size = pick_size(info["width_mm"], info["height_mm"])
except Exception:
return fail("图纸数据解析失败")
@@ -80,10 +100,12 @@ async def generate(body: AiRenderBody, user: CurrentUser, db: DbSession):
async with httpx.AsyncClient(timeout=timeout) as client:
if body.mode == "photo":
img_bytes = base64.b64decode(body.photo_b64.split(",")[-1])
mime = "image/jpeg" if img_bytes[:2] == b"\xff\xd8" else "image/png"
ext = "jpg" if mime == "image/jpeg" else "png"
resp = await client.post(
f"{base}/v1/images/edits", headers=headers,
data={"model": settings.ai_model, "prompt": prompt, "size": size, "n": "1"},
files={"image[]": ("photo.png", img_bytes, "image/png")})
files={"image[]": (f"photo.{ext}", img_bytes, mime)})
else:
resp = await client.post(
f"{base}/v1/images/generations", headers=headers,