updated fallback logic
This commit is contained in:
@@ -36,11 +36,28 @@ def get_gemini_client():
|
||||
@limiter.limit(settings.RATE_LIMIT)
|
||||
async def gemini_chat(
|
||||
request: Request,
|
||||
chat_data: LLMRequest,
|
||||
api_key: str = Depends(get_api_key),
|
||||
module: Module = Depends(get_current_module),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
# Handle text/plain as JSON (fallback for CORS "Simple Requests")
|
||||
content_type = request.headers.get("Content-Type", "")
|
||||
if "text/plain" in content_type:
|
||||
try:
|
||||
body = await request.body()
|
||||
import json
|
||||
data = json.loads(body)
|
||||
chat_data = LLMRequest(**data)
|
||||
except Exception as e:
|
||||
return {"status": "error", "detail": f"Failed to parse text/plain as JSON: {str(e)}"}
|
||||
else:
|
||||
# Standard JSON parsing
|
||||
try:
|
||||
data = await request.json()
|
||||
chat_data = LLMRequest(**data)
|
||||
except Exception as e:
|
||||
return {"status": "error", "detail": f"Invalid JSON: {str(e)}"}
|
||||
|
||||
client = get_gemini_client()
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user