Skip to content

Commit a0429e7

Browse files
authored
ADd Groq provider (#3157)
1 parent 4cc3143 commit a0429e7

File tree

7 files changed

+55
-32
lines changed

7 files changed

+55
-32
lines changed

docs/source/en/guides/inference.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -207,36 +207,36 @@ For more details, refer to the [Inference Providers pricing documentation](https
207207

208208
[`InferenceClient`]'s goal is to provide the easiest interface to run inference on Hugging Face models, on any provider. It has a simple API that supports the most common tasks. Here is a table showing which providers support which tasks:
209209

210-
| Task | Black Forest Labs | Cerebras | Cohere | fal-ai | Featherless AI | Fireworks AI | HF Inference | Hyperbolic | Nebius AI Studio | Novita AI | Replicate | Sambanova | Together |
211-
| --------------------------------------------------- | ----------------- | -------- | ------ | ------ | -------------- | ------------ | ------------ | ---------- | ---------------- | --------- | --------- | --------- | -------- |
212-
| [`~InferenceClient.audio_classification`] ||||||||||||||
213-
| [`~InferenceClient.audio_to_audio`] ||||||||||||||
214-
| [`~InferenceClient.automatic_speech_recognition`] ||||||||||||||
215-
| [`~InferenceClient.chat_completion`] ||||||||||||||
216-
| [`~InferenceClient.document_question_answering`] ||||||||||||||
217-
| [`~InferenceClient.feature_extraction`] ||||||||||||||
218-
| [`~InferenceClient.fill_mask`] ||||||||||||||
219-
| [`~InferenceClient.image_classification`] ||||||||||||||
220-
| [`~InferenceClient.image_segmentation`] ||||||||||||||
221-
| [`~InferenceClient.image_to_image`] ||||||||||||||
222-
| [`~InferenceClient.image_to_text`] ||||||||||||||
223-
| [`~InferenceClient.object_detection`] ||||||||||||||
224-
| [`~InferenceClient.question_answering`] ||||||||||||||
225-
| [`~InferenceClient.sentence_similarity`] ||||||||||||||
226-
| [`~InferenceClient.summarization`] ||||||||||||||
227-
| [`~InferenceClient.table_question_answering`] ||||||||||||||
228-
| [`~InferenceClient.text_classification`] ||||||||||||||
229-
| [`~InferenceClient.text_generation`] ||||||||||||||
230-
| [`~InferenceClient.text_to_image`] ||||||||||||||
231-
| [`~InferenceClient.text_to_speech`] ||||||||||||||
232-
| [`~InferenceClient.text_to_video`] ||||||||||||||
233-
| [`~InferenceClient.tabular_classification`] ||||||||||||||
234-
| [`~InferenceClient.tabular_regression`] ||||||||||||||
235-
| [`~InferenceClient.token_classification`] ||||||||||||||
236-
| [`~InferenceClient.translation`] ||||||||||||||
237-
| [`~InferenceClient.visual_question_answering`] ||||||||||||||
238-
| [`~InferenceClient.zero_shot_image_classification`] ||||||||||||||
239-
| [`~InferenceClient.zero_shot_classification`] ||||||||||||||
210+
| Task | Black Forest Labs | Cerebras | Cohere | fal-ai | Featherless AI | Fireworks AI | Groq | HF Inference | Hyperbolic | Nebius AI Studio | Novita AI | Replicate | Sambanova | Together |
211+
| --------------------------------------------------- | ----------------- | -------- | ------ | ------ | -------------- | ------------ | ---- | ------------ | ---------- | ---------------- | --------- | --------- | --------- | -------- |
212+
| [`~InferenceClient.audio_classification`] ||||| | | ||||||||
213+
| [`~InferenceClient.audio_to_audio`] ||||| | | ||||||||
214+
| [`~InferenceClient.automatic_speech_recognition`] ||||| | | ||||||||
215+
| [`~InferenceClient.chat_completion`] ||||| | | ||||||||
216+
| [`~InferenceClient.document_question_answering`] ||||| | | ||||||||
217+
| [`~InferenceClient.feature_extraction`] ||||| | | ||||||||
218+
| [`~InferenceClient.fill_mask`] ||||| | | ||||||||
219+
| [`~InferenceClient.image_classification`] ||||| | | ||||||||
220+
| [`~InferenceClient.image_segmentation`] ||||| | | ||||||||
221+
| [`~InferenceClient.image_to_image`] ||||| | | ||||||||
222+
| [`~InferenceClient.image_to_text`] ||||| | | ||||||||
223+
| [`~InferenceClient.object_detection`] ||||| || | |||||| | | |
224+
| [`~InferenceClient.question_answering`] ||||| | | ||||||||
225+
| [`~InferenceClient.sentence_similarity`] ||||| | | ||||||||
226+
| [`~InferenceClient.summarization`] ||||| | | ||||||||
227+
| [`~InferenceClient.table_question_answering`] ||||| | | ||||||||
228+
| [`~InferenceClient.text_classification`] ||||| | | ||||||||
229+
| [`~InferenceClient.text_generation`] ||||| | | ||||||||
230+
| [`~InferenceClient.text_to_image`] ||||| | | ||||||||
231+
| [`~InferenceClient.text_to_speech`] ||||| | | ||||||||
232+
| [`~InferenceClient.text_to_video`] ||||| | | ||||||||
233+
| [`~InferenceClient.tabular_classification`] ||||| | | ||||||||
234+
| [`~InferenceClient.tabular_regression`] ||||| | | ||||||||
235+
| [`~InferenceClient.token_classification`] ||||| | | ||||||||
236+
| [`~InferenceClient.translation`] ||||| | | ||||||||
237+
| [`~InferenceClient.visual_question_answering`] ||||| | | ||||||||
238+
| [`~InferenceClient.zero_shot_image_classification`] ||||| | | ||||||||
239+
| [`~InferenceClient.zero_shot_classification`] ||||| | | ||||||||
240240

241241
<Tip>
242242

src/huggingface_hub/inference/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class InferenceClient:
134134
path will be appended to the base URL (see the [TGI Messages API](https://huggingface.co/docs/text-generation-inference/en/messages_api)
135135
documentation for details). When passing a URL as `model`, the client will not append any suffix path to it.
136136
provider (`str`, *optional*):
137-
Name of the provider to use for inference. Can be `"black-forest-labs"`, `"cerebras"`, `"cohere"`, `"fal-ai"`, `"featherless-ai"`, `"fireworks-ai"`, `"hf-inference"`, `"hyperbolic"`, `"nebius"`, `"novita"`, `"nscale"`, `"openai"`, `"replicate"`, "sambanova"` or `"together"`.
137+
Name of the provider to use for inference. Can be `"black-forest-labs"`, `"cerebras"`, `"cohere"`, `"fal-ai"`, `"featherless-ai"`, `"fireworks-ai"`, `"groq"`, `"hf-inference"`, `"hyperbolic"`, `"nebius"`, `"novita"`, `"nscale"`, `"openai"`, `"replicate"`, "sambanova"` or `"together"`.
138138
Defaults to "auto" i.e. the first of the providers available for the model, sorted by the user's order in https://hf.co/settings/inference-providers.
139139
If model is a URL or `base_url` is passed, then `provider` is not used.
140140
token (`str`, *optional*):

src/huggingface_hub/inference/_generated/_async_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class AsyncInferenceClient:
122122
path will be appended to the base URL (see the [TGI Messages API](https://huggingface.co/docs/text-generation-inference/en/messages_api)
123123
documentation for details). When passing a URL as `model`, the client will not append any suffix path to it.
124124
provider (`str`, *optional*):
125-
Name of the provider to use for inference. Can be `"black-forest-labs"`, `"cerebras"`, `"cohere"`, `"fal-ai"`, `"featherless-ai"`, `"fireworks-ai"`, `"hf-inference"`, `"hyperbolic"`, `"nebius"`, `"novita"`, `"nscale"`, `"openai"`, `"replicate"`, "sambanova"` or `"together"`.
125+
Name of the provider to use for inference. Can be `"black-forest-labs"`, `"cerebras"`, `"cohere"`, `"fal-ai"`, `"featherless-ai"`, `"fireworks-ai"`, `"groq"`, `"hf-inference"`, `"hyperbolic"`, `"nebius"`, `"novita"`, `"nscale"`, `"openai"`, `"replicate"`, "sambanova"` or `"together"`.
126126
Defaults to "auto" i.e. the first of the providers available for the model, sorted by the user's order in https://hf.co/settings/inference-providers.
127127
If model is a URL or `base_url` is passed, then `provider` is not used.
128128
token (`str`, *optional*):

src/huggingface_hub/inference/_providers/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
FalAITextToVideoTask,
1818
)
1919
from .fireworks_ai import FireworksAIConversationalTask
20+
from .groq import GroqConversationalTask
2021
from .hf_inference import (
2122
HFInferenceBinaryInputTask,
2223
HFInferenceConversational,
@@ -48,6 +49,7 @@
4849
"fal-ai",
4950
"featherless-ai",
5051
"fireworks-ai",
52+
"groq",
5153
"hf-inference",
5254
"hyperbolic",
5355
"nebius",
@@ -84,6 +86,9 @@
8486
"fireworks-ai": {
8587
"conversational": FireworksAIConversationalTask(),
8688
},
89+
"groq": {
90+
"conversational": GroqConversationalTask(),
91+
},
8792
"hf-inference": {
8893
"text-to-image": HFInferenceTask("text-to-image"),
8994
"conversational": HFInferenceConversational(),

src/huggingface_hub/inference/_providers/_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"cohere": {},
2626
"fal-ai": {},
2727
"fireworks-ai": {},
28+
"groq": {},
2829
"hf-inference": {},
2930
"hyperbolic": {},
3031
"nebius": {},
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ._common import BaseConversationalTask
2+
3+
4+
class GroqConversationalTask(BaseConversationalTask):
5+
def __init__(self):
6+
super().__init__(provider="groq", base_url="https://api.groq.com")
7+
8+
def _prepare_route(self, mapped_model: str, api_key: str) -> str:
9+
return "/openai/v1/chat/completions"

0 commit comments

Comments
 (0)