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 json |
| #2 | import os |
| #3 | import uuid |
| #4 | |
| #5 | # Set up the directory path |
| #6 | VECTOR_ID = str(uuid.uuid4()) |
| #7 | home_dir = os.path.expanduser("~") |
| #8 | mem0_dir = os.environ.get("MEM0_DIR") or os.path.join(home_dir, ".mem0") |
| #9 | os.makedirs(mem0_dir, exist_ok=True) |
| #10 | |
| #11 | |
| #12 | def setup_config(): |
| #13 | config_path = os.path.join(mem0_dir, "config.json") |
| #14 | if not os.path.exists(config_path): |
| #15 | user_id = str(uuid.uuid4()) |
| #16 | config = {"user_id": user_id} |
| #17 | with open(config_path, "w") as config_file: |
| #18 | json.dump(config, config_file, indent=4) |
| #19 | |
| #20 | |
| #21 | def get_user_id(): |
| #22 | config_path = os.path.join(mem0_dir, "config.json") |
| #23 | if not os.path.exists(config_path): |
| #24 | return "anonymous_user" |
| #25 | |
| #26 | try: |
| #27 | with open(config_path, "r") as config_file: |
| #28 | config = json.load(config_file) |
| #29 | user_id = config.get("user_id") |
| #30 | return user_id |
| #31 | except Exception: |
| #32 | return "anonymous_user" |
| #33 | |
| #34 | |
| #35 | def get_or_create_user_id(vector_store): |
| #36 | """Store user_id in vector store and return it.""" |
| #37 | user_id = get_user_id() |
| #38 | |
| #39 | # Try to get existing user_id from vector store |
| #40 | try: |
| #41 | existing = vector_store.get(vector_id=user_id) |
| #42 | if existing and hasattr(existing, "payload") and existing.payload and "user_id" in existing.payload: |
| #43 | return existing.payload["user_id"] |
| #44 | except Exception: |
| #45 | pass |
| #46 | |
| #47 | # If we get here, we need to insert the user_id |
| #48 | try: |
| #49 | dims = getattr(vector_store, "embedding_model_dims", 1536) |
| #50 | vector_store.insert( |
| #51 | vectors=[[0.1] * dims], payloads=[{"user_id": user_id, "type": "user_identity"}], ids=[user_id] |
| #52 | ) |
| #53 | except Exception: |
| #54 | pass |
| #55 | |
| #56 | return user_id |
| #57 |