repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import os |
| #2 | from typing import Optional |
| #3 | |
| #4 | from langchain_community.embeddings import HuggingFaceEmbeddings |
| #5 | |
| #6 | try: |
| #7 | from langchain_huggingface import HuggingFaceEndpointEmbeddings |
| #8 | except ModuleNotFoundError: |
| #9 | raise ModuleNotFoundError( |
| #10 | "The required dependencies for HuggingFaceHub are not installed." |
| #11 | "Please install with `pip install langchain_huggingface`" |
| #12 | ) from None |
| #13 | |
| #14 | from embedchain.config import BaseEmbedderConfig |
| #15 | from embedchain.embedder.base import BaseEmbedder |
| #16 | from embedchain.models import VectorDimensions |
| #17 | |
| #18 | |
| #19 | class HuggingFaceEmbedder(BaseEmbedder): |
| #20 | def __init__(self, config: Optional[BaseEmbedderConfig] = None): |
| #21 | super().__init__(config=config) |
| #22 | |
| #23 | if self.config.endpoint: |
| #24 | if not self.config.api_key and "HUGGINGFACE_ACCESS_TOKEN" not in os.environ: |
| #25 | raise ValueError( |
| #26 | "Please set the HUGGINGFACE_ACCESS_TOKEN environment variable or pass API Key in the config." |
| #27 | ) |
| #28 | |
| #29 | embeddings = HuggingFaceEndpointEmbeddings( |
| #30 | model=self.config.endpoint, |
| #31 | huggingfacehub_api_token=self.config.api_key or os.getenv("HUGGINGFACE_ACCESS_TOKEN"), |
| #32 | ) |
| #33 | else: |
| #34 | embeddings = HuggingFaceEmbeddings(model_name=self.config.model, model_kwargs=self.config.model_kwargs) |
| #35 | |
| #36 | embedding_fn = BaseEmbedder._langchain_default_concept(embeddings) |
| #37 | self.set_embedding_fn(embedding_fn=embedding_fn) |
| #38 | |
| #39 | vector_dimension = self.config.vector_dimension or VectorDimensions.HUGGING_FACE.value |
| #40 | self.set_vector_dimension(vector_dimension=vector_dimension) |
| #41 |