Skip to content

Feat: Show app version in the Help page #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Answering on local documents. If you are a **developer** who wants contribute to

## Download

Download and upzip the latest version of `kotaemon` by clicking this
[link](https://github.com/Cinnamon/kotaemon/archive/refs/heads/main.zip).
Download the `kotaemon-app.zip` file from the [latest release](https://github.com/Cinnamon/kotaemon/releases/latest/).

## Installation

0. Unzip the downloaded file.
1. Navigate to the `scripts` folder and start an installer that matches your OS:
- Windows: `run_windows.bat`. Just double click the file.
- macOS: `run_macos.sh`
Expand Down
10 changes: 10 additions & 0 deletions flowsettings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from importlib.metadata import version
from inspect import currentframe, getframeinfo
from pathlib import Path

Expand All @@ -14,6 +15,15 @@
# change this if your app use a different name
KH_PACKAGE_NAME = "kotaemon_app"

KH_APP_VERSION = os.environ.get("KH_APP_VERSION", None)
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)
except Exception as e:
print(f"Failed to get app version: {e}")

# 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"
Expand Down
2 changes: 1 addition & 1 deletion libs/kotaemon/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ classifiers = [
[project.optional-dependencies]
adv = [
"wikipedia>=1.4.0,<1.5",
"duckduckgo-search>=5.3.0,<5.4.0",
"duckduckgo-search>=6.1.0,<6.2",
"googlesearch-python>=1.2.4,<1.3",
"python-docx>=1.1.0,<1.2",
"unstructured[pdf]==0.13.4",
Expand Down
65 changes: 40 additions & 25 deletions libs/ktem/ktem/pages/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import requests
from theflow.settings import settings

CHANGELOG_CACHE_DIR = Path(settings.KH_APP_DATA_DIR) / "changelogs"


def get_remote_doc(url):
def get_remote_doc(url: str) -> str:
try:
res = requests.get(url)
return res.text
Expand All @@ -17,40 +15,34 @@ def get_remote_doc(url):
return ""


def get_changelogs(version):
# try retrieve from cache
if (CHANGELOG_CACHE_DIR / f"{version}.md").exists():
with open(CHANGELOG_CACHE_DIR / f"{version}.md", "r") as fi:
return fi.read()

release_url = f"https://api.github.com/repos/Cinnamon/kotaemon/releases/{version}"
def download_changelogs(release_url: str) -> str:
try:
res = requests.get(release_url).json()
changelogs = res.get("body", "")

# cache the changelogs
with open(CHANGELOG_CACHE_DIR / f"{version}.md", "w") as fi:
fi.write(changelogs)

return changelogs
except Exception as e:
print(f"Failed to fetch changelogs from {release_url}: {e}")
return ""


class HelpPage:
def __init__(self, app):
def __init__(
self,
app,
doc_dir: str = settings.KH_DOC_DIR,
remote_content_url: str = "https://raw.githubusercontent.com/Cinnamon/kotaemon",
app_version: str | None = settings.KH_APP_VERSION,
changelogs_cache_dir: str
| Path = (Path(settings.KH_APP_DATA_DIR) / "changelogs"),
):
self._app = app
self.doc_dir = Path(settings.KH_DOC_DIR)
self.remote_content_url = "https://raw.githubusercontent.com/Cinnamon/kotaemon"
self.doc_dir = Path(doc_dir)
self.remote_content_url = remote_content_url
self.app_version = app_version
self.changelogs_cache_dir = Path(changelogs_cache_dir)

self.app_version = None
try:
# Caution: This might produce the wrong version
# https://stackoverflow.com/a/59533071
self.app_version = version(settings.KH_PACKAGE_NAME)
except Exception as e:
print(f"Failed to get app version: {e}")
self.changelogs_cache_dir.mkdir(parents=True, exist_ok=True)

about_md_dir = self.doc_dir / "about.md"
if about_md_dir.exists():
Expand All @@ -62,6 +54,8 @@ def __init__(self, app):
)
if about_md:
with gr.Accordion("About"):
if self.app_version:
about_md = f"Version: {self.app_version}\n\n{about_md}"
gr.Markdown(about_md)

user_guide_md_dir = self.doc_dir / "usage.md"
Expand All @@ -77,7 +71,28 @@ def __init__(self, app):
gr.Markdown(user_guide_md)

if self.app_version:
changelogs = get_changelogs("tags/v" + self.app_version)
# try retrieve from cache
changelogs = ""

if (self.changelogs_cache_dir / f"{version}.md").exists():
with open(self.changelogs_cache_dir / f"{version}.md", "r") as fi:
changelogs = fi.read()
else:
release_url_base = (
"https://api.github.com/repos/Cinnamon/kotaemon/releases"
)
changelogs = download_changelogs(
release_url=f"{release_url_base}/tags/v{self.app_version}"
)

# cache the changelogs
if not self.changelogs_cache_dir.exists():
self.changelogs_cache_dir.mkdir(parents=True, exist_ok=True)
with open(
self.changelogs_cache_dir / f"{self.app_version}.md", "w"
) as fi:
fi.write(changelogs)

if changelogs:
with gr.Accordion(f"Changelogs (v{self.app_version})"):
gr.Markdown(changelogs)
2 changes: 1 addition & 1 deletion libs/ktem/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies = [
"python-decouple>=3.8,<4",
"SQLAlchemy>=2.0.29,<3",
"sqlmodel>=0.0.16,<0.1",
"tiktoken>=0.6.0<1",
"tiktoken>=0.6.0,<1",
"gradio>=4.26.0,<5",
"markdown>=3.6,<4",
]
Expand Down