Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define errors in errors file #2202

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 36 additions & 29 deletions src/huggingface_hub/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,25 @@
from requests import HTTPError


# INFERENCE CLIENT ERRORS


class InferenceTimeoutError(HTTPError, TimeoutError):
"""Error raised when a model is unavailable or the request times out."""


# TEXT GENERATION ERRORS


class TextGenerationError(HTTPError):
"""Generic error raised if text-generation went wrong."""
# HEADERS ERRORS


# Text Generation Inference Errors
class ValidationError(TextGenerationError):
"""Server-side validation error."""
class LocalTokenNotFoundError(EnvironmentError):
"""Raised if local token is required but not found."""


class GenerationError(TextGenerationError):
pass
# HTTP ERRORS


class OverloadedError(TextGenerationError):
pass
class OfflineModeIsEnabled(ConnectionError):
"""Raised when a request is made but `HF_HUB_OFFLINE=1` is set as environment variable."""


class IncompleteGenerationError(TextGenerationError):
pass
# INFERENCE CLIENT ERRORS


class UnknownError(TextGenerationError):
pass
class InferenceTimeoutError(HTTPError, TimeoutError):
"""Error raised when a model is unavailable or the request times out."""


# INFERENCE ENDPOINT ERRORS
Expand Down Expand Up @@ -65,18 +51,39 @@ class NotASafetensorsRepoError(Exception):
"""


# HEADERS ERRORS
# TEMPLATING ERRORS


class LocalTokenNotFoundError(EnvironmentError):
"""Raised if local token is required but not found."""
class TemplateError(Exception):
"""Any error raised while trying to fetch or render a chat template."""


# HTTP ERRORS
# TEXT GENERATION ERRORS


class OfflineModeIsEnabled(ConnectionError):
"""Raised when a request is made but `HF_HUB_OFFLINE=1` is set as environment variable."""
class TextGenerationError(HTTPError):
"""Generic error raised if text-generation went wrong."""


# Text Generation Inference Errors
class ValidationError(TextGenerationError):
"""Server-side validation error."""


class GenerationError(TextGenerationError):
pass


class OverloadedError(TextGenerationError):
pass


class IncompleteGenerationError(TextGenerationError):
pass


class UnknownError(TextGenerationError):
pass


# VALIDATION ERRORS
Expand Down
6 changes: 2 additions & 4 deletions src/huggingface_hub/inference/_templating.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from functools import lru_cache
from typing import Callable, Dict, List, Optional, Union

from ..utils import HfHubHTTPError, RepositoryNotFoundError, is_minijinja_available

from huggingface_hub.errors import TemplateError

class TemplateError(Exception):
"""Any error raised while trying to fetch or render a chat template."""
from ..utils import HfHubHTTPError, RepositoryNotFoundError, is_minijinja_available


def _import_minijinja():
Expand Down
Loading