From 20ce3d0c78bb90c15e6d76e23d6e4530320ea8e1 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Tue, 14 Nov 2023 12:21:26 -0800 Subject: [PATCH] Update default docker compose configuration with Khoj local mode --- docker-compose.yml | 16 +++++++-- src/khoj/utils/initialization.py | 62 +++++++++++++++++++------------- 2 files changed, 51 insertions(+), 27 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c75aa4fc..c09d4310 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,15 @@ services: POSTGRES_DB: postgres volumes: - khoj_db:/var/lib/postgresql/data/ + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 30s + timeout: 10s + retries: 5 server: + depends_on: + database: + condition: service_healthy # Use the following line to use the latest version of khoj. Otherwise, it will build from source. image: ghcr.io/khoj-ai/khoj:latest # Uncomment the following line to build from source. This will take a few minutes. Comment the next two lines out if you want to use the offiicial image. @@ -47,9 +55,11 @@ services: - POSTGRES_PASSWORD=postgres - POSTGRES_HOST=database - POSTGRES_PORT=5432 - - GOOGLE_CLIENT_SECRET=bar - - GOOGLE_CLIENT_ID=foo - command: --host="0.0.0.0" --port=42110 -vv + - KHOJ_DJANGO_SECRET_KEY=secret + - KHOJ_DEBUG=True + - ADMIN_EMAIL=username@example.com + - ADMIN_PASSWORD=password + command: --host="0.0.0.0" --port=42110 -vv --anonymous-mode volumes: diff --git a/src/khoj/utils/initialization.py b/src/khoj/utils/initialization.py index af9a0a87..72cd3fe5 100644 --- a/src/khoj/utils/initialization.py +++ b/src/khoj/utils/initialization.py @@ -1,4 +1,5 @@ import logging +import os from database.models import ( KhojUser, @@ -17,37 +18,50 @@ logger = logging.getLogger(__name__) def initialization(): def _create_admin_user(): - logger.info("👩‍✈️ Setting up admin user") - email_addr = input("Email Address: ") - password = input("Password: ") + logger.info( + "👩‍✈️ Setting up admin user. These credentials will allow you to configure your server at /django/admin." + ) + email_addr = os.getenv("ADMIN_EMAIL") or input("Email: ") + password = os.getenv("ADMIN_PASSWORD") or input("Password: ") admin_user = KhojUser.objects.create_superuser(email=email_addr, username=email_addr, password=password) logger.info(f"👩‍✈️ Created admin user: {admin_user.email}") def _create_chat_configuration(): logger.info( - "🗣️ Configure chat models available to your server. You can always update these at /django/admin using the credentials of your admin account" + "🗣️ Configure chat models available to your server. You can always update these at /django/admin using the credentials of your admin account" ) - use_offline_model = input("Use offline chat model? (y/n): ") - if use_offline_model == "y": - logger.info("🗣️ Setting up offline chat model") - OfflineChatProcessorConversationConfig.objects.create(enabled=True) + try: + # Some environments don't support interactive input. We catch the exception and return if that's the case. The admin can still configure their settings from the admin page. + input() + except EOFError: + return - offline_chat_model = input( - f"Enter the name of the offline chat model you want to use, based on the models in HuggingFace (press enter to use the default: {default_offline_chat_model}): " - ) - if offline_chat_model == "": - ChatModelOptions.objects.create( - chat_model=default_offline_chat_model, model_type=ChatModelOptions.ModelType.OFFLINE - ) - else: - max_tokens = input("Enter the maximum number of tokens to use for the offline chat model:") - tokenizer = input("Enter the tokenizer to use for the offline chat model:") - ChatModelOptions.objects.create( - chat_model=offline_chat_model, - model_type=ChatModelOptions.ModelType.OFFLINE, - max_prompt_size=max_tokens, - tokenizer=tokenizer, + try: + import gpt4all + + use_offline_model = input("Use offline chat model? (y/n): ") + if use_offline_model == "y": + logger.info("🗣️ Setting up offline chat model") + OfflineChatProcessorConversationConfig.objects.create(enabled=True) + + offline_chat_model = input( + f"Enter the name of the offline chat model you want to use, based on the models in HuggingFace (press enter to use the default: {default_offline_chat_model}): " ) + if offline_chat_model == "": + ChatModelOptions.objects.create( + chat_model=default_offline_chat_model, model_type=ChatModelOptions.ModelType.OFFLINE + ) + else: + max_tokens = input("Enter the maximum number of tokens to use for the offline chat model:") + tokenizer = input("Enter the tokenizer to use for the offline chat model:") + ChatModelOptions.objects.create( + chat_model=offline_chat_model, + model_type=ChatModelOptions.ModelType.OFFLINE, + max_prompt_size=max_tokens, + tokenizer=tokenizer, + ) + except ModuleNotFoundError as e: + logger.warning("Offline models are not supported on this device.") use_openai_model = input("Use OpenAI chat model? (y/n): ") @@ -61,7 +75,7 @@ def initialization(): chat_model=openai_chat_model, model_type=ChatModelOptions.ModelType.OPENAI, max_tokens=max_tokens ) - logger.info("🗣️ Chat model configuration complete") + logger.info("🗣️ Chat model configuration complete") admin_user = KhojUser.objects.filter(is_staff=True).first() if admin_user is None: