Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
27 changes: 26 additions & 1 deletion learn2rag/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import subprocess
import threading
import time
import tomllib
from typing import Any
import urllib

Expand Down Expand Up @@ -203,7 +204,7 @@ def inject_data() -> dict[str, Any]:
'sources': learn2rag.data.get_all(app.instance_path, 'sources'),
'pipelines': learn2rag.data.get_all(app.instance_path, 'pipelines'),
}

# TODO : check if we dont need this delete
@app.context_processor
def inject_current_year() -> dict[str, Any]:
return {'current_year': datetime.now().year}
Expand All @@ -218,6 +219,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')
Expand Down Expand Up @@ -514,6 +526,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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with a packaged version?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from importlib.metadata import version, PackageNotFoundError
try:
    return version('learn2rag')
except PackageNotFoundError:
    return 'unknown'

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()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

text=True subprocess option instead of decode()

except Exception:
return "unknown"

def atexit_handler() -> None:
logging.debug('Exit handler')
Expand Down
5 changes: 5 additions & 0 deletions learn2rag/ui/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
</script>
</body>
</html>
15 changes: 6 additions & 9 deletions learn2rag/ui/templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
<div class="container d-flex flex-column flex-md-row justify-content-between align-items-center">
<!-- Left: Links -->
<div class="d-flex flex-column align-items-start">
<div class="mb-2">
<a href="https://github.com/learn2rag" class="footer-link me-4">
<i class="fab fa-github"></i> GITHUB
</a>
<a href="https://www.linkedin.com/" class="footer-link">
<i class="fab fa-linkedin"></i> LINKEDIN
</a>
</div>
<div>
© {{ current_year }} Learn2RAG.
Learn2RAG
<span class="ms-2 border-bottom border-secondary cursor-help"
data-bs-toggle="tooltip"
data-bs-title="git commit: {{ git_hash }}">
v{{ app_version }}
</span>
</div>
</div>

Expand Down
Loading