Normalize Comfly GPT image model id
This commit is contained in:
parent
382faf6c6d
commit
a939e000cf
@ -240,11 +240,18 @@ function isLongRunningComflyModel(modelId?: string) {
|
||||
return normalized.includes("gpt-image-2") && normalized.includes("4k");
|
||||
}
|
||||
|
||||
function shouldUseComflyChatImageEdit(baseURL: string, modelId?: string) {
|
||||
function isComflyGptImage2Model(baseURL: string, modelId?: string) {
|
||||
const normalizedModelId = String(modelId || "").trim().toLowerCase();
|
||||
return isComflyBaseURL(baseURL) && normalizedModelId.includes("gpt-image-2");
|
||||
}
|
||||
|
||||
function resolveProviderApiModelId(baseURL: string, modelId: string) {
|
||||
if (isComflyGptImage2Model(baseURL, modelId)) {
|
||||
return "gpt-image-2";
|
||||
}
|
||||
return modelId;
|
||||
}
|
||||
|
||||
function resolveRequestTimeoutMs(
|
||||
baseURL: string,
|
||||
imageSize?: "1K" | "2K" | "4K",
|
||||
@ -561,56 +568,6 @@ function collectImageCandidates(value: any, candidates = new Set<string>()) {
|
||||
return candidates;
|
||||
}
|
||||
|
||||
async function requestComflyChatImageEdit(params: {
|
||||
baseURL: string;
|
||||
apiKey: string;
|
||||
model: string;
|
||||
prompt: string;
|
||||
imageUrls: string[];
|
||||
signal: AbortSignal;
|
||||
}) {
|
||||
const { baseURL, apiKey, model, prompt, imageUrls, signal } = params;
|
||||
const endpoint = joinEndpoint(baseURL, "/chat/completions");
|
||||
const content = [
|
||||
{ type: "text", text: prompt },
|
||||
...imageUrls.map((url) => ({
|
||||
type: "image_url",
|
||||
image_url: { url },
|
||||
})),
|
||||
];
|
||||
|
||||
console.log("[OpenAI Image] Using Comfly chat image edit", {
|
||||
model,
|
||||
endpoint,
|
||||
imageCount: imageUrls.length,
|
||||
});
|
||||
|
||||
const response = await fetch(endpoint, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model,
|
||||
stream: false,
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content,
|
||||
},
|
||||
],
|
||||
}),
|
||||
signal,
|
||||
});
|
||||
const payload = await parseJsonResponse(response);
|
||||
if (!response.ok) {
|
||||
throw new Error(`${extractErrorMessage(payload)} (HTTP ${response.status})`);
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
async function requestOpenAIImageGeneration(params: {
|
||||
baseURL: string;
|
||||
apiKey: string;
|
||||
@ -638,6 +595,7 @@ async function requestOpenAIImageGeneration(params: {
|
||||
outputFormat,
|
||||
} = params;
|
||||
const useBltcyImageCompatParams = shouldUseBltcyImageCompatParams(baseURL);
|
||||
const apiModel = resolveProviderApiModelId(baseURL, model);
|
||||
const explicitAspectRatio =
|
||||
typeof aspectRatio === "string" && aspectRatio.trim() && aspectRatio !== "auto"
|
||||
? aspectRatio.trim()
|
||||
@ -649,20 +607,9 @@ async function requestOpenAIImageGeneration(params: {
|
||||
|
||||
try {
|
||||
if (imageUrls.length > 0) {
|
||||
if (shouldUseComflyChatImageEdit(baseURL, model)) {
|
||||
return requestComflyChatImageEdit({
|
||||
baseURL,
|
||||
apiKey,
|
||||
model,
|
||||
prompt,
|
||||
imageUrls,
|
||||
signal: controller.signal,
|
||||
});
|
||||
}
|
||||
|
||||
const endpoint = joinEndpoint(baseURL, "/images/edits");
|
||||
const formData = new FormData();
|
||||
formData.append("model", model);
|
||||
formData.append("model", apiModel);
|
||||
formData.append("prompt", prompt);
|
||||
if (size) formData.append("size", size);
|
||||
if (useBltcyImageCompatParams) {
|
||||
@ -708,7 +655,7 @@ async function requestOpenAIImageGeneration(params: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model,
|
||||
model: apiModel,
|
||||
prompt,
|
||||
...(size ? { size } : {}),
|
||||
...(useBltcyImageCompatParams && explicitAspectRatio
|
||||
@ -816,6 +763,7 @@ export function createOpenAIImage({ apiKey, baseURL }: OpenAIImageConfig) {
|
||||
|
||||
console.log("[OpenAI Image] Submitting request", {
|
||||
model: activeModelId,
|
||||
apiModel: resolveProviderApiModelId(baseURL, activeModelId),
|
||||
size,
|
||||
aspectRatio: aspectRatio || "auto",
|
||||
promptAspectRatio: promptAspectRatio || undefined,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user