donkey-embeddings-watsonx 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.
@@ -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,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: donkey-embeddings-watsonx
3
+ Version: 0.1.0
4
+ Summary: donkey embeddings watsonx 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: ibm-watsonx-ai<1.6.0,>=1.5.5
10
+ Provides-Extra: dev
11
+ Requires-Dist: pytest-asyncio<2.0.0,>=1.4.0; extra == 'dev'
12
+ Requires-Dist: pytest<10.0.0,>=9.1.1; extra == 'dev'
13
+ Requires-Dist: ruff<0.16.0,>=0.15.20; extra == 'dev'
14
+ Description-Content-Type: text/markdown
15
+
16
+ # Donkey embeddings integration - watsonx
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install donkey-embeddings-watsonx
22
+ ```
@@ -0,0 +1,7 @@
1
+ # Donkey embeddings integration - watsonx
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ pip install donkey-embeddings-watsonx
7
+ ```
@@ -0,0 +1,3 @@
1
+ from donkey.embeddings.watsonx.base import WatsonxEmbedding
2
+
3
+ __all__ = ["WatsonxEmbedding"]
@@ -0,0 +1,85 @@
1
+ from typing import Any
2
+
3
+ from donkey.core.bridge.pydantic import Field, PrivateAttr, SecretStr
4
+ from donkey.core.embeddings import BaseEmbedding, Embedding
5
+
6
+
7
+ class WatsonxEmbedding(BaseEmbedding):
8
+ """
9
+ IBM watsonx embedding models.
10
+
11
+ Note:
12
+ One of these parameters is required: `project_id` or `space_id`. Not both.
13
+
14
+ See [https://cloud.ibm.com/apidocs/watsonx-ai#endpoint-url](https://cloud.ibm.com/apidocs/watsonx-ai#endpoint-url) for the watsonx.ai API endpoints.
15
+
16
+ Attributes:
17
+ model_name (str): IBM watsonx.ai model to be used. Defaults to `ibm/slate-30m-english-rtrvr`.
18
+ api_key (str): watsonx API key.
19
+ url (str): watsonx instance url.
20
+ truncate_input_tokens (str): Maximum number of input tokens accepted. Defaults to `512`
21
+ project_id (str, optional): watsonx project_id.
22
+ space_id (str, optional): watsonx space_id.
23
+
24
+ Example:
25
+ ```python
26
+ from donkey.embeddings.watsonx import WatsonxEmbedding
27
+
28
+ watsonx_embedding = WatsonxEmbedding(
29
+ api_key="your_api_key",
30
+ url="your_instance_url",
31
+ project_id="your_project_id",
32
+ )
33
+ ```
34
+ """
35
+
36
+ model_name: str = Field(
37
+ default="ibm/slate-30m-english-rtrvr",
38
+ description="Name of the embedding model",
39
+ )
40
+ api_key: SecretStr
41
+ url: str
42
+ truncate_input_tokens: int = 512
43
+ project_id: str | None = None
44
+ space_id: str | None = None
45
+
46
+ _client: Any = PrivateAttr()
47
+
48
+ def model_post_init(self, __context): # noqa: PYI063
49
+ from ibm_watsonx_ai import Credentials
50
+ from ibm_watsonx_ai.foundation_models import Embeddings as WatsonxEmbeddings
51
+
52
+ if (not (self.project_id or self.space_id)) or (
53
+ self.project_id and self.space_id
54
+ ):
55
+ raise ValueError(
56
+ "Must provide ONE of these parameters [`project_id`, `space_id`], not both.",
57
+ )
58
+
59
+ kwargs_params = {
60
+ "model_id": self.model_name,
61
+ "params": {
62
+ "truncate_input_tokens": self.truncate_input_tokens,
63
+ "return_options": {"input_text": False},
64
+ },
65
+ "credentials": Credentials(
66
+ api_key=self.api_key.get_secret_value(), url=self.url
67
+ ),
68
+ }
69
+
70
+ if self.project_id:
71
+ kwargs_params["project_id"] = self.project_id
72
+ else:
73
+ kwargs_params["space_id"] = self.space_id
74
+
75
+ self._client = WatsonxEmbeddings(**kwargs_params)
76
+
77
+ def _get_text_embeddings(self, input: str | list[str]) -> list[Embedding]:
78
+ """Embed one or more text strings."""
79
+ if isinstance(input, str):
80
+ return [self._client.embed_query(input)]
81
+
82
+ elif isinstance(input, list) and all(isinstance(i, str) for i in input):
83
+ return self._client.embed_documents(input)
84
+ else:
85
+ raise TypeError(f"Expected str or list[str], got {type(input).__name__}")
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "donkey-embeddings-watsonx"
7
+ version = "0.1.0"
8
+ description = "donkey embeddings watsonx 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
+ "ibm-watsonx-ai>=1.5.5,<1.6.0",
15
+ "donkey-core>=0.1.0,<0.2.0",
16
+ ]
17
+
18
+ [tool.hatch.build.targets.sdist]
19
+ include = ["donkey/"]
20
+
21
+ [tool.hatch.build.targets.wheel]
22
+ include = ["donkey/"]
23
+
24
+ [project.optional-dependencies]
25
+ dev = [
26
+ "pytest>=9.1.1,<10.0.0",
27
+ "pytest-asyncio>=1.4.0,<2.0.0",
28
+ "ruff>=0.15.20,<0.16.0",
29
+ ]