huggingface_hub
Adapted from the Griptape AI Framework documentation.
__all__ = ['HuggingFaceHubEmbeddingDriver']
module-attribute
Bases:
BaseEmbeddingDriver
Attributes
Name | Type | Description |
---|---|---|
api_token | str | Hugging Face Hub API token. |
model | str | Hugging Face Hub model name. |
client | InferenceClient | Custom InferenceApi . |
Source Code in griptape/drivers/embedding/huggingface_hub_embedding_driver.py
@define class HuggingFaceHubEmbeddingDriver(BaseEmbeddingDriver): """Hugging Face Hub Embedding Driver. Attributes: api_token: Hugging Face Hub API token. model: Hugging Face Hub model name. client: Custom `InferenceApi`. """ api_token: str = field(kw_only=True, metadata={"serializable": True}) _client: Optional[InferenceClient] = field( default=None, kw_only=True, alias="client", metadata={"serializable": False} ) @lazy_property() def client(self) -> InferenceClient: return import_optional_dependency("huggingface_hub").InferenceClient( model=self.model, token=self.api_token, ) def try_embed_chunk(self, chunk: str, **kwargs) -> list[float]: response = self.client.feature_extraction(chunk) return [float(val) for val in response.flatten().tolist()]
_client = field(default=None, kw_only=True, alias='client', metadata={'serializable': False})
class-attribute instance-attributeapi_token = field(kw_only=True, metadata={'serializable': True})
class-attribute instance-attribute
client()
Source Code in griptape/drivers/embedding/huggingface_hub_embedding_driver.py
@lazy_property() def client(self) -> InferenceClient: return import_optional_dependency("huggingface_hub").InferenceClient( model=self.model, token=self.api_token, )
try_embed_chunk(chunk, **kwargs)
Source Code in griptape/drivers/embedding/huggingface_hub_embedding_driver.py
def try_embed_chunk(self, chunk: str, **kwargs) -> list[float]: response = self.client.feature_extraction(chunk) return [float(val) for val in response.flatten().tolist()]
Could this page be better? Report a problem or suggest an addition!