diff --git a/src/huggingface_hub/inference/_client.py b/src/huggingface_hub/inference/_client.py index 38b37b71e3..8fa9e80b73 100644 --- a/src/huggingface_hub/inference/_client.py +++ b/src/huggingface_hub/inference/_client.py @@ -3003,6 +3003,10 @@ def _resolve_url(self, model: Optional[str] = None, task: Optional[str] = None) # If model is already a URL, ignore `task` and return directly if model is not None and (model.startswith("http://") or model.startswith("https://")): + # special case for sentence-similarity with TEI endpoints for which we need to add the `/similarity` suffix. + # see: https://huggingface.github.io/text-embeddings-inference/openapi.json. + if task == "sentence-similarity": + model += "/similarity" return model # # If no model but task is set => fetch the recommended one for this task diff --git a/src/huggingface_hub/inference/_generated/_async_client.py b/src/huggingface_hub/inference/_generated/_async_client.py index 8a1384a671..bb13b3be93 100644 --- a/src/huggingface_hub/inference/_generated/_async_client.py +++ b/src/huggingface_hub/inference/_generated/_async_client.py @@ -3116,6 +3116,10 @@ def _resolve_url(self, model: Optional[str] = None, task: Optional[str] = None) # If model is already a URL, ignore `task` and return directly if model is not None and (model.startswith("http://") or model.startswith("https://")): + # special case for sentence-similarity with TEI endpoints for which we need to add the `/similarity` suffix. + # see: https://huggingface.github.io/text-embeddings-inference/openapi.json. + if task == "sentence-similarity": + model += "/similarity" return model # # If no model but task is set => fetch the recommended one for this task