|
14 | 14 | # limitations under the License. |
15 | 15 |
|
16 | 16 | import asyncio |
| 17 | +import os |
| 18 | + |
| 19 | +import pytest |
17 | 20 | import unittest |
18 | | -from unittest.mock import AsyncMock, MagicMock |
| 21 | +from unittest.mock import AsyncMock, MagicMock, patch |
19 | 22 |
|
| 23 | +from nemoguardrails import LLMRails |
20 | 24 | from nemoguardrails.logging.explain import LLMCallInfo |
21 | | -from nemoguardrails.rails.llm.config import TracingConfig |
| 25 | +from nemoguardrails.rails.llm.config import TracingConfig, RailsConfig |
22 | 26 | from nemoguardrails.rails.llm.options import ( |
23 | 27 | ActivatedRail, |
24 | 28 | ExecutedAction, |
@@ -201,5 +205,39 @@ def test_export_async(self): |
201 | 205 | adapter_non_empty.transform_async.assert_called_once() |
202 | 206 |
|
203 | 207 |
|
| 208 | +@patch.object(Tracer, "export_async", return_value="") |
| 209 | +@pytest.mark.asyncio |
| 210 | +async def test_tracing_enable_no_crash_issue_1093(mockTracer): |
| 211 | + config = RailsConfig.from_content( |
| 212 | + colang_content=""" |
| 213 | + define user express greeting |
| 214 | + "hello" |
| 215 | +
|
| 216 | + define flow |
| 217 | + user express greeting |
| 218 | + bot express greeting |
| 219 | +
|
| 220 | + define bot express greeting |
| 221 | + "Hello World!\\n NewLine World!" |
| 222 | + """, |
| 223 | + config={ |
| 224 | + "models": [], |
| 225 | + "rails": {"dialog": {"user_messages": {"embeddings_only": True}}}, |
| 226 | + }, |
| 227 | + ) |
| 228 | + # Force Tracing to be enabled |
| 229 | + config.tracing.enabled = True |
| 230 | + rails = LLMRails(config) |
| 231 | + res = await rails.generate_async( |
| 232 | + messages=[ |
| 233 | + {"role": "user", "content": "hi!"}, |
| 234 | + {"role": "assistant", "content": "hi!"}, |
| 235 | + {"role": "user", "content": "hi!"}, |
| 236 | + ] |
| 237 | + ) |
| 238 | + assert mockTracer.called == True |
| 239 | + assert res.response != None |
| 240 | + |
| 241 | + |
204 | 242 | if __name__ == "__main__": |
205 | 243 | unittest.main() |
0 commit comments