Skip to content

Commit 6374198

Browse files
committed
refactor: update streaming config and handling
- Removed `enabled` flag from `examples/configs/abc_streaming/config.yml` - Updated `generation.py` to check for output flows instead of the `enabled` flag - Fixed typo in `llmrails.py` and updated streaming handling logic
1 parent 01805e4 commit 6374198

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

examples/configs/abc_streaming/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ rails:
3030
flows:
3131
- self check output
3232
streaming:
33-
enabled: True
3433
window_size: 20
3534

3635
dialog:

nemoguardrails/actions/llm/generation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,9 @@ async def generate_bot_message(
767767
# as it is executed separately in llmrails.py
768768
# of course, it does not work when passed as context in `run_output_rails_in_streaming`
769769
# streaming_handler is set when stream_async method is used
770-
if streaming_handler and self.config.rails.output.streaming.enabled:
770+
771+
if streaming_handler and len(self.config.rails.output.flows) > 0:
772+
# if streaming_handler and self.config.rails.output.streaming.enabled:
771773
context_updates["skip_output_rails"] = True
772774

773775
if bot_intent in self.config.bot_messages:

nemoguardrails/rails/llm/config.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,15 +1219,15 @@ def parse_object(cls, obj):
12191219

12201220
@property
12211221
def streaming_supported(self):
1222-
"""Whether the current config supports streaming or not.
1223-
1224-
Currently, we don't support streaming if there are output rails.
1225-
"""
1226-
if len(self.rails.output.flows) > 0:
1227-
# if we have output rails streaming enabled
1228-
if self.rails.output.streaming.enabled:
1229-
return True
1230-
return False
1222+
"""Whether the current config supports streaming or not."""
1223+
1224+
# if len(self.rails.output.flows) > 0:
1225+
# # if we have output rails streaming enabled
1226+
# # we keep it in case it was needed when we have
1227+
# # support per rails
1228+
# if self.rails.output.streaming.enabled:
1229+
# return True
1230+
# return False
12311231

12321232
return True
12331233

nemoguardrails/rails/llm/llmrails.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def _init_llms(self):
418418
self.runtime.register_action_param(
419419
model_name, getattr(self, model_name)
420420
)
421-
# this is used for cotnent safety and topic control
421+
# this is used for content safety and topic control
422422
llms[llm_config.type] = getattr(self, model_name)
423423

424424
self.runtime.register_action_param("llms", llms)
@@ -953,7 +953,11 @@ def stream_async(
953953
options=options,
954954
)
955955
)
956-
if self.config.rails.output.streaming.enabled:
956+
# TODO:
957+
# when we have output rails we wrap the streaming handler
958+
if len(self.config.rails.output.flows) > 0:
959+
#
960+
# if self.config.rails.output.streaming.enabled:
957961
# returns an async generator
958962
return self._run_output_rails_in_streaming(
959963
streaming_handler=streaming_handler,

0 commit comments

Comments
 (0)