mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
Simplify solution
Remove result caching as its not the core part of the problem at hand.
This commit is contained in:
parent
c4410bcbfe
commit
12a9d351ac
2 changed files with 0 additions and 51 deletions
|
|
@ -121,9 +121,6 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail):
|
|||
# Loop-bound session cache for background threads
|
||||
self._loop_sessions: Dict[asyncio.AbstractEventLoop, aiohttp.ClientSession] = {}
|
||||
|
||||
# Result cache to avoid redundant network calls
|
||||
self.pii_cache = DualCache()
|
||||
|
||||
if mock_testing is True: # for testing purposes only
|
||||
return
|
||||
|
||||
|
|
@ -488,13 +485,6 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail):
|
|||
"""
|
||||
Calls Presidio Analyze + Anonymize endpoints for PII Analysis + Masking
|
||||
"""
|
||||
# Cache check
|
||||
cache_key = f"presidio:pii:{text}:{output_parse_pii}:{presidio_config}:{self.pii_entities_config}"
|
||||
cached_result = self.pii_cache.get_cache(cache_key)
|
||||
if cached_result is not None:
|
||||
verbose_proxy_logger.debug("PII Cache Hit for text: %s", text)
|
||||
return cached_result
|
||||
|
||||
start_time = datetime.now()
|
||||
analyze_results: Optional[Union[List[PresidioAnalyzeResponseItem], Dict]] = None
|
||||
status: GuardrailStatus = "success"
|
||||
|
|
@ -532,7 +522,6 @@ class _OPTIONAL_PresidioPIIMasking(CustomGuardrail):
|
|||
output_parse_pii=output_parse_pii,
|
||||
masked_entity_count=masked_entity_count,
|
||||
)
|
||||
self.pii_cache.set_cache(cache_key, anonymized_text)
|
||||
return anonymized_text
|
||||
return redacted_text["text"]
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -97,43 +97,3 @@ async def test_optimization_presidio_avoid_recognizer_reloads_on_server():
|
|||
|
||||
# Optimization Check: payload should NOT contain the redundant recognizers
|
||||
assert "ad_hoc_recognizers" not in payload
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_optimization_presidio_pii_caching_skips_network_calls():
|
||||
"""
|
||||
OPTIMIZATION VERIFICATION:
|
||||
Verify that PII results are cached in local memory.
|
||||
Identical text should return instantly from cache without making a
|
||||
network round-trip to the Presidio service.
|
||||
"""
|
||||
presidio = _OPTIONAL_PresidioPIIMasking(
|
||||
mock_testing=True,
|
||||
presidio_analyzer_api_base="http://mock-analyzer",
|
||||
presidio_anonymizer_api_base="http://mock-anonymizer"
|
||||
)
|
||||
|
||||
# Mock network calls
|
||||
presidio.analyze_text = MagicMock(return_value=asyncio.Future())
|
||||
presidio.analyze_text.return_value.set_result([])
|
||||
presidio.anonymize_text = MagicMock(return_value=asyncio.Future())
|
||||
presidio.anonymize_text.return_value.set_result("redacted text")
|
||||
|
||||
# First call - Must hit the mock (Network)
|
||||
result1 = await presidio.check_pii(
|
||||
text="repetitive call center text",
|
||||
output_parse_pii=False,
|
||||
presidio_config=None,
|
||||
request_data={}
|
||||
)
|
||||
assert result1 == "redacted text"
|
||||
assert presidio.analyze_text.call_count == 1
|
||||
|
||||
# Second call - Must hit the CACHE (No Network)
|
||||
result2 = await presidio.check_pii(
|
||||
text="repetitive call center text",
|
||||
output_parse_pii=False,
|
||||
presidio_config=None,
|
||||
request_data={}
|
||||
)
|
||||
assert result2 == "redacted text"
|
||||
assert presidio.analyze_text.call_count == 1 # Counter should NOT increase
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue