-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·120 lines (98 loc) · 3.46 KB
/
setup.py
File metadata and controls
executable file
·120 lines (98 loc) · 3.46 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python3
"""
Setup script for the RAG Document Q&A system.
Written by DJ Leamen (2025-2026)
"""
import os
import sys
import subprocess
from pathlib import Path
def run_command(command, description):
'''
Run a shell command with error handling.
:param command: Command to run
:param description: Description of the command
:return: True if command succeeded, False otherwise
'''
print(f"{description}...")
try:
subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
return True
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
print(f"Output: {e.stdout}")
print(f"Error: {e.stderr}")
return False
def check_python_version():
'''
Check if the Python version is 3.8 or higher.
:return: True if version is valid, False otherwise
'''
version = sys.version_info
if version.major < 3 or (version.major == 3 and version.minor < 8):
print("Python 3.8 or higher is required")
return False
print(f"Python {version.major}.{version.minor}.{version.micro} detected")
return True
def setup_environment():
'''
Set up the development environment for the RAG Document Q&A System.
:return: True if setup succeeded, False otherwise
'''
print("Setting up RAG Document Q&A System...")
# Check Python version
if not check_python_version():
return False
# Create virtual environment if it doesn't exist
if not Path("venv").exists():
if not run_command(f"{sys.executable} -m venv venv", "Creating virtual environment"):
return False
else:
print("Virtual environment already exists")
# Determine activation command based on OS
if os.name == 'nt': # Windows
pip_cmd = "venv\\Scripts\\pip"
else: # Unix/Linux/macOS
pip_cmd = "venv/bin/pip"
# Install requirements
if not run_command(f"{pip_cmd} install -r requirements.txt", "Installing dependencies"):
return False
# Create necessary directories
directories = ["documents", "indexes", "logs", "temp", "backups", "media", "staticfiles"]
for directory in directories:
Path(directory).mkdir(exist_ok=True)
print("Created necessary directories")
# Copy .env.example to .env if it doesn't exist
env_file = Path(".env")
if not env_file.exists():
if Path(".env.example").exists():
run_command("cp .env.example .env", "Creating .env file from template")
print("Please edit .env with your API keys")
else:
print(".env.example file not found")
return False
else:
print(".env file already exists")
print("\nSetup completed successfully!")
print("\nQuick start guide:")
print("1. Edit .env file with your OpenAI API key")
print("2. Run: python main.py start")
print("3. Open: http://localhost:8000")
return True
def main():
'''
Main entry point for the RAG Document Q&A system.
Parses command-line arguments and dispatches to appropriate
functionality: quick start, Django app, CLI, or setup.
'''
try:
success = setup_environment()
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\nSetup interrupted by user")
sys.exit(1)
except Exception as unexpected_error:
print(f"Unexpected error: {unexpected_error}")
sys.exit(1)
if __name__ == "__main__":
main()