donkey-embeddings-huggingface 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- donkey_embeddings_huggingface-0.1.0/.gitignore +85 -0
- donkey_embeddings_huggingface-0.1.0/PKG-INFO +25 -0
- donkey_embeddings_huggingface-0.1.0/README.md +9 -0
- donkey_embeddings_huggingface-0.1.0/donkey/embeddings/huggingface/__init__.py +3 -0
- donkey_embeddings_huggingface-0.1.0/donkey/embeddings/huggingface/base.py +43 -0
- donkey_embeddings_huggingface-0.1.0/pyproject.toml +30 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
#IDE
|
|
10
|
+
.DS_Store
|
|
11
|
+
.idea
|
|
12
|
+
.vscode
|
|
13
|
+
|
|
14
|
+
# Distribution / packaging
|
|
15
|
+
.Python
|
|
16
|
+
build/
|
|
17
|
+
develop-eggs/
|
|
18
|
+
dist/
|
|
19
|
+
downloads/
|
|
20
|
+
eggs/
|
|
21
|
+
.eggs/
|
|
22
|
+
lib/
|
|
23
|
+
lib64/
|
|
24
|
+
parts/
|
|
25
|
+
sdist/
|
|
26
|
+
var/
|
|
27
|
+
wheels/
|
|
28
|
+
share/python-wheels/
|
|
29
|
+
*.egg-info/
|
|
30
|
+
.installed.cfg
|
|
31
|
+
*.egg
|
|
32
|
+
MANIFEST
|
|
33
|
+
|
|
34
|
+
# PyInstaller
|
|
35
|
+
# Usually these files are written by a python script from a template
|
|
36
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
37
|
+
*.manifest
|
|
38
|
+
*.spec
|
|
39
|
+
|
|
40
|
+
# Installer logs
|
|
41
|
+
pip-log.txt
|
|
42
|
+
pip-delete-this-directory.txt
|
|
43
|
+
|
|
44
|
+
# Unit test / coverage reports
|
|
45
|
+
htmlcov/
|
|
46
|
+
.tox/
|
|
47
|
+
.nox/
|
|
48
|
+
.coverage
|
|
49
|
+
.coverage.*
|
|
50
|
+
.cache
|
|
51
|
+
nosetests.xml
|
|
52
|
+
coverage.xml
|
|
53
|
+
*.cover
|
|
54
|
+
*.py,cover
|
|
55
|
+
.hypothesis/
|
|
56
|
+
.pytest_cache/
|
|
57
|
+
cover/
|
|
58
|
+
|
|
59
|
+
# Mkdocs documentation
|
|
60
|
+
docs/_build/
|
|
61
|
+
docs/api_reference/site/
|
|
62
|
+
|
|
63
|
+
# Ruff
|
|
64
|
+
.ruff_cache/
|
|
65
|
+
|
|
66
|
+
# PyBuilder
|
|
67
|
+
.pybuilder/
|
|
68
|
+
target/
|
|
69
|
+
|
|
70
|
+
# Jupyter Notebook
|
|
71
|
+
.ipynb_checkpoints
|
|
72
|
+
|
|
73
|
+
# pyenv
|
|
74
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
75
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
76
|
+
.python-version
|
|
77
|
+
|
|
78
|
+
# Environments
|
|
79
|
+
.env
|
|
80
|
+
.venv
|
|
81
|
+
env/
|
|
82
|
+
venv/
|
|
83
|
+
ENV/
|
|
84
|
+
env.bak/
|
|
85
|
+
venv.bak/
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: donkey-embeddings-huggingface
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: donkey embeddings huggingface integration
|
|
5
|
+
Author-email: Leonardo Furnielis <leonardofurnielis@outlook.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Requires-Python: <3.14,>=3.11
|
|
8
|
+
Requires-Dist: donkey-core<0.2.0,>=0.1.0
|
|
9
|
+
Requires-Dist: hf-xet<1.5.0,>=1.4.2
|
|
10
|
+
Requires-Dist: sentence-transformers<6.0.0,>=5.2.3
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: pytest-asyncio<2.0.0,>=1.4.0; extra == 'dev'
|
|
13
|
+
Requires-Dist: pytest<10.0.0,>=9.1.1; extra == 'dev'
|
|
14
|
+
Requires-Dist: ruff<0.16.0,>=0.15.20; extra == 'dev'
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# Donkey embeddings integration - HuggingFace
|
|
18
|
+
|
|
19
|
+
HuggingFace sentence-transformers integration for Donkey.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install donkey-embeddings-huggingface
|
|
25
|
+
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from typing import Any, Literal
|
|
2
|
+
|
|
3
|
+
from donkey.core.bridge.pydantic import Field, PrivateAttr
|
|
4
|
+
from donkey.core.embeddings import BaseEmbedding, Embedding
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class HuggingFaceEmbedding(BaseEmbedding):
|
|
8
|
+
"""
|
|
9
|
+
HuggingFace `sentence_transformers` embedding models.
|
|
10
|
+
|
|
11
|
+
Attributes:
|
|
12
|
+
model_name (str): Hugging Face model to be used. Defaults to `sentence-transformers/all-MiniLM-L6-v2`.
|
|
13
|
+
device (str, optional): Device to run the model on. Supports `cpu` and `cuda`. Defaults to `cpu`.
|
|
14
|
+
|
|
15
|
+
Example:
|
|
16
|
+
```python
|
|
17
|
+
from donkey.embeddings.huggingface import HuggingFaceEmbedding
|
|
18
|
+
|
|
19
|
+
embedding = HuggingFaceEmbedding()
|
|
20
|
+
```
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
model_name: str = Field(
|
|
24
|
+
default="sentence-transformers/all-MiniLM-L6-v2",
|
|
25
|
+
description="Name of the embedding model",
|
|
26
|
+
)
|
|
27
|
+
device: Literal["cpu", "cuda"] = "cpu"
|
|
28
|
+
|
|
29
|
+
_client: Any = PrivateAttr()
|
|
30
|
+
|
|
31
|
+
def model_post_init(self, __context): # noqa: PYI063
|
|
32
|
+
from sentence_transformers import SentenceTransformer
|
|
33
|
+
|
|
34
|
+
self._client = SentenceTransformer(self.model_name, device=self.device)
|
|
35
|
+
|
|
36
|
+
def _get_text_embeddings(self, input: str | list[str]) -> list[Embedding]:
|
|
37
|
+
"""Embed one or more text strings."""
|
|
38
|
+
embeddings = self._client.encode_document(input).tolist()
|
|
39
|
+
|
|
40
|
+
if embeddings and all(isinstance(item, list) for item in embeddings):
|
|
41
|
+
return embeddings
|
|
42
|
+
else:
|
|
43
|
+
return [embeddings]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "donkey-embeddings-huggingface"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "donkey embeddings huggingface integration"
|
|
9
|
+
authors = [{ name = "Leonardo Furnielis", email = "leonardofurnielis@outlook.com" }]
|
|
10
|
+
license = { text = "Apache-2.0" }
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.11,<3.14"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"sentence-transformers>=5.2.3,<6.0.0",
|
|
15
|
+
"hf-xet>=1.4.2,<1.5.0",
|
|
16
|
+
"donkey-core>=0.1.0,<0.2.0",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[tool.hatch.build.targets.sdist]
|
|
20
|
+
include = ["donkey/"]
|
|
21
|
+
|
|
22
|
+
[tool.hatch.build.targets.wheel]
|
|
23
|
+
include = ["donkey/"]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
dev = [
|
|
27
|
+
"pytest>=9.1.1,<10.0.0",
|
|
28
|
+
"pytest-asyncio>=1.4.0,<2.0.0",
|
|
29
|
+
"ruff>=0.15.20,<0.16.0",
|
|
30
|
+
]
|