|
| 1 | +from promptlayer import AsyncPromptLayer, PromptLayer |
| 2 | + |
| 3 | + |
| 4 | +def test_promptlayer_client_invalidate_prompt_name(promptlayer_api_key, base_url): |
| 5 | + client = PromptLayer(api_key=promptlayer_api_key, base_url=base_url, cache_ttl_seconds=60) |
| 6 | + cache = client.templates._cache |
| 7 | + |
| 8 | + alpha_key = cache.make_key("alpha") |
| 9 | + beta_key = cache.make_key("beta") |
| 10 | + cache.put(alpha_key, {"prompt_template": {"type": "chat", "messages": []}}) |
| 11 | + cache.put(beta_key, {"prompt_template": {"type": "chat", "messages": []}}) |
| 12 | + |
| 13 | + client.invalidate("alpha") |
| 14 | + |
| 15 | + alpha_cached, _ = cache.get(alpha_key) |
| 16 | + beta_cached, _ = cache.get(beta_key) |
| 17 | + assert alpha_cached is None |
| 18 | + assert beta_cached is not None |
| 19 | + |
| 20 | + |
| 21 | +def test_promptlayer_client_invalidate_all(promptlayer_api_key, base_url): |
| 22 | + client = PromptLayer(api_key=promptlayer_api_key, base_url=base_url, cache_ttl_seconds=60) |
| 23 | + cache = client.templates._cache |
| 24 | + |
| 25 | + first_key = cache.make_key("first") |
| 26 | + second_key = cache.make_key("second") |
| 27 | + cache.put(first_key, {"prompt_template": {"type": "chat", "messages": []}}) |
| 28 | + cache.put(second_key, {"prompt_template": {"type": "chat", "messages": []}}) |
| 29 | + |
| 30 | + client.invalidate() |
| 31 | + |
| 32 | + first_cached, _ = cache.get(first_key) |
| 33 | + second_cached, _ = cache.get(second_key) |
| 34 | + assert first_cached is None |
| 35 | + assert second_cached is None |
| 36 | + |
| 37 | + |
| 38 | +def test_async_promptlayer_client_invalidate(promptlayer_api_key, base_url): |
| 39 | + client = AsyncPromptLayer(api_key=promptlayer_api_key, base_url=base_url, cache_ttl_seconds=60) |
| 40 | + cache = client.templates._cache |
| 41 | + |
| 42 | + key = cache.make_key("async-template") |
| 43 | + cache.put(key, {"prompt_template": {"type": "chat", "messages": []}}) |
| 44 | + |
| 45 | + client.invalidate("async-template") |
| 46 | + |
| 47 | + cached, _ = cache.get(key) |
| 48 | + assert cached is None |
0 commit comments