From 0568a263e60f0273d64a295f40e6632967ea18e1 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Fri, 8 Sep 2023 21:34:09 -0700 Subject: [PATCH] safe get_or_generate_uuid --- litellm/utils.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/litellm/utils.py b/litellm/utils.py index cb914c4c42..665a604d3d 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -1961,10 +1961,20 @@ def get_or_generate_uuid(): except FileNotFoundError: # Generate a new UUID if the file doesn't exist or is empty - new_uuid = uuid.uuid4() - uuid_value = str(new_uuid) - with open(uuid_file, "w") as file: - file.write(uuid_value) + try: + new_uuid = uuid.uuid4() + uuid_value = str(new_uuid) + 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: # [Non-Blocking Error] return @@ -1973,7 +1983,11 @@ def get_or_generate_uuid(): def litellm_telemetry(data): # 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: # Prepare the data to send to litellm logging api payload = {