Philips656 commited on
Commit
39f4cda
·
verified ·
1 Parent(s): acda684

Update shield.py

Browse files
Files changed (1) hide show
  1. shield.py +10 -10
shield.py CHANGED
@@ -3,18 +3,18 @@ from flask import Flask, request, Response
3
 
4
  app = Flask(__name__)
5
 
6
- # YOUR OPENAI PROJECT KEY (Already inserted)
7
  OPENAI_KEY = "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"
8
 
9
- # TiDB Credentials from Environment Variables
10
  TIDB_CONFIG = {
11
- "host": os.getenv("TIDB_HOST"),
12
  "port": 4000,
13
- "user": os.getenv("TIDB_USER"),
14
- "password": os.getenv("TIDB_PASSWORD"),
15
- "database": os.getenv("TIDB_DB_NAME", "test"),
16
  "ssl_verify_cert": True,
17
- "ssl_ca": "/etc/ssl/certs/ca-certificates.crt" # Standard for Debian/HF
18
  }
19
 
20
  def log_to_tidb(user, prompt):
@@ -48,12 +48,12 @@ def protect_and_proxy():
48
  log_to_tidb(user_auth, text_to_check)
49
  return {"error": {"message": "Policy Violation: CSAM is strictly prohibited.", "type": "safety_error"}}, 403
50
 
51
- # 3. Pass through to NewAPI running on internal port 3000
52
  resp = requests.post("http://127.0.0.1:3000/v1/chat/completions",
53
  json=data, headers=dict(request.headers))
54
  return Response(resp.content, resp.status_code, resp.headers.items())
55
 
56
- # Proxy all other routes (login, admin, etc.) to the real API
57
  @app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE'])
58
  def catch_all(path):
59
  resp = requests.request(method=request.method, url=f"http://127.0.0.1:3000/{path}",
@@ -62,4 +62,4 @@ def catch_all(path):
62
  return Response(resp.content, resp.status_code, resp.headers.items())
63
 
64
  if __name__ == '__main__':
65
- app.run(host='0.0.0.0', port=7860) # HF required port
 
3
 
4
  app = Flask(__name__)
5
 
6
+ # YOUR OPENAI PROJECT KEY
7
  OPENAI_KEY = "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"
8
 
9
+ # TIDB CONNECTION DATA
10
  TIDB_CONFIG = {
11
+ "host": "gateway01.eu-central-1.prod.aws.tidbcloud.com",
12
  "port": 4000,
13
+ "user": "uiSKPXCQ9Gzb4co.root",
14
+ "password": "Bxg8rpU27gyH60E0",
15
+ "database": "test",
16
  "ssl_verify_cert": True,
17
+ "ssl_ca": "/etc/ssl/certs/ca-certificates.crt"
18
  }
19
 
20
  def log_to_tidb(user, prompt):
 
48
  log_to_tidb(user_auth, text_to_check)
49
  return {"error": {"message": "Policy Violation: CSAM is strictly prohibited.", "type": "safety_error"}}, 403
50
 
51
+ # 3. Safe? Forward to NewAPI on internal port 3000
52
  resp = requests.post("http://127.0.0.1:3000/v1/chat/completions",
53
  json=data, headers=dict(request.headers))
54
  return Response(resp.content, resp.status_code, resp.headers.items())
55
 
56
+ # Proxy all other dashboard/admin traffic
57
  @app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'DELETE'])
58
  def catch_all(path):
59
  resp = requests.request(method=request.method, url=f"http://127.0.0.1:3000/{path}",
 
62
  return Response(resp.content, resp.status_code, resp.headers.items())
63
 
64
  if __name__ == '__main__':
65
+ app.run(host='0.0.0.0', port=7860)