Fix Comfly model size override

This commit is contained in:
134 2026-06-12 23:38:54 +08:00
parent 9e52e1844f
commit 748c468013

View File

@ -87,6 +87,15 @@ function normalizeImageSizeLabel(imageSize?: string): "1K" | "2K" | "4K" {
return DEFAULT_IMAGE_SIZE;
}
function inferImageSizeFromModelId(modelId?: string): "1K" | "2K" | "4K" | undefined {
const normalized = String(modelId || "").trim().toLowerCase();
const explicitBucket = normalized.match(/(?:^|[-_\s])([124])k(?:$|[-_\s])/);
if (explicitBucket?.[1] === "1") return "1K";
if (explicitBucket?.[1] === "2") return "2K";
if (explicitBucket?.[1] === "4") return "4K";
return undefined;
}
function normalizeAspectRatio(value?: string) {
const normalized = String(value || "").trim();
if (!normalized || normalized.toLowerCase() === "auto") return "auto";
@ -591,10 +600,16 @@ export function createOpenAIImage({ apiKey, baseURL }: OpenAIImageConfig) {
normalizedAspectRatio === "auto"
? promptAspectRatio || (await inferAspectRatioFromImageUrl(imageUrls[0] || ""))
: normalizedAspectRatio;
const imageSize = normalizeImageSizeLabel(options.imageParams?.imageSize);
const requestedImageSize = normalizeImageSizeLabel(options.imageParams?.imageSize);
const modelImageSize = isComflyBaseURL(baseURL)
? inferImageSizeFromModelId(activeModelId)
: undefined;
const imageSize = modelImageSize || requestedImageSize;
const size =
options.imageParams?.size ||
(aspectRatio ? resolveProviderImageSize(baseURL, aspectRatio, imageSize) : undefined);
modelImageSize && aspectRatio
? resolveProviderImageSize(baseURL, aspectRatio, imageSize)
: options.imageParams?.size ||
(aspectRatio ? resolveProviderImageSize(baseURL, aspectRatio, imageSize) : undefined);
const quality = normalizeQuality(options.imageParams?.quality);
const background = normalizeBackground(options.imageParams?.background);
const outputFormat = normalizeOutputFormat(options.imageParams?.outputFormat);
@ -605,6 +620,8 @@ export function createOpenAIImage({ apiKey, baseURL }: OpenAIImageConfig) {
aspectRatio: aspectRatio || "auto",
promptAspectRatio: promptAspectRatio || undefined,
imageSize,
requestedImageSize,
modelImageSize,
resolutionMode: isComflyBaseURL(baseURL) ? "longest-edge" : "pixel-area",
timeoutMs: resolveRequestTimeoutMs(baseURL, imageSize, activeModelId),
useBltcyImageCompatParams: shouldUseBltcyImageCompatParams(baseURL),