mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-05-20 15:50:10 +08:00
feat: 支持图片生成响应格式切换并优化Markdown渲染
This commit is contained in:
@@ -27,4 +27,4 @@ class ImageGenerationRequest(BaseModel):
|
||||
size: Optional[str] = "1024x1024"
|
||||
quality: 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"
|
||||
upload_response = image_uploader.upload(image_data,filename)
|
||||
|
||||
# base64_image = base64.b64encode(image_data).decode('utf-8')
|
||||
images_data.append({
|
||||
"url": f"{upload_response.data.url}",
|
||||
"revised_prompt": request.prompt
|
||||
})
|
||||
if request.response_format == "b64_json":
|
||||
base64_image = base64.b64encode(image_data).decode('utf-8')
|
||||
images_data.append({
|
||||
"b64_json": base64_image,
|
||||
"revised_prompt": request.prompt
|
||||
})
|
||||
else:
|
||||
images_data.append({
|
||||
"url": f"{upload_response.data.url}",
|
||||
"revised_prompt": request.prompt
|
||||
})
|
||||
|
||||
response_data = {
|
||||
"created": int(time.time()), # Current timestamp
|
||||
@@ -76,6 +82,9 @@ class ImageCreateService:
|
||||
if image_datas:
|
||||
markdown_images = []
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user