Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +27 -21
Dockerfile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
FROM ollama/ollama:latest
|
| 2 |
|
| 3 |
-
# Install Python and dependencies
|
| 4 |
RUN apt-get update && apt-get install -y python3 python3-pip && \
|
| 5 |
pip3 install flask flask-cors requests
|
| 6 |
|
|
@@ -11,24 +11,30 @@ ENV HOME=/home/ollama
|
|
| 11 |
|
| 12 |
RUN mkdir -p /home/ollama/.ollama && chmod 777 /home/ollama/.ollama
|
| 13 |
|
| 14 |
-
# Create the Security Proxy
|
| 15 |
-
RUN
|
| 16 |
-
import
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
CMD ["/bin/sh", "-c", "ollama serve & sleep 15 && ollama pull phi3 && python3 /guard.py"]
|
|
|
|
| 1 |
FROM ollama/ollama:latest
|
| 2 |
|
| 3 |
+
# Install Python and Gatekeeper dependencies
|
| 4 |
RUN apt-get update && apt-get install -y python3 python3-pip && \
|
| 5 |
pip3 install flask flask-cors requests
|
| 6 |
|
|
|
|
| 11 |
|
| 12 |
RUN mkdir -p /home/ollama/.ollama && chmod 777 /home/ollama/.ollama
|
| 13 |
|
| 14 |
+
# Create the Security Proxy using a Here-Doc (Fixes Exit Code 1)
|
| 15 |
+
RUN cat <<EOF > /guard.py
|
| 16 |
+
from flask import Flask, request, Response
|
| 17 |
+
import requests
|
| 18 |
+
from flask_cors import CORS
|
| 19 |
+
|
| 20 |
+
app = Flask(__name__)
|
| 21 |
+
CORS(app)
|
| 22 |
+
|
| 23 |
+
@app.route("/api/generate", methods=["POST"])
|
| 24 |
+
def proxy():
|
| 25 |
+
key = request.headers.get("x-api-key", "")
|
| 26 |
+
# Gatekeeper: Any key starting with sk- and longer than 10 chars is valid
|
| 27 |
+
if not key.startswith("sk-") or len(key) < 10:
|
| 28 |
+
return {"error": "Invalid API Key"}, 401
|
| 29 |
+
try:
|
| 30 |
+
resp = requests.post("http://127.0.0.1:11434/api/generate", json=request.json)
|
| 31 |
+
return Response(resp.content, resp.status_code, resp.headers.items())
|
| 32 |
+
except:
|
| 33 |
+
return {"error": "Ollama server is still starting..."}, 503
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
app.run(host="0.0.0.0", port=7860)
|
| 37 |
+
EOF
|
| 38 |
+
|
| 39 |
+
# Start Ollama, pull the model, then start the Python Guard
|
| 40 |
CMD ["/bin/sh", "-c", "ollama serve & sleep 15 && ollama pull phi3 && python3 /guard.py"]
|