forked from phoenix/litellm-mirror
bug fixes and updates
This commit is contained in:
parent
efe82c6bb6
commit
85f1591413
17 changed files with 646 additions and 330 deletions
|
@ -234,41 +234,45 @@ def handle_success(*args, **kwargs):
|
|||
|
||||
|
||||
def exception_type(model, original_exception):
|
||||
if isinstance(original_exception, OpenAIError):
|
||||
# Handle the OpenAIError
|
||||
raise original_exception
|
||||
elif model:
|
||||
error_str = str(original_exception)
|
||||
if isinstance(original_exception, BaseException):
|
||||
exception_type = type(original_exception).__name__
|
||||
try:
|
||||
if isinstance(original_exception, OpenAIError):
|
||||
# Handle the OpenAIError
|
||||
raise original_exception
|
||||
elif model:
|
||||
error_str = str(original_exception)
|
||||
if isinstance(original_exception, BaseException):
|
||||
exception_type = type(original_exception).__name__
|
||||
else:
|
||||
exception_type = ""
|
||||
if "claude" in model: #one of the anthropics
|
||||
if "status_code" in original_exception:
|
||||
print_verbose(f"status_code: {original_exception.status_code}")
|
||||
if original_exception.status_code == 401:
|
||||
raise AuthenticationError(f"AnthropicException - {original_exception.message}")
|
||||
elif original_exception.status_code == 400:
|
||||
raise InvalidRequestError(f"AnthropicException - {original_exception.message}", f"{model}")
|
||||
elif original_exception.status_code == 429:
|
||||
raise RateLimitError(f"AnthropicException - {original_exception.message}")
|
||||
elif "replicate" in model:
|
||||
if "Incorrect authentication token" in error_str:
|
||||
raise AuthenticationError(f"ReplicateException - {error_str}")
|
||||
elif exception_type == "ModelError":
|
||||
raise InvalidRequestError(f"ReplicateException - {error_str}", f"{model}")
|
||||
elif "Request was throttled" in error_str:
|
||||
raise RateLimitError(f"ReplicateException - {error_str}")
|
||||
elif exception_type == "ReplicateError": ## ReplicateError implies an error on Replicate server side, not user side
|
||||
raise ServiceUnavailableError(f"ReplicateException - {error_str}")
|
||||
elif model == "command-nightly": #Cohere
|
||||
if "invalid api token" in error_str or "No API key provided." in error_str:
|
||||
raise AuthenticationError(f"CohereException - {error_str}")
|
||||
elif "too many tokens" in error_str:
|
||||
raise InvalidRequestError(f"CohereException - {error_str}", f"{model}")
|
||||
elif "CohereConnectionError" in exception_type: # cohere seems to fire these errors when we load test it (1k+ messages / min)
|
||||
raise RateLimitError(f"CohereException - {original_exception.message}")
|
||||
raise original_exception # base case - return the original exception
|
||||
else:
|
||||
exception_type = ""
|
||||
if "claude" in model: #one of the anthropics
|
||||
print_verbose(f"status_code: {original_exception.status_code}")
|
||||
if original_exception.status_code == 401:
|
||||
raise AuthenticationError(f"AnthropicException - {original_exception.message}")
|
||||
elif original_exception.status_code == 400:
|
||||
raise InvalidRequestError(f"AnthropicException - {original_exception.message}", f"{model}")
|
||||
elif original_exception.status_code == 429:
|
||||
raise RateLimitError(f"AnthropicException - {original_exception.message}")
|
||||
elif "replicate" in model:
|
||||
if "Incorrect authentication token" in error_str:
|
||||
raise AuthenticationError(f"ReplicateException - {error_str}")
|
||||
elif exception_type == "ModelError":
|
||||
raise InvalidRequestError(f"ReplicateException - {error_str}", f"{model}")
|
||||
elif "Request was throttled" in error_str:
|
||||
raise RateLimitError(f"ReplicateException - {error_str}")
|
||||
elif exception_type == "ReplicateError": ## ReplicateError implies an error on Replicate server side, not user side
|
||||
raise ServiceUnavailableError(f"ReplicateException - {error_str}")
|
||||
elif model == "command-nightly": #Cohere
|
||||
if "invalid api token" in error_str or "No API key provided." in error_str:
|
||||
raise AuthenticationError(f"CohereException - {error_str}")
|
||||
elif "too many tokens" in error_str:
|
||||
raise InvalidRequestError(f"CohereException - {error_str}", f"{model}")
|
||||
elif "CohereConnectionError" in exception_type: # cohere seems to fire these errors when we load test it (1k+ messages / min)
|
||||
raise RateLimitError(f"CohereException - {original_exception.message}")
|
||||
raise original_exception # base case - return the original exception
|
||||
else:
|
||||
raise original_exception
|
||||
except:
|
||||
raise original_exception
|
||||
|
||||
def safe_crash_reporting(model=None, exception=None, azure=None):
|
||||
|
@ -277,11 +281,9 @@ def safe_crash_reporting(model=None, exception=None, azure=None):
|
|||
"exception": str(exception),
|
||||
"azure": azure
|
||||
}
|
||||
print(f"data in crash reporting: {data}")
|
||||
threading.Thread(target=litellm_telemetry, args=(data,), daemon=True).start()
|
||||
|
||||
def litellm_telemetry(data):
|
||||
print(f"data in in litellm telemetry: {data}")
|
||||
# Load or generate the UUID
|
||||
uuid_file = 'litellm_uuid.txt'
|
||||
try:
|
||||
|
@ -290,7 +292,6 @@ def litellm_telemetry(data):
|
|||
uuid_value = file.read()
|
||||
if uuid_value:
|
||||
uuid_value = uuid_value.strip()
|
||||
print(f"Loaded UUID: {uuid_value}")
|
||||
else:
|
||||
raise FileNotFoundError
|
||||
except FileNotFoundError:
|
||||
|
@ -299,7 +300,6 @@ def litellm_telemetry(data):
|
|||
uuid_value = str(new_uuid)
|
||||
with open(uuid_file, 'w') as file:
|
||||
file.write(uuid_value)
|
||||
print(f"Generated and stored UUID: {uuid_value}")
|
||||
|
||||
# Prepare the data to send to localhost:3000
|
||||
payload = {
|
||||
|
@ -311,7 +311,6 @@ def litellm_telemetry(data):
|
|||
# Make the POST request to localhost:3000
|
||||
response = requests.post('https://litellm.berri.ai/logging', json=payload)
|
||||
response.raise_for_status() # Raise an exception for HTTP errors
|
||||
print('Request successfully sent!')
|
||||
except requests.exceptions.RequestException as e:
|
||||
# Handle any errors in the request
|
||||
print(f'Error: {e}')
|
||||
pass
|
Loading…
Add table
Add a link
Reference in a new issue