summaryrefslogtreecommitdiffstats
path: root/g4f/debug.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2023-12-11 00:56:06 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2023-12-11 00:56:06 +0100
commitd743ee0c26f00916233d751f2f375be414487d49 (patch)
tree4377351363d186fefdf7d1eed27a4fde39f173a3 /g4f/debug.py
parentImprove error handling in gui (diff)
downloadgpt4free-d743ee0c26f00916233d751f2f375be414487d49.tar
gpt4free-d743ee0c26f00916233d751f2f375be414487d49.tar.gz
gpt4free-d743ee0c26f00916233d751f2f375be414487d49.tar.bz2
gpt4free-d743ee0c26f00916233d751f2f375be414487d49.tar.lz
gpt4free-d743ee0c26f00916233d751f2f375be414487d49.tar.xz
gpt4free-d743ee0c26f00916233d751f2f375be414487d49.tar.zst
gpt4free-d743ee0c26f00916233d751f2f375be414487d49.zip
Diffstat (limited to 'g4f/debug.py')
-rw-r--r--g4f/debug.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/g4f/debug.py b/g4f/debug.py
index 984d973a..85009277 100644
--- a/g4f/debug.py
+++ b/g4f/debug.py
@@ -1,2 +1,39 @@
+from os import environ
+from requests import get
+from importlib.metadata import version, PackageNotFoundError
+from subprocess import check_output, CalledProcessError, PIPE
+from .errors import VersionNotFoundError
+
logging = False
-version_check = True \ No newline at end of file
+version_check = True
+
+def get_version() -> str:
+ # Read from package manager
+ try:
+ return version("g4f")
+ except PackageNotFoundError:
+ pass
+ # Read from docker environment
+ current_version = environ.get("G4F_VERSION")
+ if current_version:
+ return current_version
+ # Read from git repository
+ try:
+ command = ["git", "describe", "--tags", "--abbrev=0"]
+ return check_output(command, text=True, stderr=PIPE).strip()
+ except CalledProcessError:
+ pass
+ raise VersionNotFoundError("Version not found")
+
+def get_lastet_version() -> str:
+ response = get("https://pypi.org/pypi/g4f/json").json()
+ return response["info"]["version"]
+
+def check_pypi_version() -> None:
+ try:
+ version = get_version()
+ latest_version = get_lastet_version()
+ except Exception as e:
+ print(f'Failed to check g4f pypi version: {e}')
+ if version != latest_version:
+ print(f'New pypi version: {latest_version} (current: {version}) | pip install -U g4f') \ No newline at end of file