From 9325a4919a534f4afa72147d0fb336fb434c4f51 Mon Sep 17 00:00:00 2001 From: Paulo Reyes Date: Tue, 10 Feb 2026 20:27:12 +0800 Subject: [PATCH] updated fallback logic --- app/api/endpoints/gemini.py | 19 ++++++++++++++++++- docker-compose.yml | 11 +++++++++-- server_log.txt | Bin 0 -> 2042 bytes 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 server_log.txt diff --git a/app/api/endpoints/gemini.py b/app/api/endpoints/gemini.py index e0dfccb..ed04494 100644 --- a/app/api/endpoints/gemini.py +++ b/app/api/endpoints/gemini.py @@ -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: diff --git a/docker-compose.yml b/docker-compose.yml index 4b67361..6797fe9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,11 @@ services: api: build: . - container_name: storyline-ai-gateway + container_name: ai-gateway + networks: + - caddy_network ports: - - "8191:8000" + - "8000:8000" env_file: - .env restart: always @@ -11,3 +13,8 @@ services: - .:/app # Override command for development/auto-reload if needed command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload + +networks: + caddy_network: + # Define the network at the bottom + external: true diff --git a/server_log.txt b/server_log.txt new file mode 100644 index 0000000000000000000000000000000000000000..60358902e124c4c1fe29a2c5b87f45b0aaeeebee GIT binary patch literal 2042 zcmeH{K~LL25QX2l692)c3Pj~LP#VYq2}K|wA)vHX4+%n%V-iac8^@q>;ip5t*<}@1 zazeNv6|HRV&d$Dh^LEBhkFolSb*EGl-hKU0qEeX(RhqIcbkA(8oc$GjP^1pep^kN+ z6E}}o+xW%#jMF*iC#=o8)GhM~_K8N=48`w^L9IaV=rg0G4YlF%<@sr0-)3dQ`>*O0 zv=mNLEM5K7nU1v1ECMIzeM78_`I?Ko$1Kv7i=2YiVwI4`02EspyLD{K=5PLiUmA8Sz`wA?V{RTUf-DwT;+s(_Sp|P zM#L>aD9LY#-D_fcX72X8>;)F~y=DxEH-tkt>9OqH)JK+^RjJ*OMKHg@S*%B`std=! z^6}l!)26=ZD;=|q4zIzjS8WsS)(e=w;blD+`rE3geC9lWXW?{A@Cv#|a1Qz1vLDao zyEo^&<@Ya!b#{)<7A*xmU4Yu8?#n9dpzk7W{|_BDwZ(t>U5Orl@;3cu9XG$<-gZs= E1-QXCNB{r; literal 0 HcmV?d00001