fix generations reponse body (#3094)
Signed-off-by: hx02481871@antgroup.com <hx02481871@antgroup.com> Co-authored-by: hx02481871@antgroup.com <hx02481871@antgroup.com>
This commit is contained in:
1 parent
8e9b497387
commit
9a1270e6cc
2 files changed
+22
-6
No files matched your search
@@ -1572,13 +1572,23 @@ async def generate_images(request: ImageGenerationRequest, raw_request: Request)
|
|||||||
|
|
||||||
logger.info(f"Successfully generated {len(images)} image(s)")
|
logger.info(f"Successfully generated {len(images)} image(s)")
|
||||||
|
|
||||||
# Encode images to base64
|
# Determine output format (default to png)
|
||||||
image_data = [ImageData(b64_json=encode_image_base64(img), revised_prompt=None) for img in images]
|
output_format = _choose_output_format(request.output_format or "png", None)
|
||||||
|
|
||||||
return ImageGenerationResponse(
|
# Encode images to base64 with the specified format
|
||||||
created=int(time.time()),
|
image_data = [
|
||||||
data=image_data,
|
ImageData(b64_json=_encode_image_base64_with_compression(img, format=output_format), revised_prompt=None)
|
||||||
)
|
for img in images
|
||||||
|
]
|
||||||
|
|
||||||
|
response_kwargs = {
|
||||||
|
"created": int(time.time()),
|
||||||
|
"data": image_data,
|
||||||
|
"output_format": output_format,
|
||||||
|
}
|
||||||
|
if request.size:
|
||||||
|
response_kwargs["size"] = size_str
|
||||||
|
return ImageGenerationResponse(**response_kwargs)
|
||||||
|
|
||||||
except (EngineGenerateError, EngineDeadError) as exc:
|
except (EngineGenerateError, EngineDeadError) as exc:
|
||||||
return _create_engine_error_json_response(raw_request, exc)
|
return _create_engine_error_json_response(raw_request, exc)
|
||||||
|
|||||||
@@ -139,6 +139,12 @@ class ImageGenerationRequest(BaseModel):
|
|||||||
vae_use_slicing: bool | None = Field(default=False, description="Enable VAE slicing")
|
vae_use_slicing: bool | None = Field(default=False, description="Enable VAE slicing")
|
||||||
vae_use_tiling: bool | None = Field(default=False, description="Enable VAE tiling")
|
vae_use_tiling: bool | None = Field(default=False, description="Enable VAE tiling")
|
||||||
|
|
||||||
|
# Output format for generated images
|
||||||
|
output_format: str | None = Field(
|
||||||
|
default=None,
|
||||||
|
description="Output image format: 'png', 'jpeg', or 'webp'. Defaults to 'png'.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ImageData(BaseModel):
|
class ImageData(BaseModel):
|
||||||
"""Single generated image data"""
|
"""Single generated image data"""
|
||||||
|
|||||||
Reference in new issue
Block a user