From b2296cfcdfbb17e4580d22d832c505696d1c7cc6 Mon Sep 17 00:00:00 2001 From: ian_Cin Date: Thu, 16 May 2024 14:27:51 +0700 Subject: [PATCH] (bump:patch) Feat: Show app version in the Help page (#68) * typo * show version in the Help page * update docs * pump duckduckgo-search * allow app version to be set by env var --- docs/index.md | 4 +-- flowsettings.py | 10 ++++++ libs/kotaemon/pyproject.toml | 2 +- libs/ktem/ktem/pages/help.py | 65 ++++++++++++++++++++++-------------- libs/ktem/pyproject.toml | 2 +- 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/docs/index.md b/docs/index.md index 134b4f5bf..0e8b2fb39 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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` diff --git a/flowsettings.py b/flowsettings.py index f4b5bbf17..8d7f3cc71 100644 --- a/flowsettings.py +++ b/flowsettings.py @@ -1,4 +1,5 @@ import os +from importlib.metadata import version from inspect import currentframe, getframeinfo from pathlib import Path @@ -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" diff --git a/libs/kotaemon/pyproject.toml b/libs/kotaemon/pyproject.toml index 3694f704e..101b91b11 100644 --- a/libs/kotaemon/pyproject.toml +++ b/libs/kotaemon/pyproject.toml @@ -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", diff --git a/libs/ktem/ktem/pages/help.py b/libs/ktem/ktem/pages/help.py index 54decb62d..fd750ef54 100644 --- a/libs/ktem/ktem/pages/help.py +++ b/libs/ktem/ktem/pages/help.py @@ -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 @@ -17,21 +15,11 @@ 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}") @@ -39,18 +27,22 @@ def get_changelogs(version): 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(): @@ -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" @@ -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) diff --git a/libs/ktem/pyproject.toml b/libs/ktem/pyproject.toml index e50c63da2..eb6ac122e 100644 --- a/libs/ktem/pyproject.toml +++ b/libs/ktem/pyproject.toml @@ -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", ]