mirror of
https://github.com/Skyvern-AI/skyvern.git
synced 2026-05-03 14:10:18 +00:00
65 lines
2.5 KiB
Python
65 lines
2.5 KiB
Python
from skyvern.exceptions import SkyvernException
|
|
|
|
# Exception type name constants
|
|
LLM_PROVIDER_ERROR_TYPE = "LLMProviderError"
|
|
LLM_PROVIDER_ERROR_RETRYABLE_TASK_TYPE = "LLMProviderErrorRetryableTask"
|
|
|
|
|
|
class BaseLLMError(SkyvernException):
|
|
pass
|
|
|
|
|
|
class MissingLLMProviderEnvVarsError(BaseLLMError):
|
|
def __init__(self, llm_key: str, missing_env_vars: list[str]) -> None:
|
|
super().__init__(f"Environment variables {','.join(missing_env_vars)} are required for LLMProvider {llm_key}")
|
|
|
|
|
|
class EmptyLLMResponseError(BaseLLMError):
|
|
def __init__(self, response: str) -> None:
|
|
super().__init__(f"LLM response content is empty: {response}")
|
|
|
|
|
|
class InvalidLLMResponseFormat(BaseLLMError):
|
|
def __init__(self, response: str) -> None:
|
|
super().__init__(f"LLM response content is not a valid JSON: {response}")
|
|
|
|
|
|
class InvalidLLMResponseType(BaseLLMError):
|
|
def __init__(self, response_type: str) -> None:
|
|
super().__init__(f"LLM response content is expected to be a dict, but got {response_type}")
|
|
|
|
|
|
class DuplicateCustomLLMProviderError(BaseLLMError):
|
|
def __init__(self, llm_key: str) -> None:
|
|
super().__init__(f"Custom LLMProvider {llm_key} is already registered")
|
|
|
|
|
|
class DuplicateLLMConfigError(BaseLLMError):
|
|
def __init__(self, llm_key: str) -> None:
|
|
super().__init__(f"LLM config with key {llm_key} is already registered")
|
|
|
|
|
|
class InvalidLLMConfigError(BaseLLMError):
|
|
def __init__(self, llm_key: str) -> None:
|
|
super().__init__(f"LLM config with key {llm_key} is not a valid LLMConfig")
|
|
|
|
|
|
class LLMProviderError(BaseLLMError):
|
|
def __init__(self, llm_key: str, cause: Exception | None = None) -> None:
|
|
detail = f" — {type(cause).__name__}: {cause}" if cause else ""
|
|
super().__init__(f"Error while using LLMProvider {llm_key}{detail}")
|
|
|
|
|
|
class LLMProviderErrorRetryableTask(LLMProviderError):
|
|
def __init__(self, llm_key: str, cause: Exception | None = None) -> None:
|
|
detail = f" — {type(cause).__name__}: {cause}" if cause else ""
|
|
# Skip LLMProviderError.__init__ to set our own message prefix
|
|
SkyvernException.__init__(self, f"Retryable error while using LLMProvider {llm_key}{detail}")
|
|
|
|
|
|
class NoProviderEnabledError(BaseLLMError):
|
|
def __init__(self) -> None:
|
|
super().__init__(
|
|
"At least one LLM provider must be enabled. Run `skyvern init` and follow through the LLM provider setup, "
|
|
"or update the .env file (check out .env.example to see the required environment variables)."
|
|
)
|