review+docs: 接口4 回收到网关、对齐错误码、合并文档为一份实现说明
代码 review 后的清理: - 接口4 由网关本机实现,worker app.py 的 /face/features 回退 Mock(保持 worker 无外网依赖); worker requirements 标注 volcengine 改为网关侧;移除 worker 的接口4 测试(随实现挪到网关) - 网关接口4 业务错误 HTTP 状态统一改 200(与其余接口/worker 约定一致,原为400/503) - 接口文档:gender 非法码 1004(原误写1008);修正指向已删文档的链接 文档合并:把各接口技术方案/开发任务书/系统架构/网关任务书 合并成 docs/实现说明.md(简要总览), 删除原 7 份分散文档,README 收敛为索引(实现说明/接口文档/需求/OFFLINE_ASSETS)。 pytest 44 全绿。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -679,32 +679,17 @@ async def face_features(
|
||||
image_url: Optional[str] = Form(default=None, description="图片 URL"),
|
||||
image_base64: Optional[str] = Form(default=None, description="图片 base64(需带 data:image/...;base64, 前缀)"),
|
||||
):
|
||||
# 三选一。image_url 直接交给豆包拉取;file/base64 解成字节转 data URI。
|
||||
provided = [x for x in (image_file, image_url, image_base64) if x]
|
||||
if len(provided) != 1:
|
||||
return err(1007, "图片参数错误:必须且只能传 image_file / image_url / image_base64 其中一个")
|
||||
|
||||
img_bytes = None
|
||||
if not image_url:
|
||||
raw, e = await resolve_image_bytes(image_file, None, image_base64)
|
||||
if e is not None:
|
||||
return e
|
||||
if len(raw) > MAX_FILE_BYTES:
|
||||
return err(1006, "文件超出 1 MB 限制")
|
||||
img_bytes = raw
|
||||
|
||||
try:
|
||||
from fastapi.concurrency import run_in_threadpool
|
||||
from face_features import analyze_features, has_face
|
||||
|
||||
feats = await run_in_threadpool(analyze_features, img_bytes, image_url)
|
||||
if not has_face(feats):
|
||||
return err(1001, "无法识别人像")
|
||||
# 契约:data.features 为 JSON 字符串
|
||||
return ok({"features": json.dumps(feats, ensure_ascii=False)})
|
||||
except Exception as ex: # noqa: BLE001
|
||||
logger.exception("接口4 处理异常")
|
||||
return err(1007, f"处理失败:{ex}")
|
||||
# ⚠️ 接口4 已迁到**网关本机**实现(直接调豆包视觉模型,见 gateway/app.py)。
|
||||
# 网关不会把本接口转发到 worker,故此处仅留 Mock 占位、保持 worker 无外网依赖。
|
||||
features = json.dumps(
|
||||
{
|
||||
"_note": "接口4 由网关实现,worker 此响应为占位 Mock",
|
||||
"face_shape": "鹅蛋脸", "eyebrow_shape": "平眉", "facial_age": "18-25岁",
|
||||
"dynamic_static_type": "静态型", "gender": "女", "gene_style": "少年型",
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
return ok({"features": features})
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user