Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions mem0/memory/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ def setup_config():

def get_user_id():
config_path = os.path.join(mem0_dir, "config.json")
if not os.path.exists(config_path):
return "anonymous_user"

try:
with open(config_path, "r") as config_file:
config = json.load(config_file)
user_id = config.get("user_id")
return user_id
except Exception:
# Load and fetch user_id in a single step to avoid unnecessary variable
return json.load(config_file).get("user_id")
except (FileNotFoundError, json.JSONDecodeError, PermissionError):
# Directly catch file and JSON errors to avoid handling unrelated exceptions
return "anonymous_user"


Expand Down