fix: use correct Gemini model for image generation (gemini-3-pro-image-preview)
This commit is contained in:
parent
cf347dfdf8
commit
0724566c05
|
|
@ -77,26 +77,27 @@ Square format, clean edges for die-cut sticker."""
|
||||||
# Call Gemini API for image generation
|
# Call Gemini API for image generation
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient(timeout=120.0) as client:
|
async with httpx.AsyncClient(timeout=120.0) as client:
|
||||||
|
# Use gemini-3-pro-image-preview for image generation
|
||||||
response = await client.post(
|
response = await client.post(
|
||||||
f"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key={gemini_api_key}",
|
f"https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent?key={gemini_api_key}",
|
||||||
json={
|
json={
|
||||||
"contents": [{
|
"contents": [{
|
||||||
"parts": [{
|
"parts": [{
|
||||||
"text": f"Generate an image: {style_prompt}"
|
"text": style_prompt
|
||||||
}]
|
}]
|
||||||
}],
|
}],
|
||||||
"generationConfig": {
|
"generationConfig": {
|
||||||
"responseModalities": ["image", "text"],
|
"responseModalities": ["image", "text"]
|
||||||
"responseMimeType": "image/png"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
headers={"Content-Type": "application/json"}
|
headers={"Content-Type": "application/json"}
|
||||||
)
|
)
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
|
error_detail = response.text[:500] if response.text else "Unknown error"
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=502,
|
status_code=502,
|
||||||
detail=f"AI generation failed: {response.text}"
|
detail=f"AI generation failed ({response.status_code}): {error_detail}"
|
||||||
)
|
)
|
||||||
|
|
||||||
result = response.json()
|
result = response.json()
|
||||||
|
|
@ -112,9 +113,11 @@ Square format, clean edges for die-cut sticker."""
|
||||||
break
|
break
|
||||||
|
|
||||||
if not image_data:
|
if not image_data:
|
||||||
|
# Log what we got for debugging
|
||||||
|
import json
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=502,
|
status_code=502,
|
||||||
detail="AI did not return an image"
|
detail=f"AI did not return an image. Response: {json.dumps(result)[:500]}"
|
||||||
)
|
)
|
||||||
|
|
||||||
except httpx.TimeoutException:
|
except httpx.TimeoutException:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue