fix(image): support stream and moderation options

This commit is contained in:
2026-05-25 18:42:47 +08:00
parent ca2fa1b03d
commit 7b9b96e332
9 changed files with 609 additions and 4 deletions

View File

@@ -287,7 +287,48 @@ else:
raise RuntimeError(f"unexpected response: {data}")
```
## 15. 图片接口常见问题
## 15. `stream`、`partial_images`、`moderation`
`gpt-image-2` 的图片接口可额外尝试下面几个字段:
- `stream``true` / `false`
- `partial_images`:整数,常见值 `1`
- `moderation``auto``low`
示例:
```json
{
"model": "gpt-image-2",
"prompt": "火影忍者真人版海报",
"size": "3840x1280",
"quality": "high",
"output_format": "png",
"moderation": "low",
"stream": true,
"partial_images": 1
}
```
说明:
- `stream=true` 时,服务端可能返回 `text/event-stream`
- `partial_images=1` 表示在最终图之前,先推 1 张中间图。
- `moderation` 当前只观察到 `auto``low` 两个枚举值。
- 不是所有兼容网关都会真的返回 SSE有些网关即使接受 `stream=true`,仍然返回普通 JSON。
仓库里的环境变量映射:
- `IMAGE_STREAM=true`
- `IMAGE_PARTIAL_IMAGES=1`
- `IMAGE_MODERATION=low`
脚本处理策略:
- 收到 `EventStream`:逐条解析事件,保存 `stream-events.jsonl``partials/`
- 没收到 `EventStream`:自动回退到同步 JSON 或异步任务轮询逻辑。
## 16. 图片接口常见问题
- 只传 `size: "16:9"` 不能保证一定是 4K要 4K推荐直接传 `4096x2304` 等像素尺寸。
- `gpt-image-1``gpt-image-1.5` 不支持真正 4K网关会自动降级。
@@ -295,7 +336,7 @@ else:
- 单张图可能耗时较长,客户端 `timeout` 建议至少 120 秒4K 建议 240 秒。
- 如果返回 `b64_json`,说明当前是同步模式,不需要再轮询 `task_id`
## 16. 直连测试命令
## 17. 直连测试命令
- 运行 `scripts/run_figma_direct_test.sh` 会先读取当前 `.env`,再临时清空本地代理并直连 `vip.auto-code.net`
- 它只强制 `IMAGE_REQUEST_STYLE=apicodex``IMAGE_SIZE=3840x2160` 和长超时,其余参数继续沿用 `.env``gpt_image2_generate.py` 的默认值。