fix: preserve SnapGen resolution tiers
This commit is contained in:
parent
dcd005d369
commit
5973359197
@ -644,8 +644,11 @@ type AgentVideoPlan = {
|
||||
|
||||
function normalizeChatImageSize(value?: string | null): ChatImageSize | undefined {
|
||||
const normalized = String(value || "").trim().toUpperCase();
|
||||
if (normalized === "1K" || normalized === "2K" || normalized === "4K") {
|
||||
return normalized;
|
||||
const kMatch = normalized.match(/^(\d+(?:\.\d+)?)K$/);
|
||||
if (!kMatch?.[1]) return undefined;
|
||||
const normalizedK = `${Number(kMatch[1]).toString()}K`;
|
||||
if (["0.5K", "1K", "2K", "4K", "8K", "10K", "12K"].includes(normalizedK)) {
|
||||
return normalizedK as ChatImageSize;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ const videoParamsSchema = z.object({
|
||||
returnLastFrame: z.boolean().optional(),
|
||||
}).optional();
|
||||
|
||||
const imageSizeValues = ["1K", "2K", "4K"] as const;
|
||||
const imageSizeValues = ["0.5K", "1K", "2K", "4K", "8K", "10K", "12K"] as const;
|
||||
|
||||
function normalizeImageSizeInput(value: unknown) {
|
||||
if (typeof value !== "string") return undefined;
|
||||
|
||||
@ -90,6 +90,10 @@ function normalizeResolution(imageSize?: string, apiFormat?: SnapgenApiFormat) {
|
||||
return defaultResolution;
|
||||
}
|
||||
|
||||
function toSnapgenResolutionParam(resolution: string) {
|
||||
return resolution.trim().toLowerCase();
|
||||
}
|
||||
|
||||
function normalizeOutputFormat(outputFormat?: string): "png" | "jpeg" {
|
||||
if (!outputFormat) return DEFAULT_OUTPUT_FORMAT;
|
||||
const normalized = outputFormat.trim().toLowerCase();
|
||||
@ -709,6 +713,7 @@ function appendGenericFields({
|
||||
imageUrls,
|
||||
aspectRatio,
|
||||
resolution,
|
||||
resolutionParam,
|
||||
outputFormat,
|
||||
}: {
|
||||
formData: FormData;
|
||||
@ -717,12 +722,13 @@ function appendGenericFields({
|
||||
imageUrls: string[];
|
||||
aspectRatio: string;
|
||||
resolution: string;
|
||||
resolutionParam: string;
|
||||
outputFormat: string;
|
||||
}) {
|
||||
formData.append("prompt", prompt);
|
||||
formData.append("model", getGenericEndpointModel(runtimeModelId));
|
||||
formData.append("aspect_ratio", aspectRatio);
|
||||
formData.append("resolution", resolution);
|
||||
formData.append("resolution", resolutionParam || toSnapgenResolutionParam(resolution));
|
||||
formData.append("output_format", outputFormat);
|
||||
for (const imageUrl of imageUrls.slice(0, 8)) {
|
||||
formData.append("file_urls", imageUrl);
|
||||
@ -743,6 +749,7 @@ async function buildRequestForm({
|
||||
imageUrls,
|
||||
aspectRatio,
|
||||
resolution,
|
||||
resolutionParam,
|
||||
imageCount,
|
||||
outputFormat,
|
||||
quality,
|
||||
@ -753,6 +760,7 @@ async function buildRequestForm({
|
||||
imageUrls: string[];
|
||||
aspectRatio: string;
|
||||
resolution: string;
|
||||
resolutionParam: string;
|
||||
imageCount: number;
|
||||
outputFormat: string;
|
||||
quality?: string;
|
||||
@ -778,7 +786,7 @@ async function buildRequestForm({
|
||||
case "snapgen-gpt-image-2": {
|
||||
formData.append("prompt", prompt);
|
||||
formData.append("aspect_ratio", aspectRatio);
|
||||
formData.append("resolution", resolution);
|
||||
formData.append("resolution", resolutionParam || toSnapgenResolutionParam(resolution));
|
||||
formData.append("mode", normalizeGptImage2Mode(quality));
|
||||
await appendReferenceFiles(formData, imageUrls);
|
||||
return formData;
|
||||
@ -792,6 +800,7 @@ async function buildRequestForm({
|
||||
imageUrls,
|
||||
aspectRatio,
|
||||
resolution,
|
||||
resolutionParam,
|
||||
outputFormat,
|
||||
});
|
||||
return formData;
|
||||
@ -863,6 +872,7 @@ export function createSnapgenImage({ apiKey, baseURL }: SnapgenImageConfig) {
|
||||
});
|
||||
const aspectRatio = resolvedAspectRatio.aspectRatio;
|
||||
const resolution = normalizeResolution(options.imageParams?.imageSize, apiFormat);
|
||||
const resolutionParam = toSnapgenResolutionParam(resolution);
|
||||
const outputFormat = normalizeOutputFormat(options.imageParams?.outputFormat);
|
||||
const maxImages = options.imageGenConfig?.maxImages || (apiFormat === "snapgen-grok-image" ? 8 : apiFormat === "snapgen-meta-ai-image" ? 4 : 1);
|
||||
const imageCount = clampImageCount(options.imageParams?.imageCount, maxImages);
|
||||
@ -873,6 +883,7 @@ export function createSnapgenImage({ apiKey, baseURL }: SnapgenImageConfig) {
|
||||
imageUrls,
|
||||
aspectRatio,
|
||||
resolution,
|
||||
resolutionParam,
|
||||
imageCount,
|
||||
outputFormat,
|
||||
quality: options.imageParams?.quality,
|
||||
@ -885,7 +896,9 @@ export function createSnapgenImage({ apiKey, baseURL }: SnapgenImageConfig) {
|
||||
aspectRatio,
|
||||
aspectRatioSource: resolvedAspectRatio.aspectRatioSource,
|
||||
referenceImageSize: resolvedAspectRatio.referenceImageSize,
|
||||
requestedImageSize: options.imageParams?.imageSize,
|
||||
resolution,
|
||||
resolutionParam,
|
||||
imageCount,
|
||||
referenceImageCount: imageUrls.length,
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user