feat(接口4): 用户特征-火山方舟豆包视觉模型(替换Mock)

接口4 改用远程视觉大模型(算法来源 /home/xsl/fuyan),一次返回几十项面部特征。

- face_features.py: 火山方舟 Ark 客户端(单例)+doubao-seed-1-6-vision prompt(移植fuyan)
  +base64 data URI喂图(实测doubao接受)+解析JSON+映射6英文优先字段(face_shape等)
  并保留doubao全部中文字段;has_face 据"图片是否有人脸"判定
- app.py: /face/features 真实实现,三选一图(image_url直传doubao,file/base64转dataURI),
  features 为 JSON 字符串;无人脸→1001;重活线程池
- 配置: API Key 走 worker_config.json.ark_api_key / 环境变量 ARK_API_KEY(不入git);
  worker_config.example 加占位; requirements 加 volcengine-python-sdk[ark]
- 文档: 接口文档/OpenAPI 更新为豆包实现+几十项字段+1001
- 测试: mock doubao 的成功/无人脸/多参,47全绿

⚠️ 唯一调外网云模型的接口,worker 需可达 ark.cn-beijing.volces.com(已实测可达)。
实测 frontal: 42字段, 鹅蛋脸/平眉/18-25岁/静态型/女/少年型。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
xsl
2026-06-15 10:50:17 +08:00
co-authored by Claude Opus 4.8
parent 795de68985
commit 0e71830bb6
6 changed files with 233 additions and 37 deletions
+29
View File
@@ -1,5 +1,6 @@
"""接口集成测试(FastAPI TestClient):错误码 + 鉴权 + 正常用例结构。"""
import base64
import json
import pytest
from fastapi.testclient import TestClient
@@ -150,6 +151,34 @@ def test_hairline_gen_female(client):
assert "image_url" not in d["hairline_images"][0]
FEATURES = "/api/v1/face/features"
def test_features_success(client, monkeypatch):
import face_features as ff
monkeypatch.setattr(ff, "analyze_features", lambda *a, **k: {
"图片是否有人脸": "有人", "脸型": "鹅蛋脸", "face_shape": "鹅蛋脸",
"gender": "", "gene_style": "少女型"})
files = {"image_file": ("frontal.jpg", open(fixture("frontal.jpg"), "rb"), "application/octet-stream")}
body = client.post(FEATURES, headers=H, files=files).json()
assert body["code"] == 0, body
f = json.loads(body["data"]["features"]) # features 是 JSON 字符串
assert f["face_shape"] == "鹅蛋脸" and f["gender"] == ""
def test_features_no_face_1001(client, monkeypatch):
import face_features as ff
monkeypatch.setattr(ff, "analyze_features", lambda *a, **k: {"图片是否有人脸": "没人"})
files = {"image_file": ("x.jpg", open(fixture("landscape.jpg"), "rb"), "application/octet-stream")}
assert client.post(FEATURES, headers=H, files=files).json()["code"] == 1001
def test_features_multi_param_1007(client):
files = {"image_file": ("frontal.jpg", open(fixture("frontal.jpg"), "rb"), "application/octet-stream")}
r = client.post(FEATURES, headers=H, files=files, data={"image_url": "http://x/y.jpg"})
assert r.json()["code"] == 1007
def test_success_structure(client):
r = _post(client, "frontal.jpg")
body = r.json()