File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change 44import sys
55from typing import Any
66
7+ from askui .chat .api .dependencies import get_settings
78from askui .chat .api .runs .events .events import Event
89
910
1011class IOPublisher :
1112 """Publisher that serializes events to JSON and writes to stdout."""
1213
14+ def __init__ (self ) -> None :
15+ """Initialize the IO publisher."""
16+ settings = get_settings ()
17+ self ._enabled = settings .enable_io_events
18+
1319 def publish (self , event : Event ) -> None :
1420 """
1521 Publish an event by serializing it to JSON and writing to stdout.
1622
23+ If the publisher is disabled, this method does nothing.
24+
1725 Args:
1826 event: The event to publish
1927 """
28+ if not self ._enabled :
29+ return
30+
2031 try :
2132 event_dict : dict [str , Any ] = event .model_dump (mode = "json" )
2233 event_json = json .dumps (event_dict )
Original file line number Diff line number Diff line change @@ -118,3 +118,7 @@ class Settings(BaseSettings):
118118 default_factory = OtelSettings ,
119119 description = "OpenTelemetry configuration settings" ,
120120 )
121+ enable_io_events : bool = Field (
122+ default = False ,
123+ description = "Whether to enable the publishing events to stdout" ,
124+ )
You can’t perform that action at this time.
0 commit comments