File tree Expand file tree Collapse file tree 6 files changed +53
-2
lines changed Expand file tree Collapse file tree 6 files changed +53
-2
lines changed Original file line number Diff line number Diff line change 1212from guardrails .cli .hub .console import console
1313from guardrails .cli .server .hub_client import AuthenticationError , get_auth
1414from guardrails .cli .telemetry import trace_if_enabled
15-
15+ from guardrails . cli . version import version_warnings_if_applicable
1616
1717DEFAULT_TOKEN = ""
1818DEFAULT_ENABLE_METRICS = True
@@ -78,6 +78,7 @@ def configure(
7878 help = "Clear the existing token from the configuration file." ,
7979 ),
8080):
81+ version_warnings_if_applicable (console )
8182 trace_if_enabled ("configure" )
8283 existing_token = _get_default_token ()
8384 last4 = existing_token [- 4 :] if existing_token else ""
Original file line number Diff line number Diff line change 55
66from guardrails .cli .hub .hub import hub_command
77from guardrails .cli .logger import logger
8+ from guardrails .cli .hub .console import console
89from guardrails .cli .telemetry import trace_if_enabled
10+ from guardrails .cli .version import version_warnings_if_applicable
911
1012
1113@hub_command .command ()
@@ -40,6 +42,8 @@ def confirm():
4042 " local models for local inference?" ,
4143 )
4244
45+ version_warnings_if_applicable (console )
46+
4347 install_multiple (
4448 package_uris ,
4549 install_local_models = local_models ,
Original file line number Diff line number Diff line change 55from guardrails .cli .hub .utils import pip_process
66from guardrails .cli .logger import logger
77from guardrails .cli .telemetry import trace_if_enabled
8+ from guardrails .cli .version import version_warnings_if_applicable
9+ from guardrails .cli .hub .console import console
810
911
1012def api_is_installed () -> bool :
@@ -39,5 +41,6 @@ def start(
3941 from guardrails_api .cli .start import start # type: ignore
4042
4143 logger .info ("Starting Guardrails server" )
44+ version_warnings_if_applicable (console )
4245 trace_if_enabled ("start" )
4346 start (env , config , port )
Original file line number Diff line number Diff line change 1+ import contextlib
2+ import requests
3+ import semver
4+ from importlib .metadata import version
5+ from rich .console import Console
6+
7+
8+ GUARDRAILS_PACKAGE_NAME = "guardrails-ai"
9+
10+
11+ def get_guardrails_version ():
12+ return version (GUARDRAILS_PACKAGE_NAME )
13+
14+
15+ def version_warnings_if_applicable (console : Console ):
16+ current_version = get_guardrails_version ()
17+
18+ with contextlib .suppress (Exception ):
19+ res = requests .get (f"https://pypi.org/pypi/{ GUARDRAILS_PACKAGE_NAME } /json" )
20+ version_info = res .json ()
21+ info = version_info .get ("info" , {})
22+ latest_version = info .get ("version" )
23+
24+ is_update_available = semver .compare (latest_version , current_version ) > 0
25+
26+ if is_update_available :
27+ console .print (
28+ "[yellow]There is a newer version of Guardrails "
29+ f"available { latest_version } . Your current version "
30+ f"is { current_version } [/yellow]!"
31+ )
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ diff-match-patch = "^20230430"
6161guardrails-api = " >=0.0.1"
6262mlflow = {version = " >=2.0.1" , optional = true }
6363uvloop = {version = " ^0.20.0" , optional = true }
64+ semver = " ^3.0.2"
6465
6566[tool .poetry .extras ]
6667sql = [" sqlvalidator" , " sqlalchemy" , " sqlglot" ]
You can’t perform that action at this time.
0 commit comments