-
Notifications
You must be signed in to change notification settings - Fork 567
refactor(streaming)!: drop streaming field from config #1538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
01e1fab to
912fcba
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Greptile OverviewGreptile SummaryThis PR refactors streaming functionality from a static configuration field to a per-request capability, removing the deprecated Key Changes:
Impact:
|
| Filename | Score | Overview |
|---|---|---|
| nemoguardrails/cli/chat.py | 4/5 | Improved error handling for streaming with better user-facing error messages; removed early streaming validation check |
| nemoguardrails/rails/llm/config.py | 5/5 | Removed deprecated streaming field and streaming_supported property from RailsConfig |
| nemoguardrails/rails/llm/llmrails.py | 4/5 | Moved streaming configuration to stream_async() call site; removed main_llm_supports_streaming flag; stream_usage now always enabled |
| nemoguardrails/server/api.py | 4/5 | Simplified streaming API to use stream_async() directly instead of generate_async() with streaming_handler |
Sequence Diagram
sequenceDiagram
participant User
participant CLI/API
participant LLMRails
participant Config
participant LLM
Note over User,LLM: Before: Streaming configured in config.yml
User->>CLI/API: Request with streaming flag
CLI/API->>Config: Check streaming_supported
Config-->>CLI/API: Return boolean
CLI/API->>LLMRails: Check main_llm_supports_streaming
alt streaming not supported
CLI/API->>User: WARNING: fallback to normal mode
else streaming supported
CLI/API->>LLMRails: generate_async(streaming_handler)
LLMRails->>LLM: Generate with streaming
LLM-->>CLI/API: Stream chunks
end
Note over User,LLM: After: Streaming enabled per request
User->>CLI/API: Request with streaming flag
CLI/API->>LLMRails: stream_async(messages)
LLMRails->>LLMRails: _validate_streaming_with_output_rails()
alt output rails without streaming config
LLMRails-->>CLI/API: Raise InvalidRailsConfigurationError
CLI/API-->>User: Helpful error message with fix instructions
else valid configuration
LLMRails->>LLMRails: _configure_main_llm_streaming(llm)
LLMRails->>LLM: Set streaming=True attribute
LLMRails->>LLMRails: generate_async(streaming_handler)
LLM-->>CLI/API: Stream chunks
CLI/API-->>User: Display chunks
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (7)
-
examples/configs/streaming/config.yml, line 17 (link)syntax: The
streaming: Truefield has been removed fromRailsConfigin this PR. This configuration file needs to be updated to remove this line. -
examples/configs/llm/hf_pipeline_dolly/config.yml, line 6 (link)syntax: The
streaming: Truefield has been removed fromRailsConfig. This configuration file needs to be updated. -
examples/configs/gs_content_safety/config/config.yml, line 22 (link)syntax: The
streaming: Truefield has been removed fromRailsConfig. This configuration file needs to be updated. -
examples/scripts/demo_streaming.py, line 38 (link)syntax: The
streaming: Truefield has been removed fromRailsConfig. This example code needs to be updated to remove this line from the YAML configuration. -
examples/scripts/demo_streaming.py, line 103 (link)syntax: The
streaming: Truefield has been removed fromRailsConfig. Remove this line from the YAML configuration. -
docs/configure-rails/yaml-schema/streaming/global-streaming.md, line 1-162 (link)syntax: This entire documentation page describes the
streaming: Truefield which has been removed fromRailsConfig. The page needs to be either removed or completely rewritten to reflect the new streaming behavior where streaming is enabled per-request via thestream_async()method rather than through global configuration. -
examples/notebooks/generate_events_and_streaming.ipynb, line 71 (link)syntax: The
streaming: Truefield has been removed fromRailsConfig. This notebook needs to be updated to remove this configuration line.
15 files reviewed, 7 comments
| # providers that don't support this parameter will simply ignore it | ||
| if self.config.streaming: | ||
| kwargs["stream_usage"] = True | ||
| kwargs["stream_usage"] = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pouyanpi : we can move this later to llm_call when we drop the streaming callback handler feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
15 files reviewed, 1 comment
- Remove `streaming` and `streaming_supported` properties from RailsConfig - Add `StreamingNotSupportedError` exception for clearer error handling - Move streaming validation from config-time to runtime in LLMRails - Remove `main_llm_supports_streaming` flag and related logic - Update CLI to catch StreamingNotSupportedError instead of pre-checking - Simplify server API streaming logic to use stream_async directly - Configure LLM streaming only when stream_async is called - Remove redundant streaming warnings and fallback logic BREAKING CHANGE: `RailsConfig.streaming` and `RailsConfig.streaming_supported` properties have been removed. Streaming support is now validated at runtime when `stream_async()` is called.
- Remove RailsConfig.streaming references from all tests - Update streaming tests to use StreamingNotSupportedError - Remove tests for deprecated streaming_supported property - Remove tests for main_llm_supports_streaming flag - Update CLI tests to verify StreamingNotSupportedError handling - Simplify test fixtures to remove streaming config parameters - Update token usage tests to reflect stream_usage always enabled - Fix test mocks to align with new streaming validation approach
Replace InvalidRailsConfigurationError with a new, more specific StreamingNotSupportedError for cases where streaming is requested but not supported by the configuration. Update all relevant imports, usages, and tests to use the new exception. This improves error clarity and guidance for users encountering streaming configuration issues.
6ab6f6e to
220cbd8
Compare
feature: #1538 Revise streaming docs to clarify usage of stream_async(), remove outdated global streaming config, and add CLI usage instructions. Explain output rails streaming requirements and deprecation of StreamingHandler. Improve examples and guidance for token usage tracking.
Description
streaming is enalbed per request:
via
stream_asyncmethodvia chat CLI (--streaming)
(we still support streaming when
StremingHandleris used with generate_async and generate_events_async for backward compatibility)the error message:
Documentation:
#1542