fix: pass bltcy image aspect params
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled

This commit is contained in:
Your Name 2026-05-12 17:18:26 +08:00
parent a0e303abcb
commit 40e7ecc7da

View File

@ -28,7 +28,6 @@ const DEFAULT_TIMEOUT_MS = 300000;
const OPENAI_IMAGE_MIN_TOTAL_PIXELS = 3_686_400;
const OPENAI_IMAGE_DIMENSION_MULTIPLE = 16;
const BLTCY_HOST_REGEX = /(^|\.)bltcy\.ai$/i;
const KONTEXT_MODEL_REGEX = /kontext/i;
const SUPPORTED_ASPECT_RATIOS = [
"1:1",
"1:4",
@ -67,8 +66,8 @@ function isBltcyBaseURL(baseURL: string) {
}
}
function shouldUseBltcyFluxCompatParams(baseURL: string, model: string) {
return isBltcyBaseURL(baseURL) && KONTEXT_MODEL_REGEX.test(String(model || "").trim());
function shouldUseBltcyImageCompatParams(baseURL: string) {
return isBltcyBaseURL(baseURL);
}
function normalizeImageSizeLabel(imageSize?: string): "1K" | "2K" | "4K" {
@ -413,7 +412,7 @@ async function requestOpenAIImageGeneration(params: {
background,
outputFormat,
} = params;
const useBltcyFluxCompatParams = shouldUseBltcyFluxCompatParams(baseURL, model);
const useBltcyImageCompatParams = shouldUseBltcyImageCompatParams(baseURL);
const explicitAspectRatio =
typeof aspectRatio === "string" && aspectRatio.trim() && aspectRatio !== "auto"
? aspectRatio.trim()
@ -429,7 +428,7 @@ async function requestOpenAIImageGeneration(params: {
formData.append("model", model);
formData.append("prompt", prompt);
if (size) formData.append("size", size);
if (useBltcyFluxCompatParams) {
if (useBltcyImageCompatParams) {
if (explicitAspectRatio) formData.append("aspect_ratio", explicitAspectRatio);
if (imageSizeLabel) formData.append("image_size", imageSizeLabel);
}
@ -475,10 +474,10 @@ async function requestOpenAIImageGeneration(params: {
model,
prompt,
...(size ? { size } : {}),
...(useBltcyFluxCompatParams && explicitAspectRatio
...(useBltcyImageCompatParams && explicitAspectRatio
? { aspect_ratio: explicitAspectRatio }
: {}),
...(useBltcyFluxCompatParams && imageSizeLabel ? { image_size: imageSizeLabel } : {}),
...(useBltcyImageCompatParams && imageSizeLabel ? { image_size: imageSizeLabel } : {}),
response_format: "url",
...(quality ? { quality } : {}),
...(background ? { background } : {}),
@ -552,7 +551,7 @@ export function createOpenAIImage({ apiKey, baseURL }: OpenAIImageConfig) {
aspectRatio: aspectRatio || "auto",
promptAspectRatio: promptAspectRatio || undefined,
imageSize,
useBltcyFluxCompatParams: shouldUseBltcyFluxCompatParams(baseURL, activeModelId),
useBltcyImageCompatParams: shouldUseBltcyImageCompatParams(baseURL),
imageCount: imageUrls.length,
baseURL: normalizeBaseURL(baseURL),
});