mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-05 13:21:18 +00:00
Simplify migration scripts management. Make them use static version
- Only make them update config when it's run conditions are satisfies - Use static schema version to simplify reasoning about run conditions
This commit is contained in:
@@ -13,13 +13,13 @@ def migrate_offline_model(args):
|
||||
|
||||
if version_no is None or version.parse(version_no) < version.parse("0.10.1"):
|
||||
logger.info(f"Migrating offline model used for version {version_no} to latest version for {args.version_no}")
|
||||
raw_config["version"] = "0.10.1"
|
||||
|
||||
# If the user has downloaded the offline model, remove it from the cache.
|
||||
offline_model_path = os.path.expanduser("~/.cache/gpt4all/llama-2-7b-chat.ggmlv3.q4_K_S.bin")
|
||||
if os.path.exists(offline_model_path):
|
||||
os.remove(offline_model_path)
|
||||
|
||||
raw_config["version"] = args.version_no
|
||||
save_config_to_file(raw_config, args.config_file)
|
||||
save_config_to_file(raw_config, args.config_file)
|
||||
|
||||
return args
|
||||
|
||||
@@ -36,8 +36,6 @@ from khoj.utils.yaml import load_config_from_file, save_config_to_file
|
||||
def migrate_processor_conversation_schema(args):
|
||||
raw_config = load_config_from_file(args.config_file)
|
||||
|
||||
raw_config["version"] = args.version_no
|
||||
|
||||
if "processor" not in raw_config:
|
||||
return args
|
||||
if raw_config["processor"] is None:
|
||||
@@ -45,22 +43,24 @@ def migrate_processor_conversation_schema(args):
|
||||
if "conversation" not in raw_config["processor"]:
|
||||
return args
|
||||
|
||||
# Add enable_offline_chat to khoj config schema
|
||||
if "enable-offline-chat" not in raw_config["processor"]["conversation"]:
|
||||
raw_config["processor"]["conversation"]["enable-offline-chat"] = False
|
||||
save_config_to_file(raw_config, args.config_file)
|
||||
|
||||
current_openai_api_key = raw_config["processor"]["conversation"].get("openai-api-key", None)
|
||||
current_chat_model = raw_config["processor"]["conversation"].get("chat-model", None)
|
||||
if current_openai_api_key is None and current_chat_model is None:
|
||||
return args
|
||||
|
||||
conversation_logfile = raw_config["processor"]["conversation"].get("conversation-logfile", None)
|
||||
raw_config["version"] = "0.10.0"
|
||||
|
||||
# Add enable_offline_chat to khoj config schema
|
||||
if "enable-offline-chat" not in raw_config["processor"]["conversation"]:
|
||||
raw_config["processor"]["conversation"]["enable-offline-chat"] = False
|
||||
|
||||
# Update conversation processor schema
|
||||
conversation_logfile = raw_config["processor"]["conversation"].get("conversation-logfile", None)
|
||||
raw_config["processor"]["conversation"] = {
|
||||
"openai": {"chat-model": current_chat_model, "api-key": current_openai_api_key},
|
||||
"conversation-logfile": conversation_logfile,
|
||||
"enable-offline-chat": False,
|
||||
}
|
||||
|
||||
save_config_to_file(raw_config, args.config_file)
|
||||
return args
|
||||
|
||||
@@ -6,7 +6,7 @@ def migrate_config_to_version(args):
|
||||
|
||||
# Add version to khoj config schema
|
||||
if "version" not in raw_config:
|
||||
raw_config["version"] = args.version_no
|
||||
raw_config["version"] = "0.9.0"
|
||||
save_config_to_file(raw_config, args.config_file)
|
||||
|
||||
# regenerate khoj index on first start of this version
|
||||
|
||||
Reference in New Issue
Block a user