trustgraph-base 0.21.0__tar.gz → 0.21.2__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.
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/PKG-INFO +2 -2
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/base/__init__.py +2 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/base/base_processor.py +23 -4
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/base/consumer.py +3 -2
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/base/consumer_producer.py +1 -1
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/base/producer.py +1 -1
- trustgraph-base-0.21.2/trustgraph/base/publisher.py +63 -0
- trustgraph-base-0.21.2/trustgraph/base/subscriber.py +114 -0
- trustgraph-base-0.21.2/trustgraph/base_version.py +1 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/exceptions.py +3 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/schema/__init__.py +1 -0
- trustgraph-base-0.21.2/trustgraph/schema/library.py +58 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph_base.egg-info/PKG-INFO +2 -2
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph_base.egg-info/SOURCES.txt +3 -0
- trustgraph-base-0.21.0/trustgraph/base_version.py +0 -1
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/README.md +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/setup.cfg +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/setup.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/api/__init__.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/api/api.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/__init__.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/agent_client.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/base.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/document_embeddings_client.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/document_rag_client.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/embeddings_client.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/graph_embeddings_client.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/graph_rag_client.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/llm_client.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/prompt_client.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/triples_query_client.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/knowledge/__init__.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/knowledge/defs.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/knowledge/document.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/knowledge/identifier.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/knowledge/organization.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/knowledge/publication.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/log_level.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/objects/__init__.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/objects/field.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/objects/object.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/rdf.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/schema/agent.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/schema/documents.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/schema/graph.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/schema/lookup.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/schema/metadata.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/schema/models.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/schema/object.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/schema/prompt.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/schema/retrieval.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/schema/topic.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/schema/types.py +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph_base.egg-info/dependency_links.txt +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph_base.egg-info/requires.txt +0 -0
- {trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph_base.egg-info/top_level.txt +0 -0
@@ -1,9 +1,9 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: trustgraph-base
|
3
|
-
Version: 0.21.
|
3
|
+
Version: 0.21.2
|
4
4
|
Summary: TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.
|
5
5
|
Home-page: https://github.com/trustgraph-ai/trustgraph
|
6
|
-
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.21.
|
6
|
+
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.21.2.tar.gz
|
7
7
|
Author: trustgraph.ai
|
8
8
|
Author-email: security@trustgraph.ai
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
@@ -1,4 +1,5 @@
|
|
1
1
|
|
2
|
+
import asyncio
|
2
3
|
import os
|
3
4
|
import argparse
|
4
5
|
import pulsar
|
@@ -28,15 +29,19 @@ class BaseProcessor:
|
|
28
29
|
})
|
29
30
|
|
30
31
|
pulsar_host = params.get("pulsar_host", self.default_pulsar_host)
|
32
|
+
pulsar_listener = params.get("pulsar_listener", None)
|
31
33
|
log_level = params.get("log_level", LogLevel.INFO)
|
32
34
|
|
33
35
|
self.pulsar_host = pulsar_host
|
34
36
|
|
35
37
|
self.client = pulsar.Client(
|
36
38
|
pulsar_host,
|
39
|
+
listener_name=pulsar_listener,
|
37
40
|
logger=pulsar.ConsoleLogger(log_level.to_pulsar())
|
38
41
|
)
|
39
42
|
|
43
|
+
self.pulsar_listener = pulsar_listener
|
44
|
+
|
40
45
|
def __del__(self):
|
41
46
|
|
42
47
|
if hasattr(self, "client"):
|
@@ -52,6 +57,11 @@ class BaseProcessor:
|
|
52
57
|
help=f'Pulsar host (default: {__class__.default_pulsar_host})',
|
53
58
|
)
|
54
59
|
|
60
|
+
parser.add_argument(
|
61
|
+
'--pulsar-listener',
|
62
|
+
help=f'Pulsar listener (default: none)',
|
63
|
+
)
|
64
|
+
|
55
65
|
parser.add_argument(
|
56
66
|
'-l', '--log-level',
|
57
67
|
type=LogLevel,
|
@@ -74,11 +84,20 @@ class BaseProcessor:
|
|
74
84
|
help=f'Pulsar host (default: 8000)',
|
75
85
|
)
|
76
86
|
|
77
|
-
def
|
87
|
+
async def start(self):
|
88
|
+
pass
|
89
|
+
|
90
|
+
async def run(self):
|
78
91
|
raise RuntimeError("Something should have implemented the run method")
|
79
92
|
|
80
93
|
@classmethod
|
81
|
-
def
|
94
|
+
async def launch_async(cls, args):
|
95
|
+
p = cls(**args)
|
96
|
+
await p.start()
|
97
|
+
await p.run()
|
98
|
+
|
99
|
+
@classmethod
|
100
|
+
def launch(cls, prog, doc):
|
82
101
|
|
83
102
|
parser = argparse.ArgumentParser(
|
84
103
|
prog=prog,
|
@@ -99,8 +118,7 @@ class BaseProcessor:
|
|
99
118
|
|
100
119
|
try:
|
101
120
|
|
102
|
-
|
103
|
-
p.run()
|
121
|
+
asyncio.run(cls.launch_async(args))
|
104
122
|
|
105
123
|
except KeyboardInterrupt:
|
106
124
|
print("Keyboard interrupt.")
|
@@ -118,3 +136,4 @@ class BaseProcessor:
|
|
118
136
|
print("Will retry...", flush=True)
|
119
137
|
|
120
138
|
time.sleep(4)
|
139
|
+
|
@@ -1,4 +1,5 @@
|
|
1
1
|
|
2
|
+
import asyncio
|
2
3
|
from pulsar.schema import JsonSchema
|
3
4
|
import pulsar
|
4
5
|
from prometheus_client import Histogram, Info, Counter, Enum
|
@@ -75,7 +76,7 @@ class Consumer(BaseProcessor):
|
|
75
76
|
|
76
77
|
print("Initialised consumer.", flush=True)
|
77
78
|
|
78
|
-
def run(self):
|
79
|
+
async def run(self):
|
79
80
|
|
80
81
|
__class__.state_metric.state('running')
|
81
82
|
|
@@ -104,7 +105,7 @@ class Consumer(BaseProcessor):
|
|
104
105
|
try:
|
105
106
|
|
106
107
|
with __class__.request_metric.time():
|
107
|
-
self.handle(msg)
|
108
|
+
await self.handle(msg)
|
108
109
|
|
109
110
|
# Acknowledge successful processing of the message
|
110
111
|
self.consumer.acknowledge(msg)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
|
2
|
+
import queue
|
3
|
+
import time
|
4
|
+
import pulsar
|
5
|
+
import threading
|
6
|
+
|
7
|
+
class Publisher:
|
8
|
+
|
9
|
+
def __init__(self, pulsar_client, topic, schema=None, max_size=10,
|
10
|
+
chunking_enabled=True):
|
11
|
+
self.client = pulsar_client
|
12
|
+
self.topic = topic
|
13
|
+
self.schema = schema
|
14
|
+
self.q = queue.Queue(maxsize=max_size)
|
15
|
+
self.chunking_enabled = chunking_enabled
|
16
|
+
self.running = True
|
17
|
+
|
18
|
+
def start(self):
|
19
|
+
self.task = threading.Thread(target=self.run)
|
20
|
+
self.task.start()
|
21
|
+
|
22
|
+
def stop(self):
|
23
|
+
self.running = False
|
24
|
+
|
25
|
+
def join(self):
|
26
|
+
self.stop()
|
27
|
+
self.task.join()
|
28
|
+
|
29
|
+
def run(self):
|
30
|
+
|
31
|
+
while self.running:
|
32
|
+
|
33
|
+
try:
|
34
|
+
|
35
|
+
print(self.chunking_enabled)
|
36
|
+
producer = self.client.create_producer(
|
37
|
+
topic=self.topic,
|
38
|
+
schema=self.schema,
|
39
|
+
chunking_enabled=self.chunking_enabled,
|
40
|
+
)
|
41
|
+
|
42
|
+
while self.running:
|
43
|
+
|
44
|
+
try:
|
45
|
+
id, item = self.q.get(timeout=0.5)
|
46
|
+
except queue.Empty:
|
47
|
+
continue
|
48
|
+
|
49
|
+
if id:
|
50
|
+
producer.send(item, { "id": id })
|
51
|
+
else:
|
52
|
+
producer.send(item)
|
53
|
+
|
54
|
+
except Exception as e:
|
55
|
+
print("Exception:", e, flush=True)
|
56
|
+
|
57
|
+
# If handler drops out, sleep a retry
|
58
|
+
time.sleep(2)
|
59
|
+
|
60
|
+
def send(self, id, msg):
|
61
|
+
self.q.put((id, msg))
|
62
|
+
|
63
|
+
|
@@ -0,0 +1,114 @@
|
|
1
|
+
|
2
|
+
import queue
|
3
|
+
import pulsar
|
4
|
+
import threading
|
5
|
+
import time
|
6
|
+
|
7
|
+
class Subscriber:
|
8
|
+
|
9
|
+
def __init__(self, pulsar_client, topic, subscription, consumer_name,
|
10
|
+
schema=None, max_size=100):
|
11
|
+
self.client = pulsar_client
|
12
|
+
self.topic = topic
|
13
|
+
self.subscription = subscription
|
14
|
+
self.consumer_name = consumer_name
|
15
|
+
self.schema = schema
|
16
|
+
self.q = {}
|
17
|
+
self.full = {}
|
18
|
+
self.max_size = max_size
|
19
|
+
self.lock = threading.Lock()
|
20
|
+
self.running = True
|
21
|
+
|
22
|
+
def start(self):
|
23
|
+
self.task = threading.Thread(target=self.run)
|
24
|
+
self.task.start()
|
25
|
+
|
26
|
+
def stop(self):
|
27
|
+
self.running = False
|
28
|
+
|
29
|
+
def join(self):
|
30
|
+
self.task.join()
|
31
|
+
|
32
|
+
def run(self):
|
33
|
+
|
34
|
+
while self.running:
|
35
|
+
|
36
|
+
try:
|
37
|
+
|
38
|
+
consumer = self.client.subscribe(
|
39
|
+
topic=self.topic,
|
40
|
+
subscription_name=self.subscription,
|
41
|
+
consumer_name=self.consumer_name,
|
42
|
+
schema=self.schema,
|
43
|
+
)
|
44
|
+
|
45
|
+
while self.running:
|
46
|
+
|
47
|
+
msg = consumer.receive()
|
48
|
+
|
49
|
+
# Acknowledge successful reception of the message
|
50
|
+
consumer.acknowledge(msg)
|
51
|
+
|
52
|
+
try:
|
53
|
+
id = msg.properties()["id"]
|
54
|
+
except:
|
55
|
+
id = None
|
56
|
+
|
57
|
+
value = msg.value()
|
58
|
+
|
59
|
+
with self.lock:
|
60
|
+
|
61
|
+
if id in self.q:
|
62
|
+
try:
|
63
|
+
# FIXME: Timeout means data goes missing
|
64
|
+
self.q[id].put(value, timeout=0.5)
|
65
|
+
except:
|
66
|
+
pass
|
67
|
+
|
68
|
+
for q in self.full.values():
|
69
|
+
try:
|
70
|
+
# FIXME: Timeout means data goes missing
|
71
|
+
q.put(value, timeout=0.5)
|
72
|
+
except:
|
73
|
+
pass
|
74
|
+
|
75
|
+
except Exception as e:
|
76
|
+
print("Exception:", e, flush=True)
|
77
|
+
|
78
|
+
# If handler drops out, sleep a retry
|
79
|
+
time.sleep(2)
|
80
|
+
|
81
|
+
def subscribe(self, id):
|
82
|
+
|
83
|
+
with self.lock:
|
84
|
+
|
85
|
+
q = queue.Queue(maxsize=self.max_size)
|
86
|
+
self.q[id] = q
|
87
|
+
|
88
|
+
return q
|
89
|
+
|
90
|
+
def unsubscribe(self, id):
|
91
|
+
|
92
|
+
with self.lock:
|
93
|
+
|
94
|
+
if id in self.q:
|
95
|
+
# self.q[id].shutdown(immediate=True)
|
96
|
+
del self.q[id]
|
97
|
+
|
98
|
+
def subscribe_all(self, id):
|
99
|
+
|
100
|
+
with self.lock:
|
101
|
+
|
102
|
+
q = queue.Queue(maxsize=self.max_size)
|
103
|
+
self.full[id] = q
|
104
|
+
|
105
|
+
return q
|
106
|
+
|
107
|
+
def unsubscribe_all(self, id):
|
108
|
+
|
109
|
+
with self.lock:
|
110
|
+
|
111
|
+
if id in self.full:
|
112
|
+
# self.full[id].shutdown(immediate=True)
|
113
|
+
del self.full[id]
|
114
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
__version__ = "0.21.2"
|
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
from pulsar.schema import Record, Bytes, String, Array
|
3
|
+
from . types import Triple
|
4
|
+
from . topic import topic
|
5
|
+
from . types import Error
|
6
|
+
from . metadata import Metadata
|
7
|
+
from . documents import Document, TextDocument
|
8
|
+
|
9
|
+
# add(Metadata, Bytes) : error?
|
10
|
+
# copy(id, user, collection)
|
11
|
+
# move(id, user, collection)
|
12
|
+
# delete(id)
|
13
|
+
# get(id) : Bytes
|
14
|
+
# reindex(id)
|
15
|
+
# list(user, collection) : id[]
|
16
|
+
# info(id[]) : DocumentInfo[]
|
17
|
+
# search(<key,op,value>[]) : id[]
|
18
|
+
|
19
|
+
class DocumentPackage(Record):
|
20
|
+
metadata = Array(Triple())
|
21
|
+
document = Bytes()
|
22
|
+
kind = String()
|
23
|
+
user = String()
|
24
|
+
collection = String()
|
25
|
+
title = String()
|
26
|
+
comments = String()
|
27
|
+
|
28
|
+
class DocumentInfo(Record):
|
29
|
+
metadata = Array(Triple())
|
30
|
+
kind = String()
|
31
|
+
user = String()
|
32
|
+
collection = String()
|
33
|
+
|
34
|
+
class Criteria(Record):
|
35
|
+
key = String()
|
36
|
+
value = String()
|
37
|
+
operator = String()
|
38
|
+
|
39
|
+
class LibrarianRequest(Record):
|
40
|
+
operation = String()
|
41
|
+
id = String()
|
42
|
+
document = DocumentPackage()
|
43
|
+
user = String()
|
44
|
+
collection = String()
|
45
|
+
criteria = Array(Criteria())
|
46
|
+
|
47
|
+
class LibrarianResponse(Record):
|
48
|
+
error = Error()
|
49
|
+
document = DocumentPackage()
|
50
|
+
info = Array(DocumentInfo())
|
51
|
+
|
52
|
+
librarian_request_queue = topic(
|
53
|
+
'librarian', kind='non-persistent', namespace='request'
|
54
|
+
)
|
55
|
+
librarian_response_queue = topic(
|
56
|
+
'librarian', kind='non-persistent', namespace='response',
|
57
|
+
)
|
58
|
+
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: trustgraph-base
|
3
|
-
Version: 0.21.
|
3
|
+
Version: 0.21.2
|
4
4
|
Summary: TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.
|
5
5
|
Home-page: https://github.com/trustgraph-ai/trustgraph
|
6
|
-
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.21.
|
6
|
+
Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.21.2.tar.gz
|
7
7
|
Author: trustgraph.ai
|
8
8
|
Author-email: security@trustgraph.ai
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
@@ -11,6 +11,8 @@ trustgraph/base/base_processor.py
|
|
11
11
|
trustgraph/base/consumer.py
|
12
12
|
trustgraph/base/consumer_producer.py
|
13
13
|
trustgraph/base/producer.py
|
14
|
+
trustgraph/base/publisher.py
|
15
|
+
trustgraph/base/subscriber.py
|
14
16
|
trustgraph/clients/__init__.py
|
15
17
|
trustgraph/clients/agent_client.py
|
16
18
|
trustgraph/clients/base.py
|
@@ -35,6 +37,7 @@ trustgraph/schema/__init__.py
|
|
35
37
|
trustgraph/schema/agent.py
|
36
38
|
trustgraph/schema/documents.py
|
37
39
|
trustgraph/schema/graph.py
|
40
|
+
trustgraph/schema/library.py
|
38
41
|
trustgraph/schema/lookup.py
|
39
42
|
trustgraph/schema/metadata.py
|
40
43
|
trustgraph/schema/models.py
|
@@ -1 +0,0 @@
|
|
1
|
-
__version__ = "0.21.0"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/document_embeddings_client.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/graph_embeddings_client.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph/clients/triples_query_client.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{trustgraph-base-0.21.0 → trustgraph-base-0.21.2}/trustgraph_base.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|