Spaces:
Runtime error
Runtime error
Update shield.py
Browse files
shield.py
CHANGED
|
@@ -3,18 +3,18 @@ from flask import Flask, request, Response
|
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
| 6 |
-
# YOUR OPENAI PROJECT KEY
|
| 7 |
OPENAI_KEY = "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"
|
| 8 |
|
| 9 |
-
#
|
| 10 |
TIDB_CONFIG = {
|
| 11 |
-
"host":
|
| 12 |
"port": 4000,
|
| 13 |
-
"user":
|
| 14 |
-
"password":
|
| 15 |
-
"database":
|
| 16 |
"ssl_verify_cert": True,
|
| 17 |
-
"ssl_ca": "/etc/ssl/certs/ca-certificates.crt"
|
| 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.
|
| 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
|
| 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)
|
|
|
|
| 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)
|