Skip to content
This repository was archived by the owner on Jul 17, 2026. It is now read-only.

Commit 7922bc9

Browse files
committed
add 4k resolution for nanobananapro
1 parent 71fd2f8 commit 7922bc9

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ coverage/
5454
# Temporary folders
5555
tmp/
5656
temp/
57-
jimeng-*.md
57+
jimeng-*.md
58+
.ace-tool/

src/api/builders/payload-builder.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import util from "@/lib/util.ts";
2-
import { DRAFT_MIN_VERSION, DRAFT_VERSION, RESOLUTION_OPTIONS } from "@/api/consts/common.ts";
2+
import { DRAFT_MIN_VERSION, DRAFT_VERSION, RESOLUTION_OPTIONS, RESOLUTION_OPTIONS_NANOBANANAPRO_4K } from "@/api/consts/common.ts";
33
import { RegionInfo, getAssistantId } from "@/api/controllers/core.ts";
44

55
export type RegionKey = "CN" | "US" | "HK" | "JP" | "SG";
@@ -20,7 +20,22 @@ function getRegionKey(regionInfo: RegionInfo): RegionKey {
2020
return "CN";
2121
}
2222

23-
function lookupResolution(resolution: string = "2k", ratio: string = "1:1") {
23+
function lookupResolution(resolution: string = "2k", ratio: string = "1:1", userModel?: string) {
24+
// nanobananapro 模型使用 4k 时,使用专用配置
25+
if (userModel === "nanobananapro" && resolution === "4k") {
26+
const ratioConfig = RESOLUTION_OPTIONS_NANOBANANAPRO_4K[ratio];
27+
if (!ratioConfig) {
28+
const supportedRatios = Object.keys(RESOLUTION_OPTIONS_NANOBANANAPRO_4K).join(", ");
29+
throw new Error(`nanobananapro 模型在 4k 分辨率下,不支持的比例 "${ratio}"。支持的比例: ${supportedRatios}`);
30+
}
31+
return {
32+
width: ratioConfig.width,
33+
height: ratioConfig.height,
34+
imageRatio: ratioConfig.ratio,
35+
resolutionType: resolution,
36+
};
37+
}
38+
2439
const resolutionGroup = RESOLUTION_OPTIONS[resolution];
2540
if (!resolutionGroup) {
2641
const supportedResolutions = Object.keys(RESOLUTION_OPTIONS).join(", ");
@@ -76,7 +91,7 @@ export function resolveResolution(
7691
};
7792
} else if (regionKey === "HK" || regionKey === "JP" || regionKey === "SG") {
7893
// HK/JP/SG 站: 强制 1k 分辨率,但 ratio 可自定义
79-
const params = lookupResolution("1k", ratio);
94+
const params = lookupResolution("1k", ratio, userModel);
8095
return {
8196
width: params.width,
8297
height: params.height,
@@ -88,7 +103,7 @@ export function resolveResolution(
88103
}
89104

90105
// 其他所有情况: 使用用户指定的 resolution 和 ratio
91-
const params = lookupResolution(resolution, ratio);
106+
const params = lookupResolution(resolution, ratio, userModel);
92107
return {
93108
...params,
94109
isForced: false,

src/api/consts/common.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,15 @@ export const RESOLUTION_OPTIONS = {
147147
"21:9": {width: 6048, height: 2592, ratio: 108}
148148
}
149149
};
150+
151+
// nanobananapro 模型专用的 4k 分辨率配置(ratio 值与 1k/2k 一致)
152+
export const RESOLUTION_OPTIONS_NANOBANANAPRO_4K = {
153+
"1:1": { width: 4096, height: 4096, ratio: 1 },
154+
"4:3": { width: 4693, height: 3520, ratio: 4 },
155+
"3:4": { width: 3520, height: 4693, ratio: 2 },
156+
"16:9": { width: 5404, height: 3040, ratio: 3 },
157+
"9:16": { width: 3040, height: 5404, ratio: 5 },
158+
"3:2": { width: 4992, height: 3328, ratio: 7 },
159+
"2:3": { width: 3328, height: 4992, ratio: 6 },
160+
"21:9": { width: 6197, height: 2656, ratio: 8 }
161+
};

0 commit comments

Comments
 (0)