safe get_or_generate_uuid

This commit is contained in:
ishaan-jaff 2023-09-08 21:34:09 -07:00
parent a86786dea5
commit 0568a263e6

View file

@ -1961,10 +1961,20 @@ def get_or_generate_uuid():
except FileNotFoundError: except FileNotFoundError:
# Generate a new UUID if the file doesn't exist or is empty # Generate a new UUID if the file doesn't exist or is empty
new_uuid = uuid.uuid4() try:
uuid_value = str(new_uuid) new_uuid = uuid.uuid4()
with open(uuid_file, "w") as file: uuid_value = str(new_uuid)
file.write(uuid_value) with open(uuid_file, "w") as file:
file.write(uuid_value)
except: # if writing to tmp/litellm_uuid.txt then retry writing to litellm_uuid.txt
try:
new_uuid = uuid.uuid4()
uuid_value = str(new_uuid)
with open("litellm_uuid.txt", "w") as file:
file.write(uuid_value)
except: # if this 3rd attempt fails just pass
# Good first issue for someone to improve this function :)
return
except: except:
# [Non-Blocking Error] # [Non-Blocking Error]
return return
@ -1973,7 +1983,11 @@ def get_or_generate_uuid():
def litellm_telemetry(data): def litellm_telemetry(data):
# Load or generate the UUID # Load or generate the UUID
uuid_value = get_or_generate_uuid() uuid_value = ""
try:
uuid_value = get_or_generate_uuid()
except:
uuid_value = str(uuid.uuid4())
try: try:
# Prepare the data to send to litellm logging api # Prepare the data to send to litellm logging api
payload = { payload = {