trustgraph-embeddings-hf 0.11.11__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,29 @@
1
+ Metadata-Version: 2.1
2
+ Name: trustgraph-embeddings-hf
3
+ Version: 0.11.11
4
+ Summary: HuggingFace embeddings support for TrustGraph.
5
+ Home-page: https://github.com/trustgraph-ai/trustgraph
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.11.11.tar.gz
7
+ Author: trustgraph.ai
8
+ Author-email: security@trustgraph.ai
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: trustgraph-base
15
+ Requires-Dist: trustgraph-flow
16
+ Requires-Dist: torch
17
+ Requires-Dist: urllib3
18
+ Requires-Dist: transformers
19
+ Requires-Dist: sentence-transformers
20
+ Requires-Dist: langchain
21
+ Requires-Dist: langchain-core
22
+ Requires-Dist: langchain-huggingface
23
+ Requires-Dist: langchain-community
24
+ Requires-Dist: huggingface-hub
25
+ Requires-Dist: pulsar-client
26
+ Requires-Dist: pyyaml
27
+ Requires-Dist: prometheus-client
28
+
29
+ See https://trustgraph.ai/
@@ -0,0 +1 @@
1
+ See https://trustgraph.ai/
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from trustgraph.embeddings.hf import run
4
+
5
+ run()
6
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,55 @@
1
+ import setuptools
2
+ import os
3
+ import importlib
4
+
5
+ with open("README.md", "r") as fh:
6
+ long_description = fh.read()
7
+
8
+ # Load a version number module
9
+ spec = importlib.util.spec_from_file_location(
10
+ 'version', 'trustgraph/embeddings_hf_version.py'
11
+ )
12
+ version_module = importlib.util.module_from_spec(spec)
13
+ spec.loader.exec_module(version_module)
14
+
15
+ version = version_module.__version__
16
+
17
+ setuptools.setup(
18
+ name="trustgraph-embeddings-hf",
19
+ version=version,
20
+ author="trustgraph.ai",
21
+ author_email="security@trustgraph.ai",
22
+ description="HuggingFace embeddings support for TrustGraph.",
23
+ long_description=long_description,
24
+ long_description_content_type="text/markdown",
25
+ url="https://github.com/trustgraph-ai/trustgraph",
26
+ packages=setuptools.find_namespace_packages(
27
+ where='./',
28
+ ),
29
+ classifiers=[
30
+ "Programming Language :: Python :: 3",
31
+ "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
32
+ "Operating System :: OS Independent",
33
+ ],
34
+ python_requires='>=3.8',
35
+ download_url = "https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v" + version + ".tar.gz",
36
+ install_requires=[
37
+ "trustgraph-base",
38
+ "trustgraph-flow",
39
+ "torch",
40
+ "urllib3",
41
+ "transformers",
42
+ "sentence-transformers",
43
+ "langchain",
44
+ "langchain-core",
45
+ "langchain-huggingface",
46
+ "langchain-community",
47
+ "huggingface-hub",
48
+ "pulsar-client",
49
+ "pyyaml",
50
+ "prometheus-client",
51
+ ],
52
+ scripts=[
53
+ "scripts/embeddings-hf",
54
+ ]
55
+ )
@@ -0,0 +1,3 @@
1
+
2
+ from . hf import *
3
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from . hf import run
4
+
5
+ if __name__ == '__main__':
6
+ run()
7
+
@@ -0,0 +1,100 @@
1
+
2
+ """
3
+ Embeddings service, applies an embeddings model selected from HuggingFace.
4
+ Input is text, output is embeddings vector.
5
+ """
6
+
7
+ from langchain_huggingface import HuggingFaceEmbeddings
8
+
9
+ from trustgraph.schema import EmbeddingsRequest, EmbeddingsResponse, Error
10
+ from trustgraph.schema import embeddings_request_queue
11
+ from trustgraph.schema import embeddings_response_queue
12
+ from trustgraph.log_level import LogLevel
13
+ from trustgraph.base import ConsumerProducer
14
+
15
+ module = ".".join(__name__.split(".")[1:-1])
16
+
17
+ default_input_queue = embeddings_request_queue
18
+ default_output_queue = embeddings_response_queue
19
+ default_subscriber = module
20
+ default_model="all-MiniLM-L6-v2"
21
+
22
+ class Processor(ConsumerProducer):
23
+
24
+ def __init__(self, **params):
25
+
26
+ input_queue = params.get("input_queue", default_input_queue)
27
+ output_queue = params.get("output_queue", default_output_queue)
28
+ subscriber = params.get("subscriber", default_subscriber)
29
+ model = params.get("model", default_model)
30
+
31
+ super(Processor, self).__init__(
32
+ **params | {
33
+ "input_queue": input_queue,
34
+ "output_queue": output_queue,
35
+ "subscriber": subscriber,
36
+ "input_schema": EmbeddingsRequest,
37
+ "output_schema": EmbeddingsResponse,
38
+ }
39
+ )
40
+
41
+ self.embeddings = HuggingFaceEmbeddings(model_name=model)
42
+
43
+ def handle(self, msg):
44
+
45
+ v = msg.value()
46
+
47
+ # Sender-produced ID
48
+ id = msg.properties()["id"]
49
+
50
+ print(f"Handling input {id}...", flush=True)
51
+
52
+ try:
53
+
54
+ text = v.text
55
+ embeds = self.embeddings.embed_documents([text])
56
+
57
+ print("Send response...", flush=True)
58
+ r = EmbeddingsResponse(vectors=embeds, error=None)
59
+ self.producer.send(r, properties={"id": id})
60
+
61
+ print("Done.", flush=True)
62
+
63
+
64
+ except Exception as e:
65
+
66
+ print(f"Exception: {e}")
67
+
68
+ print("Send error response...", flush=True)
69
+
70
+ r = EmbeddingsResponse(
71
+ error=Error(
72
+ type = "llm-error",
73
+ message = str(e),
74
+ ),
75
+ response=None,
76
+ )
77
+
78
+ self.producer.send(r, properties={"id": id})
79
+
80
+ self.consumer.acknowledge(msg)
81
+
82
+
83
+ @staticmethod
84
+ def add_args(parser):
85
+
86
+ ConsumerProducer.add_args(
87
+ parser, default_input_queue, default_subscriber,
88
+ default_output_queue,
89
+ )
90
+
91
+ parser.add_argument(
92
+ '-m', '--model',
93
+ default="all-MiniLM-L6-v2",
94
+ help=f'LLM model (default: all-MiniLM-L6-v2)'
95
+ )
96
+
97
+ def run():
98
+
99
+ Processor.start(module, __doc__)
100
+
@@ -0,0 +1 @@
1
+ __version__ = "0.11.11"
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.1
2
+ Name: trustgraph-embeddings-hf
3
+ Version: 0.11.11
4
+ Summary: HuggingFace embeddings support for TrustGraph.
5
+ Home-page: https://github.com/trustgraph-ai/trustgraph
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.11.11.tar.gz
7
+ Author: trustgraph.ai
8
+ Author-email: security@trustgraph.ai
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ Requires-Dist: trustgraph-base
15
+ Requires-Dist: trustgraph-flow
16
+ Requires-Dist: torch
17
+ Requires-Dist: urllib3
18
+ Requires-Dist: transformers
19
+ Requires-Dist: sentence-transformers
20
+ Requires-Dist: langchain
21
+ Requires-Dist: langchain-core
22
+ Requires-Dist: langchain-huggingface
23
+ Requires-Dist: langchain-community
24
+ Requires-Dist: huggingface-hub
25
+ Requires-Dist: pulsar-client
26
+ Requires-Dist: pyyaml
27
+ Requires-Dist: prometheus-client
28
+
29
+ See https://trustgraph.ai/
@@ -0,0 +1,14 @@
1
+ README.md
2
+ setup.py
3
+ scripts/embeddings-hf
4
+ trustgraph/__init__.py
5
+ trustgraph/embeddings_hf_version.py
6
+ trustgraph/embeddings/__init__.py
7
+ trustgraph/embeddings/hf/__init__.py
8
+ trustgraph/embeddings/hf/__main__.py
9
+ trustgraph/embeddings/hf/hf.py
10
+ trustgraph_embeddings_hf.egg-info/PKG-INFO
11
+ trustgraph_embeddings_hf.egg-info/SOURCES.txt
12
+ trustgraph_embeddings_hf.egg-info/dependency_links.txt
13
+ trustgraph_embeddings_hf.egg-info/requires.txt
14
+ trustgraph_embeddings_hf.egg-info/top_level.txt
@@ -0,0 +1,14 @@
1
+ trustgraph-base
2
+ trustgraph-flow
3
+ torch
4
+ urllib3
5
+ transformers
6
+ sentence-transformers
7
+ langchain
8
+ langchain-core
9
+ langchain-huggingface
10
+ langchain-community
11
+ huggingface-hub
12
+ pulsar-client
13
+ pyyaml
14
+ prometheus-client