Skip to content

Commit

Permalink
Partial revert #2851: allow task override on sentence-similarity
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin committed Feb 14, 2025
1 parent 166f174 commit cc0f4ae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/huggingface_hub/inference/_providers/hf_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ def _prepare_url(self, api_key: str, mapped_model: str) -> str:
# hf-inference provider can handle URLs (e.g. Inference Endpoints or TGI deployment)
if mapped_model.startswith(("http://", "https://")):
return mapped_model
return f"{self.base_url}/models/{mapped_model}"
return (
# Feature-extraction and sentence-similarity are the only cases where we handle models with several tasks.
f"{self.base_url}/pipeline/{self.task}/{mapped_model}"
if self.task in ("feature-extraction", "sentence-similarity")
# Otherwise, we use the default endpoint
else f"{self.base_url}/models/{mapped_model}"
)

def _prepare_payload(self, inputs: Any, parameters: Dict, mapped_model: str) -> Optional[Dict]:
if isinstance(inputs, bytes):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interactions:
X-Amzn-Trace-Id:
- 0434ff33-56fe-49db-9380-17b81e41f756
method: POST
uri: https://router.huggingface.co/hf-inference/models/sentence-transformers/all-MiniLM-L6-v2
uri: https://router.huggingface.co/hf-inference/pipeline/sentence-similarity/sentence-transformers/all-MiniLM-L6-v2
response:
body:
string: '[0.7785724997520447,0.4587624967098236,0.29062220454216003]'
Expand Down
2 changes: 1 addition & 1 deletion tests/cassettes/test_async_sentence_similarity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ interactions:
body: null
headers: {}
method: POST
uri: https://router.huggingface.co/hf-inference/models/sentence-transformers/all-MiniLM-L6-v2
uri: https://router.huggingface.co/hf-inference/pipeline/sentence-similarity/sentence-transformers/all-MiniLM-L6-v2
response:
body:
string: '[0.7785724997520447,0.4587624967098236,0.29062220454216003]'
Expand Down

0 comments on commit cc0f4ae

Please sign in to comment.