From 464e4ce7dac3c93194a08a1cb410e379978230f0 Mon Sep 17 00:00:00 2001 From: zlc1004 Date: Sun, 27 Jul 2025 15:40:17 +0800 Subject: [PATCH 1/5] feat(main.py): update OpenWebUI base URL to use environment variable Refactor the code to use an environment variable for the OpenWebUI base URL instead of a hardcoded value. This allows for greater flexibility and ease of configuration. --- .dockerignore | 34 ++++++++++++++++++++++++++++++++++ Dockerfile | 21 +++++++++++++++++++++ compose.yaml | 8 ++++++++ main.py | 3 ++- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..03a268b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,34 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.DS_Store +**/__pycache__ +**/.venv +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose.y*ml +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..94ef128 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +ARG PYTHON_VERSION=3.10.14 +FROM python:${PYTHON_VERSION}-slim as base +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 +WORKDIR /app +ARG UID=10001 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + appuser +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=bind,source=requirements.txt,target=requirements.txt \ + python -m pip install -r requirements.txt +USER appuser +COPY . . +EXPOSE 5001 +CMD gunicorn 'main:app' --bind=0.0.0.0:5001 \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..d6650a3 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,8 @@ +services: + openwebui-proxy: + build: + context: . + ports: + - 5001:5001 + environment: + - OPENWEBUI_BASE_URL="host.docker.internal:5000" \ No newline at end of file diff --git a/main.py b/main.py index 280c172..023853b 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,11 @@ from flask import Flask, request, jsonify import requests +import os app = Flask(__name__) # Configuration for OpenWebUI -OPENWEBUI_BASE_URL = "YOUR_OPENWEBUI_URL" +OPENWEBUI_BASE_URL = os.getenv("OPENWEBUI_BASE_URL", "host.docker.internal:5000") @app.route('/v1/models', methods=['GET']) def get_models(): From ecd25bd253b39b10e1d4f51419c46320568e5163 Mon Sep 17 00:00:00 2001 From: zlc1004 Date: Sun, 27 Jul 2025 15:56:32 +0800 Subject: [PATCH 2/5] fix small error --- compose.yaml => docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename compose.yaml => docker-compose.yml (65%) diff --git a/compose.yaml b/docker-compose.yml similarity index 65% rename from compose.yaml rename to docker-compose.yml index d6650a3..3354256 100644 --- a/compose.yaml +++ b/docker-compose.yml @@ -5,4 +5,4 @@ services: ports: - 5001:5001 environment: - - OPENWEBUI_BASE_URL="host.docker.internal:5000" \ No newline at end of file + - OPENWEBUI_BASE_URL=host.docker.internal:5000 \ No newline at end of file From 5ecde7918e8953225f96cc397e27429bc20f1318 Mon Sep 17 00:00:00 2001 From: zlc1004 Date: Thu, 25 Sep 2025 18:13:30 -0700 Subject: [PATCH 3/5] fix(main.py): increase timeout for chat completions API request --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 023853b..3462123 100644 --- a/main.py +++ b/main.py @@ -45,7 +45,7 @@ def chat_completions(): } try: - response = requests.post(f"{OPENWEBUI_BASE_URL}/api/chat/completions", headers=headers, json=openwebui_payload, timeout=120) # Increased to 120 seconds + response = requests.post(f"{OPENWEBUI_BASE_URL}/api/chat/completions", headers=headers, json=openwebui_payload, timeout=1200) # Increased to 120 seconds if response.status_code == 200: return jsonify(response.json()) From aeb0aa7afd1bcd75027157c27ba9da6d5e98e9c6 Mon Sep 17 00:00:00 2001 From: zlc1004 Date: Thu, 25 Sep 2025 18:24:22 -0700 Subject: [PATCH 4/5] fix(main.py): increase timeout for models API request to 1200 seconds Increase the timeout for requests to the `/api/models` endpoint from 30 seconds to 1200 seconds to ensure that large model requests have enough time to complete. --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 3462123..55ddbb0 100644 --- a/main.py +++ b/main.py @@ -17,7 +17,7 @@ def get_models(): } try: - response = requests.get(f"{OPENWEBUI_BASE_URL}/api/models", headers=headers, timeout=30) + response = requests.get(f"{OPENWEBUI_BASE_URL}/api/models", headers=headers, timeout=1200) if response.status_code == 200: return jsonify(response.json()) From 370511845d6fe0034827e92348af3bcbcbe06724 Mon Sep 17 00:00:00 2001 From: zlc1004 Date: Thu, 25 Sep 2025 18:25:23 -0700 Subject: [PATCH 5/5] fix(Dockerfile): increase gunicorn timeout to 30000 seconds Increase the timeout for gunicorn command to ensure that large requests have enough time to complete. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 94ef128..03cad8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,4 +18,4 @@ RUN --mount=type=cache,target=/root/.cache/pip \ USER appuser COPY . . EXPOSE 5001 -CMD gunicorn 'main:app' --bind=0.0.0.0:5001 \ No newline at end of file +CMD gunicorn 'main:app' --bind=0.0.0.0:5001 --timeout 30000 \ No newline at end of file