text-generation-webui/extensions/openai/errors.py

32 lines
1.0 KiB
Python
Raw Normal View History

class OpenAIError(Exception):
2023-07-12 20:33:25 +02:00
def __init__(self, message=None, code=500, internal_message=''):
self.message = message
self.code = code
self.internal_message = internal_message
2023-07-12 20:33:25 +02:00
def __repr__(self):
return "%s(message=%r, code=%d)" % (
self.__class__.__name__,
self.message,
self.code,
)
2023-07-12 20:33:25 +02:00
class InvalidRequestError(OpenAIError):
2023-07-12 20:33:25 +02:00
def __init__(self, message, param, code=400, error_type='InvalidRequestError', internal_message=''):
super(OpenAIError, self).__init__(message, code, error_type, internal_message)
self.param = param
2023-07-12 20:33:25 +02:00
def __repr__(self):
return "%s(message=%r, code=%d, param=%s)" % (
self.__class__.__name__,
self.message,
self.code,
self.param,
)
2023-07-12 20:33:25 +02:00
class ServiceUnavailableError(OpenAIError):
2023-07-12 20:33:25 +02:00
def __init__(self, message=None, code=500, error_type='ServiceUnavailableError', internal_message=''):
super(OpenAIError, self).__init__(message, code, error_type, internal_message)