Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import logging
import os
import platform
from typing import Dict, Any

from theflow.settings import settings as flowsettings

Expand All @@ -11,9 +14,50 @@
os.environ["GRADIO_TEMP_DIR"] = GRADIO_TEMP_DIR


from ktem.embeddings.manager import embedding_models_manager
from ktem.llms.manager import llms
from ktem.main import App # noqa


def _classify_services(info_dict: Dict[str, Dict[str, Any]]) -> Dict[str, Dict[str, Any]]:
local_markers = ["LlamaCpp", "LCOllama", "LCHuggingFace", "FastEmbed"]
classified = {}
for name, info in info_dict.items():
spec_type = info.get("spec", {}).get("__type__", "")
location = (
"local"
if any(marker in spec_type for marker in local_markers)
else "external"
)
classified[name] = {
"type": spec_type,
"location": location,
"default": info.get("default", False),
}

return classified


def log_startup_info(app):
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("startup")
logger.setLevel(logging.INFO)
logger.info("OS: %s", platform.platform())
logger.info("Python: %s", platform.python_version())

docstore = getattr(flowsettings, "KH_DOCSTORE", {})
vectorstore = getattr(flowsettings, "KH_VECTORSTORE", {})
logger.info("Docstore: %s", docstore)
logger.info("Vectorstore: %s", vectorstore)

logger.info("LLMs: %s", _classify_services(llms.info()))
logger.info(
"Embeddings: %s", _classify_services(embedding_models_manager.info())
)


app = App()
log_startup_info(app)
demo = app.make()
demo.queue().launch(
favicon_path=app._favicon,
Expand Down