2024-04-13 23:26:06 +07:00
|
|
|
import os
|
2024-05-16 14:27:51 +07:00
|
|
|
from importlib.metadata import version
|
2024-04-13 23:26:06 +07:00
|
|
|
from inspect import currentframe, getframeinfo
|
2024-01-23 10:54:18 +07:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from decouple import config
|
|
|
|
from theflow.settings.default import * # noqa
|
|
|
|
|
2024-04-13 23:26:06 +07:00
|
|
|
cur_frame = currentframe()
|
|
|
|
if cur_frame is None:
|
|
|
|
raise ValueError("Cannot get the current frame.")
|
|
|
|
this_file = getframeinfo(cur_frame).filename
|
|
|
|
this_dir = Path(this_file).parent
|
|
|
|
|
2024-05-15 16:34:50 +07:00
|
|
|
# change this if your app use a different name
|
|
|
|
KH_PACKAGE_NAME = "kotaemon_app"
|
|
|
|
|
2024-09-02 17:42:39 +07:00
|
|
|
KH_APP_VERSION = config("KH_APP_VERSION", None)
|
2024-05-16 14:27:51 +07:00
|
|
|
if not KH_APP_VERSION:
|
|
|
|
try:
|
|
|
|
# Caution: This might produce the wrong version
|
|
|
|
# https://stackoverflow.com/a/59533071
|
|
|
|
KH_APP_VERSION = version(KH_PACKAGE_NAME)
|
2024-09-02 17:42:39 +07:00
|
|
|
except Exception:
|
|
|
|
KH_APP_VERSION = "local"
|
2024-05-16 14:27:51 +07:00
|
|
|
|
2024-09-22 16:32:23 +07:00
|
|
|
KH_ENABLE_FIRST_SETUP = True
|
|
|
|
KH_DEMO_MODE = config("KH_DEMO_MODE", default=False, cast=bool)
|
|
|
|
|
2024-04-13 23:26:06 +07:00
|
|
|
# App can be ran from anywhere and it's not trivial to decide where to store app data.
|
|
|
|
# So let's use the same directory as the flowsetting.py file.
|
|
|
|
KH_APP_DATA_DIR = this_dir / "ktem_app_data"
|
2024-09-22 16:32:23 +07:00
|
|
|
KH_APP_DATA_EXISTS = KH_APP_DATA_DIR.exists()
|
2024-04-13 23:26:06 +07:00
|
|
|
KH_APP_DATA_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
# User data directory
|
|
|
|
KH_USER_DATA_DIR = KH_APP_DATA_DIR / "user_data"
|
|
|
|
KH_USER_DATA_DIR.mkdir(parents=True, exist_ok=True)
|
2024-01-23 10:54:18 +07:00
|
|
|
|
2024-08-26 08:50:37 +07:00
|
|
|
# markdown output directory
|
|
|
|
KH_MARKDOWN_OUTPUT_DIR = KH_APP_DATA_DIR / "markdown_cache_dir"
|
|
|
|
KH_MARKDOWN_OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
# chunks output directory
|
|
|
|
KH_CHUNKS_OUTPUT_DIR = KH_APP_DATA_DIR / "chunks_cache_dir"
|
|
|
|
KH_CHUNKS_OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
# zip output directory
|
|
|
|
KH_ZIP_OUTPUT_DIR = KH_APP_DATA_DIR / "zip_cache_dir"
|
|
|
|
KH_ZIP_OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
# zip input directory
|
|
|
|
KH_ZIP_INPUT_DIR = KH_APP_DATA_DIR / "zip_cache_dir_in"
|
|
|
|
KH_ZIP_INPUT_DIR.mkdir(parents=True, exist_ok=True)
|
2024-05-15 16:34:50 +07:00
|
|
|
|
2024-04-13 23:26:06 +07:00
|
|
|
# HF models can be big, let's store them in the app data directory so that it's easier
|
|
|
|
# for users to manage their storage.
|
|
|
|
# ref: https://huggingface.co/docs/huggingface_hub/en/guides/manage-cache
|
|
|
|
os.environ["HF_HOME"] = str(KH_APP_DATA_DIR / "huggingface")
|
|
|
|
os.environ["HF_HUB_CACHE"] = str(KH_APP_DATA_DIR / "huggingface")
|
2024-01-23 10:54:18 +07:00
|
|
|
|
2024-08-26 08:50:37 +07:00
|
|
|
# doc directory
|
|
|
|
KH_DOC_DIR = this_dir / "docs"
|
|
|
|
|
2024-01-25 19:07:53 +07:00
|
|
|
KH_MODE = "dev"
|
2024-09-22 16:32:23 +07:00
|
|
|
KH_FEATURE_USER_MANAGEMENT = config(
|
|
|
|
"KH_FEATURE_USER_MANAGEMENT", default=True, cast=bool
|
|
|
|
)
|
2024-08-26 08:50:37 +07:00
|
|
|
KH_USER_CAN_SEE_PUBLIC = None
|
2024-03-07 14:19:37 +07:00
|
|
|
KH_FEATURE_USER_MANAGEMENT_ADMIN = str(
|
|
|
|
config("KH_FEATURE_USER_MANAGEMENT_ADMIN", default="admin")
|
|
|
|
)
|
|
|
|
KH_FEATURE_USER_MANAGEMENT_PASSWORD = str(
|
2024-08-26 08:50:37 +07:00
|
|
|
config("KH_FEATURE_USER_MANAGEMENT_PASSWORD", default="admin")
|
2024-03-07 14:19:37 +07:00
|
|
|
)
|
2024-01-28 19:54:15 +07:00
|
|
|
KH_ENABLE_ALEMBIC = False
|
2024-04-13 23:26:06 +07:00
|
|
|
KH_DATABASE = f"sqlite:///{KH_USER_DATA_DIR / 'sql.db'}"
|
|
|
|
KH_FILESTORAGE_PATH = str(KH_USER_DATA_DIR / "files")
|
2024-03-15 16:17:33 +07:00
|
|
|
|
2024-01-23 10:54:18 +07:00
|
|
|
KH_DOCSTORE = {
|
2024-08-26 08:50:37 +07:00
|
|
|
# "__type__": "kotaemon.storages.ElasticsearchDocumentStore",
|
|
|
|
# "__type__": "kotaemon.storages.SimpleFileDocumentStore",
|
|
|
|
"__type__": "kotaemon.storages.LanceDBDocumentStore",
|
2024-04-13 23:26:06 +07:00
|
|
|
"path": str(KH_USER_DATA_DIR / "docstore"),
|
2024-01-23 10:54:18 +07:00
|
|
|
}
|
|
|
|
KH_VECTORSTORE = {
|
2024-08-26 08:50:37 +07:00
|
|
|
# "__type__": "kotaemon.storages.LanceDBVectorStore",
|
2024-01-23 10:54:18 +07:00
|
|
|
"__type__": "kotaemon.storages.ChromaVectorStore",
|
2024-09-04 21:22:50 +08:00
|
|
|
# "__type__": "kotaemon.storages.MilvusVectorStore",
|
2024-09-16 02:47:36 +05:30
|
|
|
# "__type__": "kotaemon.storages.QdrantVectorStore",
|
2024-04-13 23:26:06 +07:00
|
|
|
"path": str(KH_USER_DATA_DIR / "vectorstore"),
|
2024-01-23 10:54:18 +07:00
|
|
|
}
|
2024-03-27 19:04:48 +07:00
|
|
|
KH_LLMS = {}
|
|
|
|
KH_EMBEDDINGS = {}
|
|
|
|
|
|
|
|
# populate options from config
|
|
|
|
if config("AZURE_OPENAI_API_KEY", default="") and config(
|
|
|
|
"AZURE_OPENAI_ENDPOINT", default=""
|
|
|
|
):
|
|
|
|
if config("AZURE_OPENAI_CHAT_DEPLOYMENT", default=""):
|
|
|
|
KH_LLMS["azure"] = {
|
2024-04-06 11:53:17 +07:00
|
|
|
"spec": {
|
2024-03-27 19:04:48 +07:00
|
|
|
"__type__": "kotaemon.llms.AzureChatOpenAI",
|
|
|
|
"temperature": 0,
|
|
|
|
"azure_endpoint": config("AZURE_OPENAI_ENDPOINT", default=""),
|
2024-04-06 11:53:17 +07:00
|
|
|
"api_key": config("AZURE_OPENAI_API_KEY", default=""),
|
2024-03-27 19:04:48 +07:00
|
|
|
"api_version": config("OPENAI_API_VERSION", default="")
|
|
|
|
or "2024-02-15-preview",
|
2024-04-06 11:53:17 +07:00
|
|
|
"azure_deployment": config("AZURE_OPENAI_CHAT_DEPLOYMENT", default=""),
|
|
|
|
"timeout": 20,
|
2024-03-27 19:04:48 +07:00
|
|
|
},
|
|
|
|
"default": False,
|
|
|
|
}
|
|
|
|
if config("AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT", default=""):
|
|
|
|
KH_EMBEDDINGS["azure"] = {
|
2024-04-06 11:53:17 +07:00
|
|
|
"spec": {
|
2024-04-10 15:11:44 +07:00
|
|
|
"__type__": "kotaemon.embeddings.AzureOpenAIEmbeddings",
|
2024-03-27 19:04:48 +07:00
|
|
|
"azure_endpoint": config("AZURE_OPENAI_ENDPOINT", default=""),
|
2024-04-09 15:07:59 +07:00
|
|
|
"api_key": config("AZURE_OPENAI_API_KEY", default=""),
|
2024-03-27 19:04:48 +07:00
|
|
|
"api_version": config("OPENAI_API_VERSION", default="")
|
|
|
|
or "2024-02-15-preview",
|
2024-04-09 15:07:59 +07:00
|
|
|
"azure_deployment": config(
|
|
|
|
"AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT", default=""
|
|
|
|
),
|
|
|
|
"timeout": 10,
|
2024-03-27 19:04:48 +07:00
|
|
|
},
|
|
|
|
"default": False,
|
|
|
|
}
|
|
|
|
|
|
|
|
if config("OPENAI_API_KEY", default=""):
|
|
|
|
KH_LLMS["openai"] = {
|
2024-04-08 22:23:00 +07:00
|
|
|
"spec": {
|
2024-03-27 19:04:48 +07:00
|
|
|
"__type__": "kotaemon.llms.ChatOpenAI",
|
|
|
|
"temperature": 0,
|
2024-04-08 22:23:00 +07:00
|
|
|
"base_url": config("OPENAI_API_BASE", default="")
|
2024-03-27 19:04:48 +07:00
|
|
|
or "https://api.openai.com/v1",
|
2024-04-08 22:23:00 +07:00
|
|
|
"api_key": config("OPENAI_API_KEY", default=""),
|
2024-08-26 08:50:37 +07:00
|
|
|
"model": config("OPENAI_CHAT_MODEL", default="gpt-3.5-turbo"),
|
|
|
|
"timeout": 20,
|
|
|
|
},
|
|
|
|
"default": True,
|
|
|
|
}
|
|
|
|
KH_EMBEDDINGS["openai"] = {
|
|
|
|
"spec": {
|
|
|
|
"__type__": "kotaemon.embeddings.OpenAIEmbeddings",
|
|
|
|
"base_url": config("OPENAI_API_BASE", default="https://api.openai.com/v1"),
|
|
|
|
"api_key": config("OPENAI_API_KEY", default=""),
|
|
|
|
"model": config(
|
|
|
|
"OPENAI_EMBEDDINGS_MODEL", default="text-embedding-ada-002"
|
|
|
|
),
|
2024-04-08 22:23:00 +07:00
|
|
|
"timeout": 10,
|
2024-08-26 08:50:37 +07:00
|
|
|
"context_length": 8191,
|
2024-01-23 10:54:18 +07:00
|
|
|
},
|
2024-08-26 08:50:37 +07:00
|
|
|
"default": True,
|
2024-03-27 19:04:48 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if config("LOCAL_MODEL", default=""):
|
2024-08-26 08:50:37 +07:00
|
|
|
KH_LLMS["ollama"] = {
|
2024-04-08 22:23:00 +07:00
|
|
|
"spec": {
|
2024-08-26 08:50:37 +07:00
|
|
|
"__type__": "kotaemon.llms.ChatOpenAI",
|
|
|
|
"base_url": "http://localhost:11434/v1/",
|
|
|
|
"model": config("LOCAL_MODEL", default="llama3.1:8b"),
|
2024-08-30 23:18:31 +07:00
|
|
|
"api_key": "ollama",
|
2024-08-26 08:50:37 +07:00
|
|
|
},
|
|
|
|
"default": False,
|
|
|
|
}
|
|
|
|
KH_EMBEDDINGS["ollama"] = {
|
|
|
|
"spec": {
|
|
|
|
"__type__": "kotaemon.embeddings.OpenAIEmbeddings",
|
|
|
|
"base_url": "http://localhost:11434/v1/",
|
|
|
|
"model": config("LOCAL_MODEL_EMBEDDINGS", default="nomic-embed-text"),
|
2024-08-30 23:18:31 +07:00
|
|
|
"api_key": "ollama",
|
2024-01-23 10:54:18 +07:00
|
|
|
},
|
2024-03-15 16:17:33 +07:00
|
|
|
"default": False,
|
2024-03-27 19:04:48 +07:00
|
|
|
}
|
|
|
|
|
2024-09-06 18:18:19 +07:00
|
|
|
KH_EMBEDDINGS["fast_embed"] = {
|
2024-04-10 15:11:44 +07:00
|
|
|
"spec": {
|
|
|
|
"__type__": "kotaemon.embeddings.FastEmbedEmbeddings",
|
2024-04-13 18:29:37 +07:00
|
|
|
"model_name": "BAAI/bge-base-en-v1.5",
|
2024-04-10 15:11:44 +07:00
|
|
|
},
|
2024-08-26 08:50:37 +07:00
|
|
|
"default": False,
|
2024-04-10 15:11:44 +07:00
|
|
|
}
|
2024-03-27 19:04:48 +07:00
|
|
|
|
2024-09-05 21:58:20 +07:00
|
|
|
# additional LLM configurations
|
2024-09-06 09:23:26 +07:00
|
|
|
KH_LLMS["claude"] = {
|
|
|
|
"spec": {
|
|
|
|
"__type__": "kotaemon.llms.chats.LCAnthropicChat",
|
|
|
|
"model_name": "claude-3-5-sonnet-20240620",
|
|
|
|
"api_key": "your-key",
|
|
|
|
},
|
|
|
|
"default": False,
|
|
|
|
}
|
2024-09-06 09:36:21 +07:00
|
|
|
# KH_LLMS["gemini"] = {
|
|
|
|
# "spec": {
|
|
|
|
# "__type__": "kotaemon.llms.chats.LCGeminiChat",
|
|
|
|
# "model_name": "gemini-1.5-pro",
|
|
|
|
# "api_key": "your-key",
|
|
|
|
# },
|
|
|
|
# "default": False,
|
|
|
|
# }
|
2024-09-05 21:58:20 +07:00
|
|
|
KH_LLMS["groq"] = {
|
|
|
|
"spec": {
|
|
|
|
"__type__": "kotaemon.llms.ChatOpenAI",
|
|
|
|
"base_url": "https://api.groq.com/openai/v1",
|
|
|
|
"model": "llama-3.1-8b-instant",
|
|
|
|
"api_key": "your-key",
|
|
|
|
},
|
|
|
|
"default": False,
|
|
|
|
}
|
2024-09-22 16:32:23 +07:00
|
|
|
KH_LLMS["cohere"] = {
|
|
|
|
"spec": {
|
|
|
|
"__type__": "kotaemon.llms.chats.LCCohereChat",
|
|
|
|
"model_name": "command-r-plus-08-2024",
|
|
|
|
"api_key": "your-key",
|
|
|
|
},
|
|
|
|
"default": False,
|
|
|
|
}
|
2024-09-05 21:58:20 +07:00
|
|
|
|
2024-09-06 18:18:19 +07:00
|
|
|
# additional embeddings configurations
|
|
|
|
KH_EMBEDDINGS["cohere"] = {
|
|
|
|
"spec": {
|
|
|
|
"__type__": "kotaemon.embeddings.LCCohereEmbeddings",
|
|
|
|
"model": "embed-multilingual-v2.0",
|
|
|
|
"cohere_api_key": "your-key",
|
2024-09-09 14:15:34 +07:00
|
|
|
"user_agent": "default",
|
2024-09-06 18:18:19 +07:00
|
|
|
},
|
|
|
|
"default": False,
|
|
|
|
}
|
|
|
|
# KH_EMBEDDINGS["huggingface"] = {
|
|
|
|
# "spec": {
|
|
|
|
# "__type__": "kotaemon.embeddings.LCHuggingFaceEmbeddings",
|
|
|
|
# "model_name": "sentence-transformers/all-mpnet-base-v2",
|
|
|
|
# },
|
|
|
|
# "default": False,
|
|
|
|
# }
|
|
|
|
|
2024-08-26 08:50:37 +07:00
|
|
|
KH_REASONINGS = [
|
|
|
|
"ktem.reasoning.simple.FullQAPipeline",
|
|
|
|
"ktem.reasoning.simple.FullDecomposeQAPipeline",
|
|
|
|
"ktem.reasoning.react.ReactAgentPipeline",
|
|
|
|
"ktem.reasoning.rewoo.RewooAgentPipeline",
|
|
|
|
]
|
|
|
|
KH_REASONINGS_USE_MULTIMODAL = False
|
2024-04-03 14:52:40 +07:00
|
|
|
KH_VLM_ENDPOINT = "{0}/openai/deployments/{1}/chat/completions?api-version={2}".format(
|
|
|
|
config("AZURE_OPENAI_ENDPOINT", default=""),
|
2024-08-26 08:50:37 +07:00
|
|
|
config("OPENAI_VISION_DEPLOYMENT_NAME", default="gpt-4o"),
|
2024-04-03 14:52:40 +07:00
|
|
|
config("OPENAI_API_VERSION", default=""),
|
|
|
|
)
|
2024-01-23 10:54:18 +07:00
|
|
|
|
|
|
|
|
2024-08-26 08:50:37 +07:00
|
|
|
SETTINGS_APP: dict[str, dict] = {}
|
2024-01-23 10:54:18 +07:00
|
|
|
|
|
|
|
|
|
|
|
SETTINGS_REASONING = {
|
|
|
|
"use": {
|
|
|
|
"name": "Reasoning options",
|
|
|
|
"value": None,
|
|
|
|
"choices": [],
|
|
|
|
"component": "radio",
|
|
|
|
},
|
|
|
|
"lang": {
|
|
|
|
"name": "Language",
|
|
|
|
"value": "en",
|
2024-08-26 08:50:37 +07:00
|
|
|
"choices": [("English", "en"), ("Japanese", "ja"), ("Vietnamese", "vi")],
|
2024-01-23 10:54:18 +07:00
|
|
|
"component": "dropdown",
|
|
|
|
},
|
2024-08-26 08:50:37 +07:00
|
|
|
"max_context_length": {
|
|
|
|
"name": "Max context length (LLM)",
|
|
|
|
"value": 32000,
|
|
|
|
"component": "number",
|
|
|
|
},
|
2024-01-23 10:54:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-08-26 08:50:37 +07:00
|
|
|
KH_INDEX_TYPES = [
|
|
|
|
"ktem.index.file.FileIndex",
|
|
|
|
"ktem.index.file.graph.GraphRAGIndex",
|
|
|
|
]
|
2024-03-07 01:50:47 +07:00
|
|
|
KH_INDICES = [
|
|
|
|
{
|
|
|
|
"name": "File",
|
2024-08-26 08:50:37 +07:00
|
|
|
"config": {
|
|
|
|
"supported_file_types": (
|
|
|
|
".png, .jpeg, .jpg, .tiff, .tif, .pdf, .xls, .xlsx, .doc, .docx, "
|
2024-09-03 23:15:26 +07:00
|
|
|
".pptx, .csv, .html, .mhtml, .txt, .md, .zip"
|
2024-08-26 08:50:37 +07:00
|
|
|
),
|
|
|
|
"private": False,
|
|
|
|
},
|
2024-03-07 01:50:47 +07:00
|
|
|
"index_type": "ktem.index.file.FileIndex",
|
2024-04-06 11:53:17 +07:00
|
|
|
},
|
2024-08-26 08:50:37 +07:00
|
|
|
{
|
|
|
|
"name": "GraphRAG",
|
|
|
|
"config": {
|
|
|
|
"supported_file_types": (
|
|
|
|
".png, .jpeg, .jpg, .tiff, .tif, .pdf, .xls, .xlsx, .doc, .docx, "
|
2024-09-03 23:15:26 +07:00
|
|
|
".pptx, .csv, .html, .mhtml, .txt, .md, .zip"
|
2024-08-26 08:50:37 +07:00
|
|
|
),
|
|
|
|
"private": False,
|
|
|
|
},
|
|
|
|
"index_type": "ktem.index.file.graph.GraphRAGIndex",
|
|
|
|
},
|
2024-03-07 01:50:47 +07:00
|
|
|
]
|