summaryrefslogtreecommitdiffstats
path: root/g4f/version.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-22 00:16:58 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-22 00:16:58 +0100
commite5b7f72b719814ffa2748e8e8ed1c6713a24e1a6 (patch)
tree70e9f87cb18f165428492d53a1c6e28c0828490a /g4f/version.py
parentUpdate docs / readme, Improve Gemini auth (diff)
downloadgpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.gz
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.bz2
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.lz
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.xz
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.tar.zst
gpt4free-e5b7f72b719814ffa2748e8e8ed1c6713a24e1a6.zip
Diffstat (limited to '')
-rw-r--r--g4f/version.py31
1 files changed, 10 insertions, 21 deletions
diff --git a/g4f/version.py b/g4f/version.py
index 63941baf..0d85a7f5 100644
--- a/g4f/version.py
+++ b/g4f/version.py
@@ -7,6 +7,9 @@ from importlib.metadata import version as get_package_version, PackageNotFoundEr
from subprocess import check_output, CalledProcessError, PIPE
from .errors import VersionNotFoundError
+PACKAGE_NAME = "g4f"
+GITHUB_REPOSITORY = "xtekky/gpt4free"
+
def get_pypi_version(package_name: str) -> str:
"""
Retrieves the latest version of a package from PyPI.
@@ -45,25 +48,6 @@ def get_github_version(repo: str) -> str:
except requests.RequestException as e:
raise VersionNotFoundError(f"Failed to get GitHub release version: {e}")
-def get_latest_version() -> str:
- """
- Retrieves the latest release version of the 'g4f' package from PyPI or GitHub.
-
- Returns:
- str: The latest release version of 'g4f'.
-
- Note:
- The function first tries to fetch the version from PyPI. If the package is not found,
- it retrieves the version from the GitHub repository.
- """
- try:
- # Is installed via package manager?
- get_package_version("g4f")
- return get_pypi_version("g4f")
- except PackageNotFoundError:
- # Else use Github version:
- return get_github_version("xtekky/gpt4free")
-
class VersionUtils:
"""
Utility class for managing and comparing package versions of 'g4f'.
@@ -82,7 +66,7 @@ class VersionUtils:
"""
# Read from package manager
try:
- return get_package_version("g4f")
+ return get_package_version(PACKAGE_NAME)
except PackageNotFoundError:
pass
@@ -108,7 +92,12 @@ class VersionUtils:
Returns:
str: The latest version of 'g4f'.
"""
- return get_latest_version()
+ # Is installed via package manager?
+ try:
+ get_package_version(PACKAGE_NAME)
+ except PackageNotFoundError:
+ return get_github_version(GITHUB_REPOSITORY)
+ return get_pypi_version(PACKAGE_NAME)
def check_version(self) -> None:
"""