mirror of
https://github.com/Cinnamon/kotaemon.git
synced 2025-06-26 23:19:56 +00:00
(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
This commit is contained in:
parent
bd34facddc
commit
b2296cfcdf
@ -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`
|
||||
|
@ -1,4 +1,5 @@
|
||||
import os
|
||||
from importlib.metadata import version
|
||||
from inspect import currentframe, getframeinfo
|
||||
from pathlib import Path
|
||||
|
||||
@ -14,6 +15,15 @@ this_dir = Path(this_file).parent
|
||||
# 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"
|
||||
|
@ -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",
|
||||
|
@ -5,10 +5,8 @@ import gradio as gr
|
||||
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 @@ class HelpPage:
|
||||
)
|
||||
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 @@ class HelpPage:
|
||||
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)
|
||||
|
@ -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",
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user