-
Notifications
You must be signed in to change notification settings - Fork 528
Finally rename HfInference
to InferenceClient
#1258
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1d401e6
some docs tweaks
julien-c 81aa352
rename
julien-c 084abaf
Update README.md
julien-c cf5dfc6
Update README.md
julien-c d573716
rename files
julien-c 5801e1f
Add backward compat test
julien-c 9148639
Fix lint?
julien-c 1d477dc
Merge branch 'main' into inference-client
Vaibhavs10 7f30f15
Update package.json
julien-c efd7385
[agents] use workspace version of inference
julien-c dd429a4
Update pnpm-lock.yaml
julien-c b1ac358
make it compile
julien-c e04e627
re-generate snippets
julien-c b102a15
Empty commit
julien-c 25a5d64
Empty commit
julien-c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ await uploadFile({ | |
|
||
await inference.chatCompletion({ | ||
model: "meta-llama/Llama-3.1-8B-Instruct", | ||
provider: "sambanova", // or together, fal-ai, replicate, cohere … | ||
messages: [ | ||
{ | ||
role: "user", | ||
|
@@ -39,11 +40,11 @@ await inference.chatCompletion({ | |
], | ||
max_tokens: 512, | ||
temperature: 0.5, | ||
provider: "sambanova", // or together, fal-ai, replicate, cohere … | ||
}); | ||
|
||
await inference.textToImage({ | ||
model: "black-forest-labs/FLUX.1-dev", | ||
provider: "replicate", | ||
inputs: "a picture of a green bird", | ||
}); | ||
|
||
|
@@ -54,7 +55,7 @@ await inference.textToImage({ | |
|
||
This is a collection of JS libraries to interact with the Hugging Face API, with TS types included. | ||
|
||
- [@huggingface/inference](packages/inference/README.md): Use HF Inference API (serverless), Inference Endpoints (dedicated) and third-party Inference Providers to make calls to 100,000+ Machine Learning models | ||
- [@huggingface/inference](packages/inference/README.md): Use HF Inference API (serverless), Inference Endpoints (dedicated) and all supported Inference Providers to make calls to 100,000+ Machine Learning models | ||
- [@huggingface/hub](packages/hub/README.md): Interact with huggingface.co to create or delete repos and commit / download files | ||
- [@huggingface/agents](packages/agents/README.md): Interact with HF models through a natural language interface | ||
- [@huggingface/gguf](packages/gguf/README.md): A GGUF parser that works on remotely hosted files. | ||
|
@@ -84,7 +85,7 @@ npm install @huggingface/agents | |
Then import the libraries in your code: | ||
|
||
```ts | ||
import { HfInference } from "@huggingface/inference"; | ||
import { InferenceClient } from "@huggingface/inference"; | ||
import { HfAgent } from "@huggingface/agents"; | ||
import { createRepo, commit, deleteRepo, listFiles } from "@huggingface/hub"; | ||
import type { RepoId } from "@huggingface/hub"; | ||
|
@@ -96,7 +97,7 @@ You can run our packages with vanilla JS, without any bundler, by using a CDN or | |
|
||
```html | ||
<script type="module"> | ||
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm'; | ||
import { InferenceClient } from 'https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm'; | ||
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm"; | ||
</script> | ||
``` | ||
|
@@ -105,12 +106,12 @@ You can run our packages with vanilla JS, without any bundler, by using a CDN or | |
|
||
```ts | ||
// esm.sh | ||
import { HfInference } from "https://esm.sh/@huggingface/inference" | ||
import { InferenceClient } from "https://esm.sh/@huggingface/inference" | ||
import { HfAgent } from "https://esm.sh/@huggingface/agents"; | ||
|
||
import { createRepo, commit, deleteRepo, listFiles } from "https://esm.sh/@huggingface/hub" | ||
// or npm: | ||
import { HfInference } from "npm:@huggingface/inference" | ||
import { InferenceClient } from "npm:@huggingface/inference" | ||
import { HfAgent } from "npm:@huggingface/agents"; | ||
|
||
import { createRepo, commit, deleteRepo, listFiles } from "npm:@huggingface/hub" | ||
|
@@ -123,11 +124,11 @@ Get your HF access token in your [account settings](https://huggingface.co/setti | |
### @huggingface/inference examples | ||
|
||
```ts | ||
import { HfInference } from "@huggingface/inference"; | ||
import { InferenceClient } from "@huggingface/inference"; | ||
|
||
const HF_TOKEN = "hf_..."; | ||
|
||
const inference = new HfInference(HF_TOKEN); | ||
const inference = new InferenceClient(HF_TOKEN); | ||
|
||
// Chat completion API | ||
const out = await inference.chatCompletion({ | ||
|
@@ -179,7 +180,7 @@ await inference.imageToText({ | |
|
||
// Using your own dedicated inference endpoint: https://hf.co/docs/inference-endpoints/ | ||
const gpt2 = inference.endpoint('https://xyz.eu-west-1.aws.endpoints.huggingface.cloud/gpt2'); | ||
const { generated_text } = await gpt2.textGeneration({inputs: 'The answer to the universe is'}); | ||
const { generated_text } = await gpt2.textGeneration({ inputs: 'The answer to the universe is' }); | ||
|
||
// Chat Completion | ||
const llamaEndpoint = inference.endpoint( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
backward compatibility line ^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you have a preference vs.
export const HfInference = InferenceClient;
maybe @coyotte508?Otherwise i'll merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could have slapped
@deprecated
on itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oooh we have this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will strike through in the editor everytime
X
is called