diff options
Diffstat (limited to 'g4f/version.py')
-rw-r--r-- | g4f/version.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/g4f/version.py b/g4f/version.py index 44d14369..bb4b7f17 100644 --- a/g4f/version.py +++ b/g4f/version.py @@ -5,6 +5,15 @@ from importlib.metadata import version as get_package_version, PackageNotFoundEr from subprocess import check_output, CalledProcessError, PIPE from .errors import VersionNotFoundError +def get_latest_version() -> str: + try: + get_package_version("g4f") + response = requests.get("https://pypi.org/pypi/g4f/json").json() + return response["info"]["version"] + except PackageNotFoundError: + url = "https://api.github.com/repos/xtekky/gpt4free/releases/latest" + response = requests.get(url).json() + return response["tag_name"] class VersionUtils(): @cached_property @@ -28,20 +37,13 @@ class VersionUtils(): @cached_property def latest_version(self) -> str: - try: - get_package_version("g4f") - response = requests.get("https://pypi.org/pypi/g4f/json").json() - return response["info"]["version"] - except PackageNotFoundError: - url = "https://api.github.com/repos/xtekky/gpt4free/releases/latest" - response = requests.get(url).json() - return response["tag_name"] - - def check_pypi_version(self) -> None: + return get_latest_version() + + def check_version(self) -> None: try: if self.current_version != self.latest_version: - print(f'New pypi version: {self.latest_version} (current: {self.current_version}) | pip install -U g4f') + print(f'New g4f version: {self.latest_version} (current: {self.current_version}) | pip install -U g4f') except Exception as e: - print(f'Failed to check g4f pypi version: {e}') + print(f'Failed to check g4f version: {e}') utils = VersionUtils()
\ No newline at end of file |