[CODE QUALITY]

pull/299/head
Kye 1 year ago
parent 5b4d7c485c
commit 37dbaf116b

@ -1,6 +1,11 @@
from swarms.telemetry.log_all import log_all_calls, log_calls
from swarms.telemetry.posthog_utils import log_activity_posthog
from swarms.telemetry.user_utils import generate_user_id, get_machine_id, get_system_info, generate_unique_identifier
from swarms.telemetry.user_utils import (
generate_user_id,
get_machine_id,
get_system_info,
generate_unique_identifier,
)
__all__ = [
@ -10,5 +15,5 @@ __all__ = [
"generate_user_id",
"get_machine_id",
"get_system_info",
"generate_unique_identifier"
]
"generate_unique_identifier",
]

@ -4,6 +4,7 @@ import os
from dotenv import load_dotenv
from posthog import Posthog
from swarms.telemetry.user_utils import generate_unique_identifier
# Load environment variables
load_dotenv()
@ -65,10 +66,13 @@ def log_activity_posthog(event_name: str, **event_properties):
return decorator_log_activity
@log_activity_posthog('function_executed', function_name='my_function')
@log_activity_posthog(
"function_executed", function_name="my_function"
)
def my_function():
# Function logic here
return "Function executed successfully!"
out = my_function()
print(out)
print(out)

@ -1,7 +1,8 @@
import hashlib
import platform
import uuid
import socket
import uuid
import socket
# Helper functions
def generate_user_id():
@ -12,6 +13,7 @@ def generate_user_id():
"""
return str(uuid.uuid4())
def get_machine_id():
"""Get machine id
@ -19,9 +21,7 @@ def get_machine_id():
_type_: _description_
"""
raw_id = platform.node()
hashed_id = hashlib.sha256(
raw_id.encode()
).hexdigest()
hashed_id = hashlib.sha256(raw_id.encode()).hexdigest()
return hashed_id
@ -39,12 +39,18 @@ def get_system_info():
"architecture": platform.machine(),
"hostname": socket.gethostname(),
"ip_address": socket.gethostbyname(socket.gethostname()),
"mac_address": ':'.join(['{:02x}'.format((uuid.getnode() >> elements) & 0xff) for elements in range(0, 2 * 6, 8)][::-1]),
"mac_address": ":".join(
[
"{:02x}".format((uuid.getnode() >> elements) & 0xFF)
for elements in range(0, 2 * 6, 8)
][::-1]
),
"processor": platform.processor(),
"python_version": platform.python_version()
"python_version": platform.python_version(),
}
return info
def generate_unique_identifier():
"""Generate unique identifier
@ -53,8 +59,5 @@ def generate_unique_identifier():
"""
system_info = get_system_info()
unique_id = uuid.uuid5(
uuid.NAMESPACE_DNS,
str(system_info)
)
return str(unique_id)
unique_id = uuid.uuid5(uuid.NAMESPACE_DNS, str(system_info))
return str(unique_id)

Loading…
Cancel
Save