guydffdsdsfd commited on
Commit
7db7a01
·
verified ·
1 Parent(s): 2d5774a

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -9
Dockerfile CHANGED
@@ -1,10 +1,8 @@
1
  FROM ollama/ollama:latest
2
 
3
- # Install Python & Dependencies
4
  RUN apt-get update && apt-get install -y python3 python3-pip && \
5
  pip3 install flask flask-cors requests --break-system-packages
6
 
7
- # Set up environment variables
8
  ENV OLLAMA_HOST=127.0.0.1:11434
9
  ENV HOME=/home/ollama
10
  RUN mkdir -p /home/ollama/.ollama && chmod -R 777 /home/ollama
@@ -16,7 +14,7 @@ import requests
16
  from flask_cors import CORS
17
 
18
  app = Flask(__name__)
19
- # Enable CORS for browser direct access
20
  CORS(app, resources={r"/*": {"origins": "*", "allow_headers": ["Content-Type", "x-api-key"]}})
21
 
22
  UNLIMITED_KEY = "sk-ess4l0ri37"
@@ -31,13 +29,35 @@ def proxy():
31
  return jsonify({"error": "Unauthorized"}), 401
32
 
33
  try:
34
- # Proxy to local Ollama
 
 
 
 
 
 
 
 
 
 
 
35
  resp = requests.post(
36
- "http://127.0.0.1:11434/api/generate",
37
- json=request.json,
38
- timeout=300
39
  )
40
- return Response(resp.content, status=resp.status_code, content_type=resp.headers.get('Content-Type'))
 
 
 
 
 
 
 
 
 
 
 
41
  except Exception as e:
42
  return jsonify({"error": str(e)}), 500
43
 
@@ -45,7 +65,7 @@ if __name__ == "__main__":
45
  app.run(host="0.0.0.0", port=7860)
46
  EOF
47
 
48
- # --- Startup Script ---
49
  RUN cat <<'EOF' > /start.sh
50
  #!/bin/bash
51
  ollama serve &
 
1
  FROM ollama/ollama:latest
2
 
 
3
  RUN apt-get update && apt-get install -y python3 python3-pip && \
4
  pip3 install flask flask-cors requests --break-system-packages
5
 
 
6
  ENV OLLAMA_HOST=127.0.0.1:11434
7
  ENV HOME=/home/ollama
8
  RUN mkdir -p /home/ollama/.ollama && chmod -R 777 /home/ollama
 
14
  from flask_cors import CORS
15
 
16
  app = Flask(__name__)
17
+ # Enable CORS for direct browser access
18
  CORS(app, resources={r"/*": {"origins": "*", "allow_headers": ["Content-Type", "x-api-key"]}})
19
 
20
  UNLIMITED_KEY = "sk-ess4l0ri37"
 
29
  return jsonify({"error": "Unauthorized"}), 401
30
 
31
  try:
32
+ data = request.json
33
+ # Convert your 'prompt' into a 'messages' array for the /api/chat endpoint
34
+ ollama_payload = {
35
+ "model": data.get("model", "dolphin3:8b"),
36
+ "messages": [{"role": "user", "content": data.get("prompt", "")}],
37
+ "stream": False,
38
+ "options": {
39
+ "temperature": data.get("temperature", 0.7)
40
+ }
41
+ }
42
+
43
+ # TALKING TO /api/chat INSTEAD OF /api/generate
44
  resp = requests.post(
45
+ "http://127.0.0.1:11434/api/chat",
46
+ json=ollama_payload,
47
+ timeout=180
48
  )
49
+
50
+ if resp.status_code != 200:
51
+ return jsonify({"error": "Ollama Error", "details": resp.text}), resp.status_code
52
+
53
+ ollama_res = resp.json()
54
+
55
+ # Flatten the response back to the format your frontend expects
56
+ return jsonify({
57
+ "response": ollama_res.get("message", {}).get("content", ""),
58
+ "done": True
59
+ })
60
+
61
  except Exception as e:
62
  return jsonify({"error": str(e)}), 500
63
 
 
65
  app.run(host="0.0.0.0", port=7860)
66
  EOF
67
 
68
+ # --- start.sh stays the same ---
69
  RUN cat <<'EOF' > /start.sh
70
  #!/bin/bash
71
  ollama serve &