Admin
commited on
Commit
·
b4b63c6
1
Parent(s):
6a7eb16
111
Browse files- app/main.py +30 -0
app/main.py
CHANGED
|
@@ -323,6 +323,36 @@ async def global_exception_handler(request: Request, exc: Exception):
|
|
| 323 |
return JSONResponse(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=ErrorResponse(message=str(exc), type="internal_error").dict())
|
| 324 |
|
| 325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
@app.get("/", response_class=HTMLResponse)
|
| 327 |
async def root():
|
| 328 |
html_content = f"""
|
|
|
|
| 323 |
return JSONResponse(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, content=ErrorResponse(message=str(exc), type="internal_error").dict())
|
| 324 |
|
| 325 |
|
| 326 |
+
@app.post("/v1beta/models/gemini-3-pro-image-preview:generateContent")
|
| 327 |
+
async def proxy_gemini_vision(request: Request, key: str):
|
| 328 |
+
"""
|
| 329 |
+
Direct proxy for gemini-3-pro-image-preview:generateContent
|
| 330 |
+
"""
|
| 331 |
+
try:
|
| 332 |
+
body = await request.json()
|
| 333 |
+
target_url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent?key={key}"
|
| 334 |
+
|
| 335 |
+
headers = {
|
| 336 |
+
"Content-Type": "application/json"
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
# Use httpx for async request
|
| 340 |
+
import httpx
|
| 341 |
+
async with httpx.AsyncClient() as client:
|
| 342 |
+
response = await client.post(target_url, json=body, headers=headers, timeout=60)
|
| 343 |
+
|
| 344 |
+
# Forward the status code and content
|
| 345 |
+
if response.status_code != 200:
|
| 346 |
+
return JSONResponse(status_code=response.status_code, content=response.json())
|
| 347 |
+
|
| 348 |
+
return response.json()
|
| 349 |
+
|
| 350 |
+
except Exception as e:
|
| 351 |
+
logger.error(f"Proxy error: {str(e)}")
|
| 352 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
|
| 356 |
@app.get("/", response_class=HTMLResponse)
|
| 357 |
async def root():
|
| 358 |
html_content = f"""
|