Skip to content

Commit 704b6d4

Browse files
committed
Merged #1410. Patch coverage 100% -> 72%
2 parents c0ef65e + 0c868c6 commit 704b6d4

File tree

6 files changed

+287
-75
lines changed

6 files changed

+287
-75
lines changed

nemoguardrails/context.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414
# limitations under the License.
1515

1616
import contextvars
17-
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
18-
19-
from nemoguardrails.logging.explain import LLMCallInfo
17+
from typing import TYPE_CHECKING, Any, Dict, List, Optional
2018

2119
if TYPE_CHECKING:
2220
from nemoguardrails.logging.explain import ExplainInfo
23-
from nemoguardrails.logging.stats import LLMStats
24-
from nemoguardrails.rails.llm.options import GenerationOptions
21+
from nemoguardrails.rails.llm.options import GenerationOptions, LLMStats
2522
from nemoguardrails.streaming import StreamingHandler
2623

2724
streaming_handler_var: contextvars.ContextVar[
@@ -34,9 +31,9 @@
3431
] = contextvars.ContextVar("explain_info", default=None)
3532

3633
# The current LLM call.
37-
llm_call_info_var: contextvars.ContextVar[
38-
Optional[LLMCallInfo]
39-
] = contextvars.ContextVar("llm_call_info", default=None)
34+
llm_call_info_var: contextvars.ContextVar[Optional[str]] = contextvars.ContextVar(
35+
"llm_call_info", default=None
36+
)
4037

4138
# All the generation options applicable to the current context.
4239
generation_options_var: contextvars.ContextVar[
@@ -50,9 +47,9 @@
5047

5148
# The raw LLM request that comes from the user.
5249
# This is used in passthrough mode.
53-
raw_llm_request: contextvars.ContextVar[
54-
Optional[Union[str, List[Dict[str, Any]]]]
55-
] = contextvars.ContextVar("raw_llm_request", default=None)
50+
raw_llm_request: contextvars.ContextVar[Optional[Any]] = contextvars.ContextVar(
51+
"raw_llm_request", default=None
52+
)
5653

5754
reasoning_trace_var: contextvars.ContextVar[Optional[str]] = contextvars.ContextVar(
5855
"reasoning_trace", default=None

nemoguardrails/rails/llm/buffer.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ def format_chunks(self, chunks: List[str]) -> str:
114114
...
115115

116116
@abstractmethod
117-
async def process_stream(
118-
self, streaming_handler
119-
) -> AsyncGenerator[ChunkBatch, None]:
117+
async def process_stream(self, streaming_handler):
120118
"""Process streaming chunks and yield chunk batches.
121119
122120
This is the main method that concrete buffer strategies must implement.
@@ -141,8 +139,7 @@ async def process_stream(
141139
... print(f"Processing: {context_formatted}")
142140
... print(f"User: {user_formatted}")
143141
"""
144-
raise NotImplementedError # pragma: no cover
145-
yield
142+
yield ChunkBatch([], []) # pragma: no cover
146143

147144
async def __call__(self, streaming_handler):
148145
"""Callable interface that delegates to process_stream.

nemoguardrails/rails/llm/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ def streaming_supported(self):
17501750
# if we have output rails streaming enabled
17511751
# we keep it in case it was needed when we have
17521752
# support per rails
1753-
if self.rails.output.streaming.enabled:
1753+
if self.rails.output.streaming and self.rails.output.streaming.enabled:
17541754
return True
17551755
return False
17561756

0 commit comments

Comments
 (0)