File size: 1,430 Bytes
7d07e42 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | """Patch chromadb DefaultEmbeddingFunction to avoid downloading ONNX model."""
import re, sys, pathlib
def patch_chromadb():
try:
import chromadb.utils.embedding_functions as ef_mod
except ImportError:
print("[chromadb] not installed; skipping patch")
return
fp = pathlib.Path(ef_mod.__file__)
txt = fp.read_text()
if "# patched: default embedding disabled" in txt:
print("[chromadb] already patched")
return
new = re.sub(
r"def DefaultEmbeddingFunction\(\)[^:]*:.*?return ONNXMiniLM_L6_V2\(\)",
"def DefaultEmbeddingFunction():\n # patched: default embedding disabled\n return None",
txt, flags=re.DOTALL, count=1,
)
if new != txt:
fp.write_text(new)
print(f"[chromadb] patched: {fp}")
else:
print("[chromadb] pattern not found, skipping")
def patch_posthog():
try:
import posthog
except ImportError:
print("[posthog] not installed; skipping")
return
fp = pathlib.Path(posthog.__file__)
txt = fp.read_text()
if "# patched: telemetry no-op" in txt:
print("[posthog] already patched")
return
new = re.sub(r"def capture\(([^)]*)\):", r"def capture(\1):\n return None # patched: telemetry no-op", txt, count=1)
if new != txt:
fp.write_text(new)
print(f"[posthog] patched: {fp}")
patch_chromadb()
patch_posthog()
|