Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f15ce67
Check in rails/ type-fixes
tgasser-nv Sep 15, 2025
7424e88
Add coverage to rails/llm/options.py
tgasser-nv Sep 22, 2025
747b540
Add coverage to _configure_main_llm_streaming()
tgasser-nv Sep 22, 2025
74a0cab
Added test coverage for nemoguardrails/rails/llm/config.py
tgasser-nv Sep 23, 2025
ec00d0f
Pass OutputRailsStreamingConfig into _run_output_rails_in_streaming …
tgasser-nv Sep 23, 2025
6948258
Add coverage to explain_info()
tgasser-nv Sep 23, 2025
0c4dc8e
Fix rebase mistake where _create_isolated_llms_for_actions() was stil…
tgasser-nv Sep 23, 2025
ba4504e
Add pre-and-post LLM call count to work around FakeLLM / TestChat rac…
tgasser-nv Sep 23, 2025
3513d70
Address feedback from Pouyan and Traian
tgasser-nv Sep 23, 2025
c0ef65e
Forgot to simplify the line 1753 in rails/llm/config.py
tgasser-nv Sep 23, 2025
b87fb4a
Dummy commit to set up the chore/type-clean-guardrails PR and branch
tgasser-nv Sep 2, 2025
7784ac3
Check in rails/ type-fixes
tgasser-nv Sep 15, 2025
bcb522d
Revert "Dummy commit to set up the chore/type-clean-guardrails PR and…
tgasser-nv Sep 22, 2025
3673cc1
Add coverage to rails/llm/options.py
tgasser-nv Sep 22, 2025
ecd87ca
Add coverage to _configure_main_llm_streaming()
tgasser-nv Sep 22, 2025
483c547
Pass OutputRailsStreamingConfig into _run_output_rails_in_streaming …
tgasser-nv Sep 23, 2025
5e46e5a
review: type hint fixes
Pouyanpi Sep 23, 2025
a278144
Fixed bad merge of GenerationOptions in llmrails.py (code referred to…
tgasser-nv Sep 24, 2025
e482617
Add pre-commit pyright hook for nemoguardrails/rails/
tgasser-nv Sep 24, 2025
244ff73
Regenerate poetry.lock
tgasser-nv Sep 24, 2025
360f4ac
revert to original state at HEAD of develop and fix the type hint
Pouyanpi Sep 24, 2025
f0bc730
delete duplicate test
Pouyanpi Sep 24, 2025
d9c0358
fix black style
Pouyanpi Sep 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ repos:
args:
- --license-filepath
- LICENSE.md

- repo: local
hooks:
- id: pyright
name: pyright
entry: poetry run pyright
language: system
types: [python]
pass_filenames: false
# Deactivating this for now.
# - repo: https://github.com/pycqa/pylint
# rev: v2.17.0
Expand Down
2 changes: 1 addition & 1 deletion nemoguardrails/actions/llm/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class LLMGenerationActions:
def __init__(
self,
config: RailsConfig,
llm: Union[BaseLLM, BaseChatModel],
llm: Optional[Union[BaseLLM, BaseChatModel]],
llm_task_manager: LLMTaskManager,
get_embedding_search_provider_instance: Callable[
[Optional[EmbeddingSearchProvider]], EmbeddingsIndex
Expand Down
34 changes: 27 additions & 7 deletions nemoguardrails/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,45 @@
# limitations under the License.

import contextvars
from typing import Optional
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union

streaming_handler_var = contextvars.ContextVar("streaming_handler", default=None)
from nemoguardrails.logging.explain import LLMCallInfo

if TYPE_CHECKING:
from nemoguardrails.logging.explain import ExplainInfo
from nemoguardrails.logging.stats import LLMStats
from nemoguardrails.rails.llm.options import GenerationOptions
from nemoguardrails.streaming import StreamingHandler

streaming_handler_var: contextvars.ContextVar[
Optional["StreamingHandler"]
] = contextvars.ContextVar("streaming_handler", default=None)

# The object that holds additional explanation information.
explain_info_var = contextvars.ContextVar("explain_info", default=None)
explain_info_var: contextvars.ContextVar[
Optional["ExplainInfo"]
] = contextvars.ContextVar("explain_info", default=None)

# The current LLM call.
llm_call_info_var = contextvars.ContextVar("llm_call_info", default=None)
llm_call_info_var: contextvars.ContextVar[
Optional[LLMCallInfo]
] = contextvars.ContextVar("llm_call_info", default=None)

# All the generation options applicable to the current context.
generation_options_var = contextvars.ContextVar("generation_options", default=None)
generation_options_var: contextvars.ContextVar[
Optional["GenerationOptions"]
] = contextvars.ContextVar("generation_options", default=None)

# The stats about the LLM calls.
llm_stats_var = contextvars.ContextVar("llm_stats", default=None)
llm_stats_var: contextvars.ContextVar[Optional["LLMStats"]] = contextvars.ContextVar(
"llm_stats", default=None
)

# The raw LLM request that comes from the user.
# This is used in passthrough mode.
raw_llm_request = contextvars.ContextVar("raw_llm_request", default=None)
raw_llm_request: contextvars.ContextVar[
Optional[Union[str, List[Dict[str, Any]]]]
] = contextvars.ContextVar("raw_llm_request", default=None)

reasoning_trace_var: contextvars.ContextVar[Optional[str]] = contextvars.ContextVar(
"reasoning_trace", default=None
Expand Down
3 changes: 2 additions & 1 deletion nemoguardrails/rails/llm/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ async def process_stream(
... print(f"Processing: {context_formatted}")
... print(f"User: {user_formatted}")
"""
...
raise NotImplementedError
yield

async def __call__(self, streaming_handler) -> AsyncGenerator[ChunkBatch, None]:
"""Callable interface that delegates to process_stream.
Expand Down
10 changes: 6 additions & 4 deletions nemoguardrails/rails/llm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class OutputRails(BaseModel):
description="The names of all the flows that implement output rails.",
)

streaming: Optional[OutputRailsStreamingConfig] = Field(
streaming: OutputRailsStreamingConfig = Field(
default_factory=OutputRailsStreamingConfig,
description="Configuration for streaming output rails.",
)
Expand Down Expand Up @@ -1128,7 +1128,9 @@ def _load_path(

# the first .railsignore file found from cwd down to its subdirectories
railsignore_path = utils.get_railsignore_path(config_path)
ignore_patterns = utils.get_railsignore_patterns(railsignore_path)
ignore_patterns = (
utils.get_railsignore_patterns(railsignore_path) if railsignore_path else set()
)

if os.path.isdir(config_path):
for root, _, files in os.walk(config_path, followlinks=True):
Expand Down Expand Up @@ -1245,8 +1247,8 @@ def _parse_colang_files_recursively(
current_file, current_path = colang_files[len(parsed_colang_files)]

with open(current_path, "r", encoding="utf-8") as f:
content = f.read()
try:
content = f.read()
_parsed_config = parse_colang_file(
current_file, content=content, version=colang_version
)
Expand Down Expand Up @@ -1748,7 +1750,7 @@ def streaming_supported(self):
# if we have output rails streaming enabled
# we keep it in case it was needed when we have
# support per rails
if self.rails.output.streaming.enabled:
if self.rails.output.streaming and self.rails.output.streaming.enabled:
return True
return False

Expand Down
Loading