From 2ba8e9bc0223efcaefa410a868ad584401a58722 Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 20 Sep 2023 20:09:02 -0700 Subject: [PATCH] only show error log dashboard on fail --- litellm/utils.py | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/litellm/utils.py b/litellm/utils.py index e1257a8c5..998c3c18c 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -1881,31 +1881,31 @@ def exception_type( global user_logger_fn, liteDebuggerClient exception_mapping_worked = False - litellm.error_logs['EXCEPTION'] = original_exception - litellm.error_logs['KWARGS'] = completion_kwargs + if litellm.set_verbose == True: + litellm.error_logs['EXCEPTION'] = original_exception + litellm.error_logs['KWARGS'] = completion_kwargs + try: + # code to show users their litellm error dashboard + import urllib.parse + import json + for log_key in litellm.error_logs: + current_logs = litellm.error_logs[log_key] + if type(current_logs) == dict: + filtered_error_logs = {key: str(value) for key, value in current_logs.items()} + litellm.error_logs[log_key] = filtered_error_logs + else: + litellm.error_logs[log_key] = str(current_logs) - import urllib.parse - import json - for log_key in litellm.error_logs: - current_logs = litellm.error_logs[log_key] - if type(current_logs) == dict: - filtered_error_logs = {key: value for key, value in current_logs.items() if isinstance(value, (str, int, float, bool, list, dict))} - litellm.error_logs[log_key] = filtered_error_logs - else: - litellm.error_logs[log_key] = str(current_logs) + # Convert the filtered_error_logs dictionary to a JSON string + error_logs_json = json.dumps(litellm.error_logs) + # URL-encode the JSON data + encoded_data = urllib.parse.quote(error_logs_json) - # Convert the filtered_error_logs dictionary to a JSON string - error_logs_json = json.dumps(litellm.error_logs) - # URL-encode the JSON data - encoded_data = urllib.parse.quote(error_logs_json) - print(encoded_data) - # Print the encoded data (this is what you can include in a URL) - print("\033[91m" + str(litellm.error_logs) + "\033[0m") + print("👉 view error logs:") + print("\033[91m" + '\033[4m' + 'https://logs.litellm.ai/?data=' + str(encoded_data) + "\033[0m") - decoded_data = urllib.parse.unquote(encoded_data) - - # Print the decoded data - print(decoded_data) + except: + pass try: if isinstance(original_exception, OriginalError): # Handle the OpenAIError