File tree Expand file tree Collapse file tree 4 files changed +22
-4
lines changed
Expand file tree Collapse file tree 4 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 77from guardrails .cli .telemetry import trace_if_enabled
88from guardrails .cli .version import version_warnings_if_applicable
99from guardrails .cli .hub .console import console
10+ from guardrails .settings import settings
1011
1112
1213def api_is_installed () -> bool :
@@ -32,15 +33,22 @@ def start(
3233 default = 8000 ,
3334 help = "The port to run the server on." ,
3435 ),
36+ watch : bool = typer .Option (
37+ default = False , is_flag = True , help = "Enable watch mode for logs."
38+ ),
3539):
3640 logger .debug ("Checking for prerequisites..." )
3741 if not api_is_installed ():
3842 package_name = 'guardrails-api>="^0.0.0a0"'
3943 pip_process ("install" , package_name )
4044
41- from guardrails_api .cli .start import start # type: ignore
45+ from guardrails_api .cli .start import start as start_api # type: ignore
4246
4347 logger .info ("Starting Guardrails server" )
48+
49+ if watch :
50+ settings ._watch_mode_enabled = True
51+
4452 version_warnings_if_applicable (console )
4553 trace_if_enabled ("start" )
46- start (env , config , port )
54+ start_api (env , config , port )
Original file line number Diff line number Diff line change 77import rich
88import typer
99
10+ from guardrails .settings import settings
1011from guardrails .cli .guardrails import guardrails as gr_cli
1112from guardrails .call_tracing import GuardTraceEntry , TraceHandler
1213from guardrails .cli .telemetry import trace_if_enabled
@@ -31,6 +32,7 @@ def watch_command(
3132 default = False , is_flag = True , help = "Clear all log outputs and exit."
3233 ),
3334):
35+ settings ._watch_mode_enabled = True
3436 trace_if_enabled ("watch" )
3537 if clear :
3638 _clear_and_quit ()
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class Settings:
88 _instance = None
99 _lock = threading .Lock ()
1010 _rc : RC
11+ _watch_mode_enabled : bool
1112 """Whether to use a local server for running Guardrails."""
1213 use_server : Optional [bool ]
1314 """Whether to disable tracing.
@@ -29,6 +30,7 @@ def _initialize(self):
2930 self .use_server = None
3031 self .disable_tracing = None
3132 self ._rc = RC .load ()
33+ self ._watch_mode_enabled = False
3234
3335 @property
3436 def rc (self ) -> RC :
@@ -40,5 +42,9 @@ def rc(self) -> RC:
4042 def rc (self , value : RC ):
4143 self ._rc = value
4244
45+ @property
46+ def watch_mode_enabled (self ) -> bool :
47+ return self ._watch_mode_enabled
48+
4349
4450settings = Settings ()
Original file line number Diff line number Diff line change 55from guardrails .actions .refrain import Refrain
66from guardrails .call_tracing .trace_handler import TraceHandler
77from guardrails .classes .validation .validator_logs import ValidatorLogs
8+ from guardrails .settings import settings
89from guardrails .telemetry .common import get_span
910from guardrails .utils .casting_utils import to_string
1011
@@ -68,7 +69,8 @@ def trace_validator_result(
6869 ** kwargs ,
6970 }
7071
71- TraceHandler ().log_validator (validator_log )
72+ if settings .watch_mode_enabled :
73+ TraceHandler ().log_validator (validator_log )
7274
7375 current_span .add_event (
7476 f"{ validator_name } _result" ,
@@ -85,6 +87,6 @@ def trace_validation_result(
8587 current_span = None ,
8688):
8789 _current_span = get_span (current_span )
88- if _current_span is not None :
90+ if _current_span is not None and not settings . disable_tracing :
8991 for log in validation_logs :
9092 trace_validator_result (_current_span , log , attempt_number )
You can’t perform that action at this time.
0 commit comments