mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
Add better handling image generation for gemini models
This commit is contained in:
parent
b949ec90db
commit
02510a908f
1 changed files with 3 additions and 9 deletions
|
|
@ -21,12 +21,6 @@ else:
|
|||
LiteLLMLoggingObj = Any
|
||||
|
||||
|
||||
FLASH_IMAGE_PREVIEW_MODEL_IDENTIFIERS = (
|
||||
"2.0-flash-preview-image",
|
||||
"2.0-flash-preview-image-generation",
|
||||
"2.5-flash-image-preview",
|
||||
"3-pro-image-preview",
|
||||
)
|
||||
class GoogleImageGenConfig(BaseImageGenerationConfig):
|
||||
DEFAULT_BASE_URL: str = "https://generativelanguage.googleapis.com/v1beta"
|
||||
|
||||
|
|
@ -104,7 +98,7 @@ class GoogleImageGenConfig(BaseImageGenerationConfig):
|
|||
complete_url = complete_url.rstrip("/")
|
||||
|
||||
# Gemini Flash Image Preview models use generateContent endpoint
|
||||
if any(identifier in model for identifier in FLASH_IMAGE_PREVIEW_MODEL_IDENTIFIERS):
|
||||
if "gemini" in model:
|
||||
complete_url = f"{complete_url}/models/{model}:generateContent"
|
||||
else:
|
||||
# All other Imagen models use predict endpoint
|
||||
|
|
@ -159,7 +153,7 @@ class GoogleImageGenConfig(BaseImageGenerationConfig):
|
|||
}
|
||||
"""
|
||||
# For Gemini Flash Image Preview models, use standard Gemini format
|
||||
if any(identifier in model for identifier in FLASH_IMAGE_PREVIEW_MODEL_IDENTIFIERS):
|
||||
if "gemini" in model:
|
||||
request_body: dict = {
|
||||
"contents": [
|
||||
{
|
||||
|
|
@ -218,7 +212,7 @@ class GoogleImageGenConfig(BaseImageGenerationConfig):
|
|||
model_response.data = []
|
||||
|
||||
# Handle different response formats based on model
|
||||
if any(identifier in model for identifier in FLASH_IMAGE_PREVIEW_MODEL_IDENTIFIERS):
|
||||
if "gemini" in model:
|
||||
# Gemini Flash Image Preview models return in candidates format
|
||||
candidates = response_data.get("candidates", [])
|
||||
for candidate in candidates:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue