From 5fd7d05d26b48b991ca2f4dc9b93244152c17604 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 24 Jun 2026 20:49:34 +0800 Subject: [PATCH] save code --- face_features.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/face_features.py b/face_features.py index eda031b..0fa6785 100644 --- a/face_features.py +++ b/face_features.py @@ -103,20 +103,23 @@ def analyze_features(image_bytes: bytes = None, image_url: str = None): {"type": "image_url", "image_url": {"url": url}}, {"type": "text", "text": _PROMPT}, ], - # 【SDK原生支持的标准参数,绝对不报错】 - max_tokens=1024, # 限制输出长度,模型秒回 - temperature=0, # 固定输出,无随机采样,提速+结果稳定 - stream=False, # 关闭流式,单次返回结果更快 - # 【官方正确写法】扩展参数必须放在extra_body中传递 - extra_body={ - "thinking": { - "type": "disabled" # 【核心提速】彻底关闭深度思考模式,提速50%+,官方标准格式{insert\_element\_1\_} - } - } }], + max_tokens=1024, # 限制输出长度,模型秒回 + temperature=0, # 固定输出,无随机采样,提速+结果稳定 + stream=False, # 关闭流式,单次返回结果更快 + extra_body={ + "thinking": { + "type": "disabled", # 彻底关闭深度思考模式,提速50%+ + }, + }, ) text = resp.choices[0].message.content - raw = _parse_json(text) # doubao 原始中文字段 + logger.info("doubao raw response (first 500 chars): %s", text[:500]) + try: + raw = _parse_json(text) # doubao 原始中文字段 + except (json.JSONDecodeError, ValueError) as e: + logger.error("doubao 返回非 JSON,原文: %s", text[:1000]) + raise RuntimeError(f"豆包模型返回格式异常,无法解析为 JSON:{text[:200]}") from e if not has_face(raw): return None # 只保留 6 个英文字段(doubao 缺某字段则跳过)