Skip to content

Commit 360f4ac

Browse files
committed
revert to original state at HEAD of develop and fix the type hint
1 parent 244ff73 commit 360f4ac

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

nemoguardrails/rails/llm/buffer.py

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

1616
from abc import ABC, abstractmethod
17-
from typing import TYPE_CHECKING, AsyncGenerator, List, NamedTuple
18-
19-
if TYPE_CHECKING:
20-
from collections.abc import AsyncIterator
17+
from typing import AsyncGenerator, List, NamedTuple
2118

2219
from nemoguardrails.rails.llm.config import OutputRailsStreamingConfig
2320

@@ -114,7 +111,9 @@ def format_chunks(self, chunks: List[str]) -> str:
114111
...
115112

116113
@abstractmethod
117-
async def process_stream(self, streaming_handler):
114+
async def process_stream(
115+
self, streaming_handler
116+
) -> AsyncGenerator[ChunkBatch, None]:
118117
"""Process streaming chunks and yield chunk batches.
119118
120119
This is the main method that concrete buffer strategies must implement.
@@ -139,9 +138,10 @@ async def process_stream(self, streaming_handler):
139138
... print(f"Processing: {context_formatted}")
140139
... print(f"User: {user_formatted}")
141140
"""
142-
yield ChunkBatch([], []) # pragma: no cover
141+
raise NotImplementedError
142+
yield
143143

144-
async def __call__(self, streaming_handler):
144+
async def __call__(self, streaming_handler) -> AsyncGenerator[ChunkBatch, None]:
145145
"""Callable interface that delegates to process_stream.
146146
147147
It delegates to the `process_stream` method and can
@@ -257,7 +257,9 @@ def from_config(cls, config: OutputRailsStreamingConfig):
257257
buffer_context_size=config.context_size, buffer_chunk_size=config.chunk_size
258258
)
259259

260-
async def process_stream(self, streaming_handler):
260+
async def process_stream(
261+
self, streaming_handler
262+
) -> AsyncGenerator[ChunkBatch, None]:
261263
"""Process streaming chunks using rolling buffer strategy.
262264
263265
This method implements the rolling buffer logic, accumulating chunks

0 commit comments

Comments
 (0)