Spaces:
Running
Running
File size: 4,289 Bytes
9f2df60 3c5b98e 9f2df60 3c5b98e 9f2df60 3c5b98e 9f2df60 a7bed5e 9f2df60 3c5b98e 9f2df60 a7bed5e 9f2df60 a7bed5e 9f2df60 3c5b98e 9f2df60 a7bed5e 9f2df60 | 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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | """
Main entry point for the Executive Education RAG Chatbot.
"""
import argparse
import langsmith
from langsmith import traceable
from src.utils.logging import init_logging, get_logger
from config import AVAILABLE_LANGUAGES
# Initialize logging
def logging_startup():
init_logging()
return get_logger('main_module')
def run_scraper(scrape_type: str) -> None:
"""
Run the scraper to collect program data.
Args:
scrape_type: Whether to ignore timestamps and scrape all pages.
"""
from src.pipeline.pipeline import ImportPipeline
logger = logging_startup()
logger.info("Running scraper...")
ImportPipeline().scrape_website(scrape_all=True if scrape_type == 'full' else False)
logger.info("Scraping completed.")
def run_importer(sources: list[str]) -> None:
"""Run the data import pipeline."""
from src.pipeline.pipeline import ImportPipeline
logger = logging_startup()
logger.info("Running data import pipeline...")
ImportPipeline().import_many_documents(sources)
logger.info("Data processing completed.")
def run_weaviate_command(command: str, backup_id: str = None):
"""Run commands to manipulate the database contents."""
from src.database.weavservice import WeaviateService
logger = logging_startup()
logger.info(f"Running database command {command}")
if command == 'restore' and not backup_id:
logger.error("Backup ID is required to initalize the restore process.")
service = WeaviateService()
if command == 'backup':
service._create_backup()
if command == 'restore':
service._restore_backup(backup_id)
if command == 'delete' or command == 'redo':
service._delete_collections()
if command == 'init' or command == 'redo':
service._create_collections()
if command == 'checkhealth' or command == 'init' or command == 'redo':
service._checkhealth()
def run_application(lang: str = 'en') -> None:
"""Run the chatbot web application."""
from src.apps.chat.app import ChatbotApplication
logger = logging_startup()
logger.info("Starting chatbot web application...")
app = ChatbotApplication(language=lang)
app.run()
def run_dbapp() -> None:
"""Run the database application."""
from src.apps.dbapp.app import DatabaseApplication
logger = logging_startup()
logger.info("Starting database application...")
app = DatabaseApplication()
app.run()
def parse_args():
"""Parse command-line arguments."""
parser = argparse.ArgumentParser(description="University of St. Gallen Executive Education RAG Chatbot")
# Add arguments
parser.add_argument("--scrape", type=str, choices=['simple', 'full'],
help="Scrapes the data from the HSG website and imports it into the database")
parser.add_argument("--imports", nargs="+", help="Runs the data importing pipeline for the provided files")
parser.add_argument("--weaviate", type=str, choices=['init', 'delete', 'redo', 'checkhealth', 'backup', 'restore'],
help="Runs different database actions")
parser.add_argument("--backup-id", type=str, help="Required when calling the --weaviate restore command!")
parser.add_argument("--cli", action="store_true", help="Run the chatbot CLI")
parser.add_argument("--app", type=str, choices=AVAILABLE_LANGUAGES, help="Run the chatbot web application")
parser.add_argument("--dbapp", action="store_true", help="Run the database management application")
return parser.parse_args()
def main():
"""Main entry point for the application."""
args = parse_args()
# Check if any argument is provided
if not any([args.scrape, args.imports, args.weaviate, args.cli, args.app, args.dbapp]):
# If no argument is provided, run the chatbot by default
run_application()
return
# Run the specified components
if args.scrape:
run_scraper(args.scrape)
if args.imports:
run_importer(args.imports)
if args.weaviate:
run_weaviate_command(command=args.weaviate, backup_id=args.backup_id)
if args.app:
run_application(lang=args.app)
if args.dbapp:
run_dbapp()
if __name__ == "__main__":
main()
|