diff --git a/learn2rag/ui/__init__.py b/learn2rag/ui/__init__.py index 0678800..4132dd3 100644 --- a/learn2rag/ui/__init__.py +++ b/learn2rag/ui/__init__.py @@ -13,6 +13,7 @@ import subprocess import threading import time +import tomllib from typing import Any import urllib @@ -204,10 +205,6 @@ def inject_data() -> dict[str, Any]: 'pipelines': learn2rag.data.get_all(app.instance_path, 'pipelines'), } - @app.context_processor - def inject_current_year() -> dict[str, Any]: - return {'current_year': datetime.now().year} - atexit.register(atexit_handler) # TODO: let the user configure the directory for ollama data before starting it? @@ -218,6 +215,17 @@ def inject_current_year() -> dict[str, Any]: app.logger.exception(e) app.logger.warning('Ollama is already running or failed to start') + + cached_version = get_version() + cached_hash = get_git_hash() + + @app.context_processor + def inject_version() -> dict[str, str]: + return { + "app_version": cached_version, + "git_hash": cached_hash + } + @app.get('/') def start() -> 'str | werkzeug.wrappers.response.Response': pipelines = learn2rag.data.get_all(app.instance_path, 'pipelines') @@ -514,6 +522,19 @@ def shutdown_request() -> 'str | werkzeug.wrappers.response.Response': app.logger.info('App creation complete') return app +def get_version() -> str: + try: + with open("pyproject.toml", "rb") as f: + data = tomllib.load(f) + return str(data.get("project", {}).get("version", "0.0.0")) + except Exception: + return "0.0.0" + +def get_git_hash() -> str: + try: + return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('ascii').strip() + except Exception: + return "unknown" def atexit_handler() -> None: logging.debug('Exit handler') diff --git a/learn2rag/ui/templates/base.html b/learn2rag/ui/templates/base.html index 63a3b9c..7f44245 100644 --- a/learn2rag/ui/templates/base.html +++ b/learn2rag/ui/templates/base.html @@ -101,6 +101,11 @@ }; document.body.addEventListener('htmx:sendError', errorHandler); document.body.addEventListener('htmx:responseError', errorHandler); + + document.addEventListener('DOMContentLoaded', function () { + const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]'); + const tooltipList = [...tooltipTriggerList].map(el => new bootstrap.Tooltip(el)); + }); diff --git a/learn2rag/ui/templates/footer.html b/learn2rag/ui/templates/footer.html index 8f22995..c744342 100644 --- a/learn2rag/ui/templates/footer.html +++ b/learn2rag/ui/templates/footer.html @@ -2,16 +2,13 @@
-
- © {{ current_year }} Learn2RAG. + Learn2RAG + + v{{ app_version }} +