Skip to content

Commit

Permalink
Support of custom hugging face inference endpoints url (langchain-ai#…
Browse files Browse the repository at this point in the history
…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:** langchain-ai#9181,
  - **Dependencies:** no extra dependencies
  • Loading branch information
dmitryrPlanner5D authored and aymeric-roucher committed Dec 11, 2023
1 parent ab50a60 commit 25eacbb
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libs/langchain/langchain/embeddings/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 25eacbb

Please sign in to comment.