You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Same as huggingface/huggingface_hub#3011.
This PR adds support for auto selection of the provider. Previously the
default value was `hf-inference` (HF Inference API provider), now we
default to "auto", meaning we will select the first of the providers
available for the model, sorted by the user's order in
https://hf.co/settings/inference-providers.
you can test with:
```ts
import { chatCompletion } from "../src";
const res = await chatCompletion({
// provider="auto",
model: "deepseek-ai/DeepSeek-V3-0324",
messages: [
{
role: "user",
content: "What is the capital of France?",
},
],
accessToken: process.env.HF_TOKEN,
});
console.log(res.choices[0].message.content);
```
```
Defaulting to 'auto' which will select the first provider available for the model, sorted by the user's order in https://hf.co/settings/inference-providers.
Auto-selected provider: sambanova
The capital of France is **Paris**. It is known for its iconic landmarks such as the Eiffel Tower...blabla
```
the selected provider should be be the first in
`inferenceProviderMapping` mapping here:
https://huggingface.co/api/models/deepseek-ai/DeepSeek-V3-0324?expand=inferenceProviderMapping
@@ -78,3 +96,23 @@ export async function getInferenceProviderMapping(
78
96
}
79
97
returnnull;
80
98
}
99
+
100
+
exportasyncfunctionresolveProvider(
101
+
provider?: InferenceProviderOrPolicy,
102
+
modelId?: string
103
+
): Promise<InferenceProvider>{
104
+
if(!provider){
105
+
console.log(
106
+
"Defaulting to 'auto' which will select the first provider available for the model, sorted by the user's order in https://hf.co/settings/inference-providers."
107
+
);
108
+
provider="auto";
109
+
}
110
+
if(provider==="auto"){
111
+
if(!modelId){
112
+
thrownewError("Specifying a model is required when provider is 'auto'");
0 commit comments