repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import logging |
| #2 | import os |
| #3 | import platform |
| #4 | import sys |
| #5 | |
| #6 | from posthog import Posthog |
| #7 | |
| #8 | import mem0 |
| #9 | from mem0.memory.setup import get_or_create_user_id |
| #10 | |
| #11 | MEM0_TELEMETRY = os.environ.get("MEM0_TELEMETRY", "True") |
| #12 | PROJECT_API_KEY = "phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX" |
| #13 | HOST = "https://us.i.posthog.com" |
| #14 | |
| #15 | if isinstance(MEM0_TELEMETRY, str): |
| #16 | MEM0_TELEMETRY = MEM0_TELEMETRY.lower() in ("true", "1", "yes") |
| #17 | |
| #18 | if not isinstance(MEM0_TELEMETRY, bool): |
| #19 | raise ValueError("MEM0_TELEMETRY must be a boolean value.") |
| #20 | |
| #21 | logging.getLogger("posthog").setLevel(logging.CRITICAL + 1) |
| #22 | logging.getLogger("urllib3").setLevel(logging.CRITICAL + 1) |
| #23 | |
| #24 | |
| #25 | class AnonymousTelemetry: |
| #26 | def __init__(self, vector_store=None): |
| #27 | if not MEM0_TELEMETRY: |
| #28 | self.posthog = None |
| #29 | self.user_id = None |
| #30 | return |
| #31 | |
| #32 | self.posthog = Posthog(project_api_key=PROJECT_API_KEY, host=HOST) |
| #33 | self.user_id = get_or_create_user_id(vector_store) |
| #34 | |
| #35 | def capture_event(self, event_name, properties=None, user_email=None): |
| #36 | if self.posthog is None: |
| #37 | return |
| #38 | |
| #39 | if properties is None: |
| #40 | properties = {} |
| #41 | properties = { |
| #42 | "client_source": "python", |
| #43 | "client_version": mem0.__version__, |
| #44 | "python_version": sys.version, |
| #45 | "os": sys.platform, |
| #46 | "os_version": platform.version(), |
| #47 | "os_release": platform.release(), |
| #48 | "processor": platform.processor(), |
| #49 | "machine": platform.machine(), |
| #50 | **properties, |
| #51 | } |
| #52 | distinct_id = self.user_id if user_email is None else user_email |
| #53 | self.posthog.capture(distinct_id=distinct_id, event=event_name, properties=properties) |
| #54 | |
| #55 | def close(self): |
| #56 | if self.posthog is not None: |
| #57 | self.posthog.shutdown() |
| #58 | |
| #59 | |
| #60 | client_telemetry = AnonymousTelemetry() |
| #61 | |
| #62 | |
| #63 | def capture_event(event_name, memory_instance, additional_data=None): |
| #64 | if not MEM0_TELEMETRY: |
| #65 | return |
| #66 | |
| #67 | oss_telemetry = AnonymousTelemetry( |
| #68 | vector_store=memory_instance._telemetry_vector_store |
| #69 | if hasattr(memory_instance, "_telemetry_vector_store") |
| #70 | else None, |
| #71 | ) |
| #72 | |
| #73 | event_data = { |
| #74 | "collection": memory_instance.collection_name, |
| #75 | "vector_size": memory_instance.embedding_model.config.embedding_dims, |
| #76 | "history_store": "sqlite", |
| #77 | "graph_store": f"{memory_instance.graph.__class__.__module__}.{memory_instance.graph.__class__.__name__}" |
| #78 | if memory_instance.config.graph_store.config |
| #79 | else None, |
| #80 | "vector_store": f"{memory_instance.vector_store.__class__.__module__}.{memory_instance.vector_store.__class__.__name__}", |
| #81 | "llm": f"{memory_instance.llm.__class__.__module__}.{memory_instance.llm.__class__.__name__}", |
| #82 | "embedding_model": f"{memory_instance.embedding_model.__class__.__module__}.{memory_instance.embedding_model.__class__.__name__}", |
| #83 | "function": f"{memory_instance.__class__.__module__}.{memory_instance.__class__.__name__}.{memory_instance.api_version}", |
| #84 | } |
| #85 | if additional_data: |
| #86 | event_data.update(additional_data) |
| #87 | |
| #88 | oss_telemetry.capture_event(event_name, event_data) |
| #89 | |
| #90 | |
| #91 | def capture_client_event(event_name, instance, additional_data=None): |
| #92 | if not MEM0_TELEMETRY: |
| #93 | return |
| #94 | |
| #95 | event_data = { |
| #96 | "function": f"{instance.__class__.__module__}.{instance.__class__.__name__}", |
| #97 | } |
| #98 | if additional_data: |
| #99 | event_data.update(additional_data) |
| #100 | |
| #101 | client_telemetry.capture_event(event_name, event_data, instance.user_email) |
| #102 |