agagsder commited on
Commit
ab16a12
·
verified ·
1 Parent(s): 21b9f54

Enable switchable image response adapter

Browse files
Files changed (2) hide show
  1. Dockerfile +15 -5
  2. README.md +23 -10
Dockerfile CHANGED
@@ -1,10 +1,20 @@
1
- # 使用官方正版镜像 (Calcium-Ion)
 
 
 
 
 
 
2
  FROM calciumion/new-api:latest
3
 
4
- # 设置 Hugging Face 要求的端口
5
- ENV PORT=7860
 
 
6
  EXPOSE 7860
7
 
8
- # 解决权限问题 (必须加,否则会报错无法写入数据库)
9
  USER root
10
- RUN mkdir -p /data && chmod 777 /data
 
 
 
 
1
+ FROM golang:1.24-alpine AS adapter-builder
2
+
3
+ WORKDIR /src/adapter
4
+ COPY adapter/ ./
5
+ RUN go test ./... && \
6
+ CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/image-response-adapter .
7
+
8
  FROM calciumion/new-api:latest
9
 
10
+ ENV PORT=7860 \
11
+ INTERNAL_NEW_API_PORT=3000 \
12
+ IMAGE_RESPONSE_MODE=b64_json \
13
+ IMAGE_CONVERSION_MAX_CONCURRENCY=4
14
  EXPOSE 7860
15
 
 
16
  USER root
17
+ RUN mkdir -p /data && chmod 777 /data
18
+
19
+ COPY --from=adapter-builder /out/image-response-adapter /image-response-adapter
20
+ ENTRYPOINT ["/image-response-adapter"]
README.md CHANGED
@@ -1,11 +1,24 @@
1
- ---
2
- title: New Api
3
- emoji: 💻
4
- colorFrom: red
5
- colorTo: indigo
6
- sdk: docker
7
- pinned: false
8
- license: mit
9
- ---
10
-
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: New Api
3
+ emoji: 💻
4
+ colorFrom: red
5
+ colorTo: indigo
6
+ sdk: docker
7
+ pinned: false
8
+ license: mit
9
+ ---
10
+
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
12
+
13
+ This Space runs the official New API image behind a small response adapter. All
14
+ requests are proxied unchanged except successful `/v1/images/generations` and
15
+ `/v1/images/edits` responses containing `data[].url` without `b64_json`. For
16
+ those responses, the adapter downloads the public image URL and returns the
17
+ official Base64 response shape expected by OpenAI-compatible clients.
18
+
19
+ The default mode is `b64_json`. A caller that needs the original URL can set
20
+ `response_format: "url"` in a JSON generation request or send
21
+ `X-Image-Response-Format: url`. The custom header is removed before forwarding.
22
+ Set `IMAGE_RESPONSE_MODE=url` to make URL passthrough the Space-wide default.
23
+ `IMAGE_CONVERSION_MAX_CONCURRENCY` limits simultaneous URL downloads and
24
+ defaults to `4` for CPU Basic hardware.