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

Add type hints for providers #2788

Merged
merged 1 commit into from
Jan 27, 2025
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
4 changes: 2 additions & 2 deletions src/huggingface_hub/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
ZeroShotClassificationOutputElement,
ZeroShotImageClassificationOutputElement,
)
from huggingface_hub.inference._providers import HFInferenceTask, get_provider_helper
from huggingface_hub.inference._providers import PROVIDER_T, HFInferenceTask, get_provider_helper
from huggingface_hub.utils import build_hf_headers, get_session, hf_raise_for_status
from huggingface_hub.utils._deprecation import _deprecate_arguments, _deprecate_method

Expand Down Expand Up @@ -164,7 +164,7 @@ def __init__(
self,
model: Optional[str] = None,
*,
provider: Optional[str] = None,
provider: Optional[PROVIDER_T] = None,
token: Optional[str] = None,
timeout: Optional[float] = None,
headers: Optional[Dict[str, str]] = None,
Expand Down
4 changes: 2 additions & 2 deletions src/huggingface_hub/inference/_generated/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
ZeroShotClassificationOutputElement,
ZeroShotImageClassificationOutputElement,
)
from huggingface_hub.inference._providers import HFInferenceTask, get_provider_helper
from huggingface_hub.inference._providers import PROVIDER_T, HFInferenceTask, get_provider_helper
from huggingface_hub.utils import build_hf_headers, get_session, hf_raise_for_status
from huggingface_hub.utils._deprecation import _deprecate_arguments, _deprecate_method

Expand Down Expand Up @@ -154,7 +154,7 @@ def __init__(
self,
model: Optional[str] = None,
*,
provider: Optional[str] = None,
provider: Optional[PROVIDER_T] = None,
token: Optional[str] = None,
timeout: Optional[float] = None,
headers: Optional[Dict[str, str]] = None,
Expand Down
14 changes: 11 additions & 3 deletions src/huggingface_hub/inference/_providers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Dict, Literal

from .._common import TaskProviderHelper
from .fal_ai import FalAIAutomaticSpeechRecognitionTask, FalAITextToImageTask
Expand All @@ -8,7 +8,15 @@
from .together import TogetherTextGenerationTask, TogetherTextToImageTask


PROVIDERS: Dict[str, Dict[str, TaskProviderHelper]] = {
PROVIDER_T = Literal[
"fal-ai",
"hf-inference",
"replicate",
"sambanova",
"together",
]

PROVIDERS: Dict[PROVIDER_T, Dict[str, TaskProviderHelper]] = {
"fal-ai": {
"text-to-image": FalAITextToImageTask(),
"automatic-speech-recognition": FalAIAutomaticSpeechRecognitionTask(),
Expand Down Expand Up @@ -55,7 +63,7 @@
}


def get_provider_helper(provider: str, task: str) -> TaskProviderHelper:
def get_provider_helper(provider: PROVIDER_T, task: str) -> TaskProviderHelper:
"""Get provider helper instance by name and task.

Args:
Expand Down
Loading