Skip to content

Commit 747b540

Browse files
committed
Add coverage to _configure_main_llm_streaming()
1 parent 7424e88 commit 747b540

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/rails/llm/test_config.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
from unittest.mock import MagicMock
17+
1618
import pytest
19+
from langchain.llms.base import BaseLLM
1720
from pydantic import ValidationError
1821

1922
from nemoguardrails.rails.llm.config import (
@@ -23,6 +26,7 @@
2326
RailsConfig,
2427
TaskPrompt,
2528
)
29+
from nemoguardrails.rails.llm.llmrails import LLMRails
2630

2731

2832
def test_task_prompt_valid_content():
@@ -307,3 +311,34 @@ def test_rails_config_none_config_path():
307311

308312
result2 = config3 + config4
309313
assert result2.config_path == ""
314+
315+
316+
def test_llm_rails_configure_streaming_with_attr():
317+
"""Check LLM has the streaming attribute set if RailsConfig has it"""
318+
319+
mock_llm = MagicMock(spec=BaseLLM)
320+
config = RailsConfig(
321+
models=[],
322+
streaming=True,
323+
)
324+
325+
rails = LLMRails(config, llm=mock_llm)
326+
setattr(mock_llm, "streaming", None)
327+
rails._configure_main_llm_streaming(llm=mock_llm)
328+
329+
assert mock_llm.streaming
330+
331+
332+
def test_llm_rails_configure_streaming_without_attr(caplog):
333+
"""Check LLM has the streaming attribute set if RailsConfig has it"""
334+
335+
mock_llm = MagicMock(spec=BaseLLM)
336+
config = RailsConfig(
337+
models=[],
338+
streaming=True,
339+
)
340+
341+
rails = LLMRails(config, llm=mock_llm)
342+
rails._configure_main_llm_streaming(mock_llm)
343+
344+
assert caplog.messages[-1] == "Provided main LLM does not support streaming."

0 commit comments

Comments
 (0)