From 9dccadad0798ee6f83403d35f12fbe589f6ca3d5 Mon Sep 17 00:00:00 2001 From: muhtasham Date: Fri, 20 Dec 2024 04:12:08 +0100 Subject: [PATCH 1/2] docs: update inference API examples for reranker model - Update code examples to show correct input format for reranker - Add examples for text/text_pair format required by mxbai-rerank-base-v1 - Include multiple input pairs to demonstrate batch processing - Update curl, Python and JavaScript examples consistently --- .../tasks/text-classification.md | 67 ++++++++++--------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/docs/api-inference/tasks/text-classification.md b/docs/api-inference/tasks/text-classification.md index 83cf43653..9fbc2adc8 100644 --- a/docs/api-inference/tasks/text-classification.md +++ b/docs/api-inference/tasks/text-classification.md @@ -38,63 +38,66 @@ Explore all available models and find the one that suits you best [here](https:/ ```bash -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 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_***' ``` -```py +```python import requests -API_URL = "https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english" +API_URL = "https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1" 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": "I like you. I love you", + "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"} + ] }) ``` - -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). -```js +```javascript async function query(data) { - 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; + 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; } -query({"inputs": "I like you. I love you"}).then((response) => { - console.log(JSON.stringify(response)); +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)); }); ``` - -To use the JavaScript client, see `huggingface.js`'s [package reference](https://huggingface.co/docs/huggingface.js/inference/classes/HfInference#textclassification). - ### API specification #### Request From cccc3225dac68a3003bb05174d8ab83a3b57ccc7 Mon Sep 17 00:00:00 2001 From: muhtasham Date: Wed, 25 Dec 2024 23:44:28 +0100 Subject: [PATCH 2/2] undo hf lib reference --- docs/api-inference/tasks/text-classification.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/api-inference/tasks/text-classification.md b/docs/api-inference/tasks/text-classification.md index 9fbc2adc8..f90a9d5e8 100644 --- a/docs/api-inference/tasks/text-classification.md +++ b/docs/api-inference/tasks/text-classification.md @@ -37,6 +37,7 @@ Explore all available models and find the one that suits you best [here](https:/ + ```bash curl https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1 \ -X POST \ @@ -44,9 +45,11 @@ curl https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base -H 'Content-Type: application/json' \ -H 'Authorization: Bearer hf_***' ``` + + ```python import requests @@ -64,9 +67,13 @@ output = query({ ] }) ``` + +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). + + ```javascript async function query(data) { const response = await fetch( @@ -93,6 +100,8 @@ query({ console.log(JSON.stringify(response)); }); ``` + +To use the JavaScript client, see `huggingface.js`'s [package reference](https://huggingface.co/docs/huggingface.js/inference/classes/HfInference#textclassification).