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 7
7
from guardrails .cli .telemetry import trace_if_enabled
8
8
from guardrails .cli .version import version_warnings_if_applicable
9
9
from guardrails .cli .hub .console import console
10
+ from guardrails .settings import settings
10
11
11
12
12
13
def api_is_installed () -> bool :
@@ -32,15 +33,22 @@ def start(
32
33
default = 8000 ,
33
34
help = "The port to run the server on." ,
34
35
),
36
+ watch : bool = typer .Option (
37
+ default = False , is_flag = True , help = "Enable watch mode for logs."
38
+ ),
35
39
):
36
40
logger .debug ("Checking for prerequisites..." )
37
41
if not api_is_installed ():
38
42
package_name = 'guardrails-api>="^0.0.0a0"'
39
43
pip_process ("install" , package_name )
40
44
41
- from guardrails_api .cli .start import start # type: ignore
45
+ from guardrails_api .cli .start import start as start_api # type: ignore
42
46
43
47
logger .info ("Starting Guardrails server" )
48
+
49
+ if watch :
50
+ settings ._watch_mode_enabled = True
51
+
44
52
version_warnings_if_applicable (console )
45
53
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 7
7
import rich
8
8
import typer
9
9
10
+ from guardrails .settings import settings
10
11
from guardrails .cli .guardrails import guardrails as gr_cli
11
12
from guardrails .call_tracing import GuardTraceEntry , TraceHandler
12
13
from guardrails .cli .telemetry import trace_if_enabled
@@ -31,6 +32,7 @@ def watch_command(
31
32
default = False , is_flag = True , help = "Clear all log outputs and exit."
32
33
),
33
34
):
35
+ settings ._watch_mode_enabled = True
34
36
trace_if_enabled ("watch" )
35
37
if clear :
36
38
_clear_and_quit ()
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class Settings:
8
8
_instance = None
9
9
_lock = threading .Lock ()
10
10
_rc : RC
11
+ _watch_mode_enabled : bool
11
12
"""Whether to use a local server for running Guardrails."""
12
13
use_server : Optional [bool ]
13
14
"""Whether to disable tracing.
@@ -29,6 +30,7 @@ def _initialize(self):
29
30
self .use_server = None
30
31
self .disable_tracing = None
31
32
self ._rc = RC .load ()
33
+ self ._watch_mode_enabled = False
32
34
33
35
@property
34
36
def rc (self ) -> RC :
@@ -40,5 +42,9 @@ def rc(self) -> RC:
40
42
def rc (self , value : RC ):
41
43
self ._rc = value
42
44
45
+ @property
46
+ def watch_mode_enabled (self ) -> bool :
47
+ return self ._watch_mode_enabled
48
+
43
49
44
50
settings = Settings ()
Original file line number Diff line number Diff line change 5
5
from guardrails .actions .refrain import Refrain
6
6
from guardrails .call_tracing .trace_handler import TraceHandler
7
7
from guardrails .classes .validation .validator_logs import ValidatorLogs
8
+ from guardrails .settings import settings
8
9
from guardrails .telemetry .common import get_span
9
10
from guardrails .utils .casting_utils import to_string
10
11
@@ -68,7 +69,8 @@ def trace_validator_result(
68
69
** kwargs ,
69
70
}
70
71
71
- TraceHandler ().log_validator (validator_log )
72
+ if settings .watch_mode_enabled :
73
+ TraceHandler ().log_validator (validator_log )
72
74
73
75
current_span .add_event (
74
76
f"{ validator_name } _result" ,
@@ -85,6 +87,6 @@ def trace_validation_result(
85
87
current_span = None ,
86
88
):
87
89
_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 :
89
91
for log in validation_logs :
90
92
trace_validator_result (_current_span , log , attempt_number )
You can’t perform that action at this time.
0 commit comments