|
18 | 18 | import pytest |
19 | 19 |
|
20 | 20 | from nemoguardrails import RailsConfig |
21 | | -from nemoguardrails.imports import check_optional_dependency |
22 | 21 | from tests.utils import TestChat |
23 | 22 |
|
24 | 23 | BASE_CONFIG = textwrap.dedent(""" |
@@ -297,40 +296,23 @@ def test_passthrough_no_cache_created(self, tmp_path): |
297 | 296 | del os.environ["FASTEMBED_CACHE_PATH"] |
298 | 297 |
|
299 | 298 |
|
300 | | -_has_fastembed = check_optional_dependency("fastembed") |
301 | | - |
302 | | - |
303 | | -@pytest.mark.skipif(not _has_fastembed, reason="fastembed not installed") |
304 | | -class TestFastEmbedDownloadedForDialogRails: |
305 | | - def test_dialog_rails_cache_created_on_generate(self, tmp_path): |
306 | | - import os |
307 | | - |
308 | | - cache_dir = tmp_path / "fastembed_cache" |
309 | | - cache_dir.mkdir() |
310 | | - os.environ["FASTEMBED_CACHE_PATH"] = str(cache_dir) |
311 | | - |
312 | | - try: |
313 | | - config = RailsConfig.from_content( |
314 | | - yaml_content=BASE_CONFIG, |
315 | | - colang_content=USER_DEFINITIONS + BOT_DEFINITIONS + FLOW_DEFINITIONS, |
316 | | - ) |
317 | | - chat = TestChat( |
318 | | - config, |
319 | | - llm_completions=["express greeting", "Hello! How can I help you?"], |
320 | | - ) |
321 | | - |
322 | | - cache_before = list(cache_dir.iterdir()) |
323 | | - assert len(cache_before) == 0, "Cache should be empty before generate" |
| 299 | +class TestIndexInitializedAfterGenerate: |
| 300 | + def test_user_message_index_initialized_after_generate(self): |
| 301 | + config = RailsConfig.from_content( |
| 302 | + yaml_content=BASE_CONFIG, |
| 303 | + colang_content=USER_DEFINITIONS + BOT_DEFINITIONS + FLOW_DEFINITIONS, |
| 304 | + ) |
| 305 | + chat = TestChat( |
| 306 | + config, |
| 307 | + llm_completions=["express greeting", "Hello! How can I help you?"], |
| 308 | + ) |
| 309 | + actions = chat.app.llm_generation_actions |
324 | 310 |
|
325 | | - response = chat.app.generate(messages=[{"role": "user", "content": "hello"}]) |
| 311 | + assert actions.user_message_index is None, "Index should be None before generate" |
326 | 312 |
|
327 | | - assert response is not None |
| 313 | + chat.app.generate(messages=[{"role": "user", "content": "hello"}]) |
328 | 314 |
|
329 | | - cache_after = list(cache_dir.iterdir()) |
330 | | - assert len(cache_after) > 0, "FastEmbed cache should have models after generate with dialog rails" |
331 | | - finally: |
332 | | - if "FASTEMBED_CACHE_PATH" in os.environ: |
333 | | - del os.environ["FASTEMBED_CACHE_PATH"] |
| 315 | + assert actions.user_message_index is not None, "Index should be initialized after generate" |
334 | 316 |
|
335 | 317 |
|
336 | 318 | class TestConcurrentInitialization: |
|
0 commit comments