MCPcopy
hub / github.com/mudler/LocalAI / fetch_and_verify

Method fetch_and_verify

backend/python/mlx/test_mlx_cache.py:394–412  ·  view source on GitHub ↗
(thread_id)

Source from the content-addressed store, hash-verified

392 cache.insert_cache("model", [i], [f"original_{i}"])
393
394 def fetch_and_verify(thread_id):
395 try:
396 for _ in range(50):
397 token_id = thread_id % 20
398 result, remaining = cache.fetch_nearest_cache("model", [token_id])
399
400 if result is not None:
401 # Verify data integrity
402 expected_prefix = f"original_{token_id}"
403 if not str(result[0]).startswith("original_"):
404 with lock:
405 errors.append(f"Corrupted data: {result}")
406
407 # Re-insert to keep cache populated
408 cache.insert_cache("model", [token_id], result)
409
410 except Exception as e:
411 with lock:
412 errors.append(str(e))
413
414 with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
415 futures = [executor.submit(fetch_and_verify, tid) for tid in range(10)]

Callers

nothing calls this directly

Calls 3

appendMethod · 0.80
fetch_nearest_cacheMethod · 0.45
insert_cacheMethod · 0.45

Tested by

no test coverage detected