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..03cad8c --- /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 --timeout 30000 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3354256 --- /dev/null +++ b/docker-compose.yml @@ -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..55ddbb0 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(): @@ -16,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()) @@ -44,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())