|
17 | 17 | from typing import Dict |
18 | 18 |
|
19 | 19 | import pytest |
| 20 | +from dotenv import load_dotenv |
20 | 21 | from langcache.errors import BadRequestErrorResponseContent |
21 | 22 |
|
22 | 23 | from redisvl.extensions.cache.llm.langcache import LangCacheSemanticCache |
23 | 24 |
|
| 25 | +load_dotenv() |
| 26 | + |
24 | 27 | REQUIRED_WITH_ATTRS_VARS = ( |
25 | 28 | "LANGCACHE_WITH_ATTRIBUTES_API_KEY", |
26 | 29 | "LANGCACHE_WITH_ATTRIBUTES_CACHE_ID", |
@@ -235,13 +238,31 @@ async def test_async_delete_variants( |
235 | 238 | ) |
236 | 239 | assert not any(hit["response"] == response for hit in hits_after_clear) |
237 | 240 |
|
| 241 | + def test_attribute_value_with_comma_passes_through_to_api( |
| 242 | + self, langcache_with_attrs: LangCacheSemanticCache |
| 243 | + ) -> None: |
| 244 | + """We currently rely on the LangCache API to validate commas in attribute values. |
| 245 | +
|
| 246 | + This test verifies we do not perform client-side validation and that the |
| 247 | + error is raised by the backend. If this behavior changes, this test will |
| 248 | + need to be updated. |
| 249 | + """ |
| 250 | + prompt = "Comma attribute value" |
| 251 | + response = "This may fail depending on the remote validation rules." |
| 252 | + |
| 253 | + with pytest.raises(BadRequestErrorResponseContent): |
| 254 | + langcache_with_attrs.store( |
| 255 | + prompt=prompt, |
| 256 | + response=response, |
| 257 | + metadata={"llm_string": "tenant,with,comma"}, |
| 258 | + ) |
| 259 | + |
238 | 260 |
|
239 | 261 | @pytest.mark.requires_api_keys |
240 | 262 | class TestLangCacheSemanticCacheIntegrationWithoutAttributes: |
241 | 263 | def test_error_on_store_with_metadata_when_no_attributes_configured( |
242 | 264 | self, langcache_no_attrs: LangCacheSemanticCache |
243 | 265 | ) -> None: |
244 | | - |
245 | 266 | prompt = "Attributes not configured" |
246 | 267 | response = "This should fail due to missing attributes configuration." |
247 | 268 |
|
@@ -279,22 +300,3 @@ def test_basic_store_and_check_works_without_attributes( |
279 | 300 | hits = langcache_no_attrs.check(prompt=prompt) |
280 | 301 | assert hits |
281 | 302 | assert any(hit["response"] == response for hit in hits) |
282 | | - |
283 | | - def test_attribute_value_with_comma_passes_through_to_api( |
284 | | - self, langcache_with_attrs: LangCacheSemanticCache |
285 | | - ) -> None: |
286 | | - """We currently rely on the LangCache API to validate commas in attribute values. |
287 | | -
|
288 | | - This test verifies we do not perform client-side validation and that the |
289 | | - error is raised by the backend. If this behavior changes, this test will |
290 | | - need to be updated. |
291 | | - """ |
292 | | - prompt = "Comma attribute value" |
293 | | - response = "This may fail depending on the remote validation rules." |
294 | | - |
295 | | - with pytest.raises(BadRequestErrorResponseContent): |
296 | | - langcache_with_attrs.store( |
297 | | - prompt=prompt, |
298 | | - response=response, |
299 | | - metadata={"llm_string": "tenant,with,comma"}, |
300 | | - ) |
|
0 commit comments