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)")
|
||||
|
||||
# Encode images to base64
|
||||
image_data = [ImageData(b64_json=encode_image_base64(img), revised_prompt=None) for img in images]
|
||||
# Determine output format (default to png)
|
||||
output_format = _choose_output_format(request.output_format or "png", None)
|
||||
|
||||
return ImageGenerationResponse(
|
||||
created=int(time.time()),
|
||||
data=image_data,
|
||||
)
|
||||
# Encode images to base64 with the specified format
|
||||
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:
|
||||
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_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):
|
||||
"""Single generated image data"""
|
||||
|
||||
Reference in new issue
Block a user