|
|
|
""" |
|
Setup script for Professional RAG Assistant. |
|
""" |
|
|
|
import os |
|
import sys |
|
import subprocess |
|
import urllib.request |
|
from pathlib import Path |
|
|
|
|
|
def run_command(command, description=""): |
|
"""Run a shell command with error handling.""" |
|
print(f"Running: {command}") |
|
if description: |
|
print(f"Description: {description}") |
|
|
|
result = subprocess.run(command, shell=True, capture_output=True, text=True) |
|
|
|
if result.returncode != 0: |
|
print(f"Error running command: {command}") |
|
print(f"Error output: {result.stderr}") |
|
return False |
|
|
|
if result.stdout: |
|
print(result.stdout) |
|
|
|
return True |
|
|
|
|
|
def check_python_version(): |
|
"""Check if Python version is compatible.""" |
|
if sys.version_info < (3, 8): |
|
print("Error: Python 3.8 or higher is required") |
|
return False |
|
|
|
print(f"Python version: {sys.version}") |
|
return True |
|
|
|
|
|
def install_requirements(): |
|
"""Install Python requirements.""" |
|
print("Installing Python dependencies...") |
|
|
|
if not run_command("pip install -r requirements.txt", "Installing main dependencies"): |
|
return False |
|
|
|
|
|
if "--dev" in sys.argv: |
|
if not run_command("pip install -r requirements-dev.txt", "Installing dev dependencies"): |
|
return False |
|
|
|
return True |
|
|
|
|
|
def create_directories(): |
|
"""Create necessary directories.""" |
|
directories = [ |
|
"logs", |
|
"cache", |
|
"static/uploads", |
|
"data", |
|
"models" |
|
] |
|
|
|
for directory in directories: |
|
Path(directory).mkdir(parents=True, exist_ok=True) |
|
print(f"Created directory: {directory}") |
|
|
|
|
|
def download_sample_documents(): |
|
"""Download sample documents for testing.""" |
|
if "--skip-samples" in sys.argv: |
|
return True |
|
|
|
print("Downloading sample documents...") |
|
|
|
sample_dir = Path("examples/sample_docs") |
|
sample_dir.mkdir(parents=True, exist_ok=True) |
|
|
|
|
|
sample_text = """ |
|
Professional RAG Assistant - Sample Document |
|
|
|
This is a sample document to demonstrate the capabilities of the Professional RAG Assistant. |
|
|
|
Key Features: |
|
- Multi-format document processing (PDF, DOCX, TXT) |
|
- Advanced hybrid search combining vector similarity and keyword search |
|
- Cross-encoder re-ranking for improved relevance |
|
- Comprehensive caching system for performance |
|
- Professional Gradio interface with analytics |
|
|
|
The system uses sentence-transformers for creating document embeddings and BM25 for keyword search. |
|
Results are re-ranked using cross-encoder models to provide the most relevant answers to user queries. |
|
|
|
This sample document can be used to test the upload and search functionality of the system. |
|
""" |
|
|
|
with open(sample_dir / "sample_document.txt", "w") as f: |
|
f.write(sample_text) |
|
|
|
print(f"Created sample document: {sample_dir / 'sample_document.txt'}") |
|
return True |
|
|
|
|
|
def setup_configuration(): |
|
"""Setup configuration files.""" |
|
print("Setting up configuration...") |
|
|
|
|
|
if not Path("config.yaml").exists(): |
|
print("Warning: config.yaml not found. Using default configuration.") |
|
|
|
if not Path("config-local.yaml").exists(): |
|
print("Info: config-local.yaml not found. This is optional for local development.") |
|
|
|
return True |
|
|
|
|
|
def run_tests(): |
|
"""Run test suite if requested.""" |
|
if "--test" not in sys.argv: |
|
return True |
|
|
|
print("Running test suite...") |
|
|
|
if not run_command("python -m pytest tests/ -v", "Running tests"): |
|
print("Warning: Some tests failed. The application should still work.") |
|
return True |
|
|
|
return True |
|
|
|
|
|
def main(): |
|
"""Main setup function.""" |
|
print("Setting up Professional RAG Assistant...") |
|
print("=" * 50) |
|
|
|
|
|
if not check_python_version(): |
|
sys.exit(1) |
|
|
|
|
|
create_directories() |
|
|
|
|
|
if not install_requirements(): |
|
print("Failed to install requirements") |
|
sys.exit(1) |
|
|
|
|
|
if not setup_configuration(): |
|
print("Failed to setup configuration") |
|
sys.exit(1) |
|
|
|
|
|
if not download_sample_documents(): |
|
print("Failed to download sample documents") |
|
sys.exit(1) |
|
|
|
|
|
if not run_tests(): |
|
print("Tests failed") |
|
sys.exit(1) |
|
|
|
print("\n" + "=" * 50) |
|
print("Setup completed successfully!") |
|
print("\nTo start the application:") |
|
print(" python app.py") |
|
print("\nTo start in debug mode:") |
|
print(" python app.py --debug") |
|
print("\nTo use local configuration:") |
|
print(" python app.py --config config-local.yaml") |
|
print("\nFor more options:") |
|
print(" python app.py --help") |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |