Source code for smarter.apps.account.management.commands.initialize_platform

import logging

from django.core.management import call_command

from smarter.common.conf import smarter_settings
from smarter.common.const import SMARTER_ACCOUNT_NUMBER, SmarterEnvironments
from smarter.lib.django.management.base import SmarterCommand

logger = logging.getLogger(__name__)


[docs] class Command(SmarterCommand): """Django manage.py initialize_platform command."""
[docs] def add_arguments(self, parser): """Add arguments to the command.""" parser.add_argument( "--username", type=str, help="The username for the superuser associated with this platform. If not provided, the default 'admin' will be used.", ) parser.add_argument( "--email", type=str, help="The email address of the user to associate with this Secret. If not provided, a default email will be assigned.", ) parser.add_argument( "--password", type=str, help="The value to encrypt and persist. If not provided and you are running locally, the default 'smarter' will be used.", )
[docs] def handle(self, *args, **options): """ Initialize the Smarter platform. Creates the minimal resources necessary to start using Smarter. 1. Create an admin user with the provided username, email, and password. 2. Create example accounts and users. 4. Verify DNS configuration. 5. Load example projects from GitHub. 6. Add plugin examples. 7. Deploy example llm_clients. 8. Initialize providers. 9. Create StackAcademy SQL and API llm_clients. 10. Apply manifests and update secrets for database connections. """ self.handle_begin() username = options.get("username") if not username: username = "admin" self.stdout.write(self.style.WARNING(f"No username provided, using the default value: {username}")) email = options.get("email") if not email: email = f"{username}@{smarter_settings.root_domain}" self.stdout.write( self.style.WARNING(f"No email provided, assigning a default email for this Secret: {email}") ) password = options.get("password") if not password: if smarter_settings.environment == SmarterEnvironments.LOCAL: password = "smarter" self.stdout.write(self.style.WARNING(f"No password provided, using the default value: {password}")) else: self.stdout.write( self.style.ERROR("An administrator password is required when not running in LOCAL environment.") ) return # create Smarter Account and admin User. # --------------------------------------------------------------------- call_command("create_smarter_admin", username=username, password=password, email=email) call_command( "create_user", account_number=SMARTER_ACCOUNT_NUMBER, username="staff_user", email=f"staff@{smarter_settings.root_domain}", password=password, first_name="Staff", last_name="User", admin=True, ) call_command( "create_user", account_number=SMARTER_ACCOUNT_NUMBER, username="customer_user", email=f"customer@{smarter_settings.root_domain}", password=password, first_name="Customer", last_name="User", ) # Initialize Smarter platform components. # --------------------------------------------------------------------- try: call_command("initialize_waffle") # Initialize builtin Waffle switches for feature flagging # pylint: disable=broad-except except Exception as e: logger.error("Failed to initialize Waffle switches: %s", e) try: call_command("initialize_providers") # Initialize builtin LLM providers: openai, metaai, googleia # pylint: disable=broad-except except Exception as e: logger.error("Failed to initialize providers: %s", e) try: call_command("initialize_vectorstore_providers") # Initialize builtin vectorstore providers: pinecone # pylint: disable=broad-except except Exception as e: logger.error("Failed to initialize vectorstore providers: %s", e) try: call_command( "verify_dns_configuration" ) # if AWS is configured then Verify Route53 Hosted Zones and DNS records # pylint: disable=broad-except except Exception as e: logger.error("Failed to verify DNS configuration: %s", e) self.handle_completed_success()