fix: support Agnes image-to-image generations API
This commit is contained in:
parent
5b2418701f
commit
dd65ef46a7
@ -36,6 +36,7 @@ const COMFLY_GPT_IMAGE_MAX_EDGE = 3840;
|
||||
const COMFLY_GPT_IMAGE_MAX_TOTAL_PIXELS = 8_294_400;
|
||||
const BLTCY_HOST_REGEX = /(^|\.)bltcy\.ai$/i;
|
||||
const COMFLY_HOST_REGEX = /(^|\.)ai\.comfly\.org$/i;
|
||||
const AGNES_HOST_REGEX = /(^|\.)agnes-ai\.com$/i;
|
||||
const SUPPORTED_ASPECT_RATIOS = [
|
||||
"1:1",
|
||||
"1:4",
|
||||
@ -87,6 +88,20 @@ function isComflyBaseURL(baseURL: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function isAgnesBaseURL(baseURL: string) {
|
||||
try {
|
||||
const parsed = new URL(normalizeBaseURL(baseURL));
|
||||
return AGNES_HOST_REGEX.test(parsed.hostname);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function isAgnesImageModel(baseURL: string, modelId?: string) {
|
||||
const normalizedModelId = String(modelId || "").trim().toLowerCase();
|
||||
return isAgnesBaseURL(baseURL) && normalizedModelId.startsWith("agnes-image-");
|
||||
}
|
||||
|
||||
function normalizeImageSizeLabel(imageSize?: string): "1K" | "2K" | "4K" {
|
||||
const normalized = String(imageSize || "").trim().toUpperCase();
|
||||
if (normalized === "1K" || normalized === "2K" || normalized === "4K") return normalized;
|
||||
@ -607,6 +622,32 @@ async function requestOpenAIImageGeneration(params: {
|
||||
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
||||
|
||||
try {
|
||||
if (isAgnesImageModel(baseURL, model)) {
|
||||
const endpoint = joinEndpoint(baseURL, "/images/generations");
|
||||
const response = await fetch(endpoint, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: apiModel,
|
||||
prompt,
|
||||
...(size ? { size } : {}),
|
||||
extra_body: {
|
||||
...(imageUrls.length > 0 ? { image: imageUrls } : {}),
|
||||
response_format: "url",
|
||||
},
|
||||
}),
|
||||
signal: controller.signal,
|
||||
});
|
||||
const payload = await parseJsonResponse(response);
|
||||
if (!response.ok) {
|
||||
throw new Error(`${extractErrorMessage(payload)} (HTTP ${response.status})`);
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
if (imageUrls.length > 0) {
|
||||
const endpoint = joinEndpoint(baseURL, "/images/edits");
|
||||
const formData = new FormData();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user