From aaabc1574fbeb8e0b4e2d4d9d0660df68b4a4e47 Mon Sep 17 00:00:00 2001 From: Dmitrii Rashchenko Date: Mon, 4 Dec 2023 22:08:51 +0200 Subject: [PATCH] Support of custom hugging face inference endpoints url (#14125) - **Description:** to support not only publicly available Hugging Face endpoints, but also protected ones (created with "Inference Endpoints" Hugging Face feature), I have added ability to specify custom api_url. But if not specified, default behaviour won't change - **Issue:** #9181, - **Dependencies:** no extra dependencies --- libs/langchain/langchain/embeddings/huggingface.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/langchain/langchain/embeddings/huggingface.py b/libs/langchain/langchain/embeddings/huggingface.py index 823e1902a3c..a835da8775b 100644 --- a/libs/langchain/langchain/embeddings/huggingface.py +++ b/libs/langchain/langchain/embeddings/huggingface.py @@ -279,9 +279,15 @@ class HuggingFaceInferenceAPIEmbeddings(BaseModel, Embeddings): """Your API key for the HuggingFace Inference API.""" model_name: str = "sentence-transformers/all-MiniLM-L6-v2" """The name of the model to use for text embeddings.""" + api_url: Optional[str] = None + """Custom inference endpoint url. None for using default public url.""" @property def _api_url(self) -> str: + return self.api_url or self._default_api_url + + @property + def _default_api_url(self) -> str: return ( "https://api-inference.huggingface.co" "/pipeline"