Repository navigation
Expand file tree
/
Copy patherrors.py
More file actions
53 lines (38 loc) · 1.69 KB
/
Copy patherrors.py
File metadata and controls
53 lines (38 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from typing import Iterable
from fastapi import status as HttpStatusCode
from feast.errors import FeastError
class ContextError(FeastError):
"""Base class for all feast.context failures."""
class TokenizerNotFoundError(ContextError):
def __init__(self, name: str, available: Iterable[str]):
super().__init__(
f"Unknown tokenizer '{name}'. Built-in tokenizers: "
f"{', '.join(sorted(available))}. For your own, pass the class "
f"path of a Tokenizer subclass, e.g. 'my_pkg.MyTokenizer'."
)
def http_status_code(self) -> int:
return HttpStatusCode.HTTP_400_BAD_REQUEST
class TokenizerUnavailableError(ContextError):
"""A known tokenizer cannot be loaded.
Covers a missing dependency, and one present but unable to load its
encoding — tiktoken fetching a BPE file on a host with no network, say.
"""
def __init__(self, name: str, reason: str, install_hint: str):
super().__init__(
f"Tokenizer '{name}' is unavailable: {reason}. Install its "
f"dependencies with: {install_hint}"
)
self.tokenizer_name = name
def http_status_code(self) -> int:
return HttpStatusCode.HTTP_400_BAD_REQUEST
class TokenBudgetExceededError(ContextError):
def __init__(self, requested: int, remaining: int, max_tokens: int):
super().__init__(
f"Cannot consume {requested} tokens: only {remaining} of "
f"{max_tokens} tokens remain in the budget."
)
self.requested = requested
self.remaining = remaining
self.max_tokens = max_tokens
def http_status_code(self) -> int:
return HttpStatusCode.HTTP_400_BAD_REQUEST