mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-09-07 08:46:37 +08:00
feat: 支持图片生成响应格式切换并优化Markdown渲染
This commit is contained in:
@@ -27,4 +27,4 @@ class ImageGenerationRequest(BaseModel):
|
|||||||
size: Optional[str] = "1024x1024"
|
size: Optional[str] = "1024x1024"
|
||||||
quality: Optional[str] = ""
|
quality: Optional[str] = ""
|
||||||
style: Optional[str] = ""
|
style: Optional[str] = ""
|
||||||
response_format: Optional[str] = "b64_json"
|
response_format: Optional[str] = "url"
|
||||||
|
|||||||
@@ -56,11 +56,17 @@ class ImageCreateService:
|
|||||||
filename = f"{current_date}/{uuid.uuid4().hex[:8]}.png"
|
filename = f"{current_date}/{uuid.uuid4().hex[:8]}.png"
|
||||||
upload_response = image_uploader.upload(image_data,filename)
|
upload_response = image_uploader.upload(image_data,filename)
|
||||||
|
|
||||||
# base64_image = base64.b64encode(image_data).decode('utf-8')
|
if request.response_format == "b64_json":
|
||||||
images_data.append({
|
base64_image = base64.b64encode(image_data).decode('utf-8')
|
||||||
"url": f"{upload_response.data.url}",
|
images_data.append({
|
||||||
"revised_prompt": request.prompt
|
"b64_json": base64_image,
|
||||||
})
|
"revised_prompt": request.prompt
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
images_data.append({
|
||||||
|
"url": f"{upload_response.data.url}",
|
||||||
|
"revised_prompt": request.prompt
|
||||||
|
})
|
||||||
|
|
||||||
response_data = {
|
response_data = {
|
||||||
"created": int(time.time()), # Current timestamp
|
"created": int(time.time()), # Current timestamp
|
||||||
@@ -76,6 +82,9 @@ class ImageCreateService:
|
|||||||
if image_datas:
|
if image_datas:
|
||||||
markdown_images = []
|
markdown_images = []
|
||||||
for index, image_data in enumerate(image_datas):
|
for index, image_data in enumerate(image_datas):
|
||||||
markdown_images.append(f"")
|
if 'url' in image_data:
|
||||||
|
markdown_images.append(f"")
|
||||||
|
else:
|
||||||
|
# 如果是base64格式,创建data URL
|
||||||
|
markdown_images.append(f"")
|
||||||
return "\n".join(markdown_images)
|
return "\n".join(markdown_images)
|
||||||
|
|
||||||
Reference in New Issue
Block a user