Skip to content

Commit

Permalink
Update API inference documentation (automated)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanouticelina authored and github-actions[bot] committed Dec 28, 2024
1 parent 5c26ed3 commit 166d016
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 47 deletions.
4 changes: 4 additions & 0 deletions changed_files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
docs/api-inference/tasks/text-classification.md
docs/api-inference/tasks/zero-shot-classification.md
scripts/api-inference/package.json
scripts/api-inference/pnpm-lock.yaml
68 changes: 28 additions & 40 deletions docs/api-inference/tasks/text-classification.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,67 +37,54 @@ Explore all available models and find the one that suits you best [here](https:/
<inferencesnippet>

<curl>

```bash
curl https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1 \
-X POST \
-d '{"inputs": [{"text": "What is Paris?", "text_pair": "Paris is the capital of France"}]}' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer hf_***'
curl https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english \
-X POST \
-d '{"inputs": "I like you. I love you"}' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer hf_***'
```

</curl>

<python>

```python
```py
import requests

API_URL = "https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1"
API_URL = "https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english"
headers = {"Authorization": "Bearer hf_***"}

def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
output = query({
"inputs": [
{"text": "What is Paris?", "text_pair": "Paris is the capital of France"},
{"text": "What is Paris?", "text_pair": "London is the capital of England"}
]
"inputs": "I like you. I love you",
})
```

To use the Python client, see `huggingface_hub`'s [package reference](https://huggingface.co/docs/huggingface_hub/package_reference/inference_client#huggingface_hub.InferenceClient.text_classification).

</python>

<js>

```javascript
```js
async function query(data) {
const response = await fetch(
"https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1",
{
headers: {
Authorization: "Bearer hf_***",
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify(data),
}
);
const result = await response.json();
return result;
const response = await fetch(
"https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english",
{
headers: {
Authorization: "Bearer hf_***",
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify(data),
}
);
const result = await response.json();
return result;
}

query({
"inputs": [
{"text": "What is Paris?", "text_pair": "Paris is the capital of France"},
{"text": "What is Paris?", "text_pair": "London is the capital of England"}
]
}).then((response) => {
console.log(JSON.stringify(response));
query({"inputs": "I like you. I love you"}).then((response) => {
console.log(JSON.stringify(response));
});
```

Expand All @@ -107,6 +94,7 @@ To use the JavaScript client, see `huggingface.js`'s [package reference](https:/
</inferencesnippet>



### API specification

#### Request
Expand Down
1 change: 0 additions & 1 deletion docs/api-inference/tasks/zero-shot-classification.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ For more details about the `zero-shot-classification` task, check out its [dedic
### Recommended models

- [facebook/bart-large-mnli](https://huggingface.co/facebook/bart-large-mnli): Powerful zero-shot text classification model.
- [MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7](https://huggingface.co/MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7): Powerful zero-shot multilingual text classification model that can accomplish multiple tasks.

Explore all available models and find the one that suits you best [here](https://huggingface.co/models?inference=warm&pipeline_tag=zero-shot-classification&sort=trending).

Expand Down
2 changes: 1 addition & 1 deletion scripts/api-inference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@huggingface/tasks": "^0.13.11",
"@huggingface/tasks": "^0.13.13",
"@types/node": "^22.5.0",
"handlebars": "^4.7.8",
"node": "^20.17.0",
Expand Down
10 changes: 5 additions & 5 deletions scripts/api-inference/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 166d016

Please sign in to comment.