forked from GreyDGL/LOA_Firewall
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
101 lines (85 loc) · 2.6 KB
/
run.py
File metadata and controls
101 lines (85 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# run.py
# !/usr/bin/env python3
"""
LLM Firewall - Main entry point
This script runs the LLM Firewall API server with command-line options.
"""
import os
import sys
import argparse
import logging
from src.api.api import FirewallAPI
def main():
"""Main entry point for the LLM Firewall"""
parser = argparse.ArgumentParser(description="LLM Firewall - Content safety filtering API")
# Configuration options
parser.add_argument(
"--config",
help="Path to configuration file",
default=os.environ.get("LLM_FIREWALL_CONFIG", "config/config.json")
)
# Server options
parser.add_argument(
"--host",
help="API server host",
default=os.environ.get("LLM_FIREWALL_HOST", "0.0.0.0")
)
parser.add_argument(
"--port",
help="API server port",
type=int,
default=int(os.environ.get("LLM_FIREWALL_PORT", "5001"))
)
parser.add_argument(
"--debug",
help="Enable debug mode",
action="store_true",
default=os.environ.get("LLM_FIREWALL_DEBUG", "false").lower() == "true"
)
# Logging options
parser.add_argument(
"--log-level",
help="Logging level",
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
default=os.environ.get("LLM_FIREWALL_LOG_LEVEL", "INFO")
)
parser.add_argument(
"--log-file",
help="Path to log file",
default=os.environ.get("LLM_FIREWALL_LOG_FILE", "logs/firewall.log")
)
# Parse arguments
args = parser.parse_args()
# Configure logging
log_dir = os.path.dirname(args.log_file)
if log_dir and not os.path.exists(log_dir):
os.makedirs(log_dir)
logging.basicConfig(
level=getattr(logging, args.log_level),
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(args.log_file),
logging.StreamHandler()
]
)
# Create config dict from command-line options
config_override = {
"api": {
"host": args.host,
"port": args.port,
"debug": args.debug,
"log_level": args.log_level
}
}
# Initialize and run API
try:
api = FirewallAPI(args.config)
# Apply command-line overrides
api.config["api"].update(config_override["api"])
logging.info(f"Starting LLM Firewall API on {args.host}:{args.port}")
api.run()
except Exception as e:
logging.critical(f"Failed to start API server: {str(e)}", exc_info=True)
sys.exit(1)
if __name__ == "__main__":
main()