diff --git a/backend/README.md b/backend/README.md index 419bec0..9f4f001 100644 --- a/backend/README.md +++ b/backend/README.md @@ -113,8 +113,8 @@ On model/auth/timeout failure the service returns HTTP 502 with | `GCP_LOCATION` | `us-east1` | Vertex AI region | | `GEMINI_MODEL` | `gemini-2.5-flash` | Model id | | `GEMINI_TIMEOUT_MS` | `30000` | Per-request model timeout (ms) | -| `GEMINI_MAX_OUTPUT_TOKENS` | `700` | Analysis output cap for the single structured call | -| `GEMINI_CHAT_MAX_OUTPUT_TOKENS` | `512` | Result-chat output cap | +| `GEMINI_MAX_OUTPUT_TOKENS` | `4096` | Analysis output cap (shared by gemini-2.5-flash thinking + JSON answer) | +| `GEMINI_CHAT_MAX_OUTPUT_TOKENS` | `2048` | Result-chat output cap (shared by thinking + answer) | | `ENABLE_OPENAPI_DOCS` | `false` | Enables `/docs`, `/redoc`, and `/openapi.json` only for local/dev use | | `CORS_ALLOWED_ORIGINS` | empty | Comma-separated browser origins allowed to call the API; empty disables CORS middleware | | `PORT` | `8080` | Server port (set by Cloud Run) | diff --git a/backend/main.py b/backend/main.py index 0431660..c0a16e0 100644 --- a/backend/main.py +++ b/backend/main.py @@ -33,8 +33,12 @@ GCP_LOCATION = os.getenv("GCP_LOCATION", "us-east1") GEMINI_MODEL = os.getenv("GEMINI_MODEL", "gemini-2.5-flash") REQUEST_TIMEOUT_MS = int(os.getenv("GEMINI_TIMEOUT_MS", "30000")) -FULL_ANALYSIS_MAX_OUTPUT_TOKENS = int(os.getenv("GEMINI_MAX_OUTPUT_TOKENS", "700")) -CHAT_MAX_OUTPUT_TOKENS = int(os.getenv("GEMINI_CHAT_MAX_OUTPUT_TOKENS", "512")) +# ponytail: gemini-2.5-flash "thinking" tokens share this output budget. 700/512 let thinking +# eat the whole cap on complex labels, truncating the JSON to garbage -> 502 model_response_unparseable. +# Raised to comfortably fit thinking + answer for real OCR inputs. If a pathological label still +# truncates, bound thinking with types.ThinkingConfig(thinking_budget=N) on the generate_content calls. +FULL_ANALYSIS_MAX_OUTPUT_TOKENS = int(os.getenv("GEMINI_MAX_OUTPUT_TOKENS", "4096")) +CHAT_MAX_OUTPUT_TOKENS = int(os.getenv("GEMINI_CHAT_MAX_OUTPUT_TOKENS", "2048")) MAX_INGREDIENT_CHARS = 20_000 MAX_CHAT_QUESTION_CHARS = 1_000 MAX_CHAT_HISTORY_MESSAGES = 12