Skip to content

Commit

Permalink
Define errors in errors file (#2202)
Browse files Browse the repository at this point in the history
* Moved inference templating errors in errors.py

* Sorted error types alphabetically

* addition from "make file"
  • Loading branch information
lappemic committed Apr 8, 2024
1 parent 9ce67ce commit bbb00ac
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
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

0 comments on commit bbb00ac

Please sign in to comment.