-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_server.py
More file actions
43 lines (34 loc) · 1.6 KB
/
run_server.py
File metadata and controls
43 lines (34 loc) · 1.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
#!/usr/bin/env python3
"""Simple launcher for the UnForkRAG server.
Usage:
python run_server.py --host 127.0.0.1 --port 8000 --debug
This script invokes the package module (`-m unforkrag.unfork_server`) so
that the server runs with the package's import context. It is cross-platform
and works well in a virtual environment.
"""
import argparse
import subprocess
import sys
import os
def main():
parser = argparse.ArgumentParser(description='Run UnForkRAG server (launcher).')
parser.add_argument('--host', default='127.0.0.1', help='Host to bind to')
parser.add_argument('--port', type=int, default=8000, help='Port to listen on')
parser.add_argument('--debug', action='store_true', help='Enable Flask debug mode')
args = parser.parse_args()
# Try to execute the package module when possible, otherwise fall back
# to running the server file directly. Running from inside the package
# directory may make `-m unforkrag.unfork_server` fail with
# ModuleNotFoundError; executing the file directly is more robust for
# the local development launcher.
server_path = os.path.join(os.path.dirname(__file__), 'unfork_server.py')
if os.path.exists(server_path):
cmd = [sys.executable, server_path, '--host', args.host, '--port', str(args.port)]
else:
cmd = [sys.executable, '-m', 'unforkrag.unfork_server', '--host', args.host, '--port', str(args.port)]
if args.debug:
cmd.append('--debug')
print(f"Starting UnForkRAG server: {' '.join(cmd)}")
subprocess.run(cmd)
if __name__ == '__main__':
main()