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
provider: "sambanova", // or together, fal-ai, replicate, …
42
43
});
43
44
44
45
awaitinference.textToImage({
@@ -53,11 +54,13 @@ await inference.textToImage({
53
54
54
55
This is a collection of JS libraries to interact with the Hugging Face API, with TS types included.
55
56
56
-
-[@huggingface/inference](packages/inference/README.md): Use Inference Endpoints (dedicated) and Inference API (serverless) to make calls to 100,000+ Machine Learning models
57
+
-[@huggingface/inference](packages/inference/README.md): Use Inference API (serverless), Inference Endpoints (dedicated) and third-party Inference providers to make calls to 100,000+ Machine Learning models
57
58
-[@huggingface/hub](packages/hub/README.md): Interact with huggingface.co to create or delete repos and commit / download files
58
59
-[@huggingface/agents](packages/agents/README.md): Interact with HF models through a natural language interface
59
60
-[@huggingface/gguf](packages/gguf/README.md): A GGUF parser that works on remotely hosted files.
61
+
-[@huggingface/dduf](packages/dduf/README.md): Similar package for DDUF (DDUF Diffusers Unified Format)
60
62
-[@huggingface/tasks](packages/tasks/README.md): The definition files and source-of-truth for the Hub's main primitives like pipeline tasks, model libraries, etc.
63
+
-[@huggingface/jinja](packages/jinja/README.md): A minimalistic JS implementation of the Jinja templating engine, to be used for ML chat templates.
61
64
-[@huggingface/space-header](packages/space-header/README.md): Use the Space `mini_header` outside Hugging Face
62
65
63
66
@@ -92,7 +95,7 @@ You can run our packages with vanilla JS, without any bundler, by using a CDN or
Copy file name to clipboardexpand all lines: packages/inference/README.md
+36-3
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# 🤗 Hugging Face Inference Endpoints
2
2
3
-
A Typescript powered wrapper for the Hugging Face Inference Endpoints API. Learn more about Inference Endpoints at [Hugging Face](https://huggingface.co/inference-endpoints).
4
-
It works with both [Inference API (serverless)](https://huggingface.co/docs/api-inference/index) and [Inference Endpoints (dedicated)](https://huggingface.co/docs/inference-endpoints/index).
3
+
A Typescript powered wrapper for the Hugging Face Inference API (serverless), Inference Endpoints (dedicated), and third-party Inference Providers.
4
+
It works with [Inference API (serverless)](https://huggingface.co/docs/api-inference/index) and [Inference Endpoints (dedicated)](https://huggingface.co/docs/inference-endpoints/index), and even with supported third-party Inference Providers.
5
5
6
6
Check out the [full documentation](https://huggingface.co/docs/huggingface.js/inference/README).
Your access token should be kept private. If you need to protect it in front-end applications, we suggest setting up a proxy server that stores the access token.
44
44
45
-
#### Tree-shaking
45
+
### Third-party inference providers
46
+
47
+
You can send inference requests to third-party providers with the inference client.
48
+
49
+
Currently, we support the following providers: [Fal.ai](https://fal.ai), [Replicate](https://replicate.com), [Together](https://together.xyz) and [Sambanova](https://sambanova.ai).
50
+
51
+
To send requests to a third-party provider, you have to pass the `provider` parameter to the inference function. Make sure your request is authenticated with an access token.
52
+
```ts
53
+
const accessToken ="hf_..."; // Either a HF access token, or an API key from the third-party provider (Replicate in this example)
54
+
55
+
const client =newHfInference(accessToken);
56
+
awaitclient.textToImage({
57
+
provider: "replicate",
58
+
model:"black-forest-labs/Flux.1-dev",
59
+
inputs: "A black forest cake"
60
+
})
61
+
```
62
+
63
+
When authenticated with a Hugging Face access token, the request is routed through https://huggingface.co.
64
+
When authenticated with a third-party provider key, the request is made directly against that provider's inference API.
65
+
66
+
Only a subset of models are supported when requesting third-party providers. You can check the list of supported models per pipeline tasks here:
-[HF Inference API (serverless)](https://huggingface.co/models?inference=warm&sort=trending)
72
+
73
+
❗**Important note:** To be compatible, the third-party API must adhere to the "standard" shape API we expect on HF model pages for each pipeline task type.
74
+
This is not an issue for LLMs as everyone converged on the OpenAI API anyways, but can be more tricky for other tasks like "text-to-image" or "automatic-speech-recognition" where there exists no standard API. Let us know if any help is needed or if we can make things easier for you!
75
+
76
+
👋**Want to add another provider?** Get in touch if you'd like to add support for another Inference provider, and/or request it on https://huggingface.co/spaces/huggingface/HuggingDiscussions/discussions/49
77
+
78
+
### Tree-shaking
46
79
47
80
You can import the functions you need directly from the module instead of using the `HfInference` class.
0 commit comments