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