updated fallback logic

This commit is contained in:
2026-02-10 20:27:12 +08:00
parent f6ad186178
commit 9325a4919a
3 changed files with 27 additions and 3 deletions

View File

@@ -36,11 +36,28 @@ def get_gemini_client():
@limiter.limit(settings.RATE_LIMIT) @limiter.limit(settings.RATE_LIMIT)
async def gemini_chat( async def gemini_chat(
request: Request, request: Request,
chat_data: LLMRequest,
api_key: str = Depends(get_api_key), api_key: str = Depends(get_api_key),
module: Module = Depends(get_current_module), module: Module = Depends(get_current_module),
db: Session = Depends(get_db) 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() client = get_gemini_client()
try: try:

View File

@@ -1,9 +1,11 @@
services: services:
api: api:
build: . build: .
container_name: storyline-ai-gateway container_name: ai-gateway
networks:
- caddy_network
ports: ports:
- "8191:8000" - "8000:8000"
env_file: env_file:
- .env - .env
restart: always restart: always
@@ -11,3 +13,8 @@ services:
- .:/app - .:/app
# Override command for development/auto-reload if needed # Override command for development/auto-reload if needed
command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
networks:
caddy_network:
# Define the network at the bottom
external: true

BIN
server_log.txt Normal file

Binary file not shown.