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

32 lines
983 B
Python
Raw Permalink Normal View History

class OpenAIError(Exception):
2023-07-12 14:33:25 -04:00
def __init__(self, message=None, code=500, internal_message=''):
self.message = message
self.code = code
self.internal_message = internal_message
2023-07-12 14:33:25 -04:00
def __repr__(self):
return "%s(message=%r, code=%d)" % (
self.__class__.__name__,
self.message,
self.code,
)
2023-07-12 14:33:25 -04:00
class InvalidRequestError(OpenAIError):
def __init__(self, message, param, code=400, internal_message=''):
super().__init__(message, code, internal_message)
self.param = param
2023-07-12 14:33:25 -04:00
def __repr__(self):
return "%s(message=%r, code=%d, param=%s)" % (
self.__class__.__name__,
self.message,
self.code,
self.param,
)
2023-07-12 14:33:25 -04:00
class ServiceUnavailableError(OpenAIError):
def __init__(self, message="Service unavailable, please try again later.", code=503, internal_message=''):
super().__init__(message, code, internal_message)