Repository navigation
refactor(sdk): separate core AWS and tokenizer dependencies #44447
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
Changes from all commits
c7a1887
a2f447c
2403684
ef05ec1
50bfc0f
dbdd5c4
c6f5c34
2cbe59f
4d7ddd1
ba9eae1
7b9bb43
937f555
20d9fce
d38f087
11a09a9
a5f8524
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from typing import Final | ||
|
|
||
|
|
||
| def ensure_optional_import(module: str) -> None: | ||
| try: | ||
| __import__(module) | ||
| except ModuleNotFoundError as error: | ||
| if error.name != module: | ||
| raise | ||
| package: Final = "boto3" if module == "botocore" else module | ||
| raise ModuleNotFoundError( | ||
| f"Missing optional dependency '{module}'. Run 'pip install {package}'.", name=module | ||
| ) from error |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| import struct | ||
| from collections.abc import Awaitable, Callable, Iterable, Mapping, Sequence | ||
| from itertools import accumulate | ||
| from typing import Final, Literal, cast | ||
| from typing import TYPE_CHECKING, Final, Literal, cast | ||
|
|
||
| import anyio | ||
| import anyio.lowlevel | ||
|
|
@@ -30,7 +30,10 @@ | |
| TOKEN_COUNTER_MAX_EXACT_CHARS, | ||
| ) | ||
| from litellm.litellm_core_utils.asyncify import asyncify | ||
| from litellm.litellm_core_utils.tokenizer import Encoding, HuggingFace, HuggingFaceTokenizer, OpenAIEncoding | ||
| from litellm.litellm_core_utils.tokenizer import HuggingFaceTokenizer, OpenAIEncoding | ||
|
|
||
| if TYPE_CHECKING: | ||
| from litellm.litellm_core_utils.tokenizer import Encoding, HuggingFace | ||
|
Comment on lines
+35
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Moving |
||
| from litellm.litellm_core_utils.url_utils import safe_get | ||
| from litellm.llms.custom_httpx.http_handler import get_httpx_client | ||
| from litellm.rust_bridge.tokenizer import get_encoding | ||
|
|
@@ -680,13 +683,13 @@ def encode_length(text: str) -> int: | |
| raise ValueError("Unsupported tokenizer type") | ||
|
|
||
|
|
||
| def _encoding_count(encoding: Encoding, text: str) -> int: | ||
| def _encoding_count(encoding: "Encoding", text: str) -> int: | ||
| if isinstance(encoding, OpenAIEncoding): | ||
| return encoding.count(text) | ||
| return len(encoding.encode(text, disallowed_special=())) | ||
|
|
||
|
|
||
| def openai_tokenizer_encoding(model: str) -> Encoding: | ||
| def openai_tokenizer_encoding(model: str) -> "Encoding": | ||
| """The encoding `token_counter` uses for a model on the `openai_tokenizer` path.""" | ||
| return get_encoding(openai_tokenizer_encoding_name(model)) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.