Prefer streaming for custom image generation
This commit is contained in:
@@ -409,6 +409,15 @@ function extractImagesFromGenerationsResponse(data: Record<string, unknown>): st
|
||||
} else if (typeof data.image_url === 'string') {
|
||||
images.push(data.image_url);
|
||||
}
|
||||
|
||||
const streamEvents = data.__streamEvents;
|
||||
if (Array.isArray(streamEvents)) {
|
||||
for (const event of streamEvents) {
|
||||
if (!event || typeof event !== 'object' || Array.isArray(event)) continue;
|
||||
images.push(...extractImagesFromGenerationsResponse(event as Record<string, unknown>));
|
||||
}
|
||||
}
|
||||
|
||||
return images;
|
||||
}
|
||||
|
||||
@@ -511,6 +520,7 @@ async function tryEditsWithFormData(
|
||||
const textFields: Record<string, string> = {
|
||||
model,
|
||||
prompt,
|
||||
stream: 'true',
|
||||
};
|
||||
if (size) textFields.size = size;
|
||||
if (count > 1) textFields.n = String(count);
|
||||
@@ -700,7 +710,7 @@ async function customApiImageToImage(
|
||||
const chatUrl = deriveChatCompletionsUrl(endpoint);
|
||||
const chatBody: Record<string, unknown> = {
|
||||
model: customApiConfig.modelName,
|
||||
stream: false,
|
||||
stream: true,
|
||||
messages: [
|
||||
{
|
||||
role: 'user',
|
||||
@@ -734,6 +744,7 @@ async function customApiImageToImage(
|
||||
n: count,
|
||||
size: size || '1024x1024',
|
||||
response_format: 'b64_json',
|
||||
stream: true,
|
||||
init_image: rawBase64,
|
||||
denoising_strength: denoisingStrength,
|
||||
};
|
||||
@@ -871,6 +882,7 @@ export async function POST(request: NextRequest) {
|
||||
n,
|
||||
size: size || '1024x1024',
|
||||
response_format: 'b64_json',
|
||||
stream: true,
|
||||
};
|
||||
if (negativePrompt) {
|
||||
requestBody.negative_prompt = negativePrompt;
|
||||
@@ -889,6 +901,7 @@ export async function POST(request: NextRequest) {
|
||||
'| size:', requestBody.size,
|
||||
'| n:', requestBody.n,
|
||||
'| aspect_ratio:', requestBody.aspect_ratio,
|
||||
'| stream:', requestBody.stream,
|
||||
'| guidance_scale:', requestBody.guidance_scale,
|
||||
'| prompt_length:', prompt.length,
|
||||
'| augmented_prompt_length:', augmentedPrompt.length);
|
||||
|
||||
Reference in New Issue
Block a user