trustgraph-base 0.21.0__tar.gz → 0.21.1__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.
Files changed (56) hide show
  1. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/PKG-INFO +2 -2
  2. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/base/__init__.py +2 -0
  3. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/base/base_processor.py +23 -4
  4. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/base/consumer.py +3 -2
  5. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/base/consumer_producer.py +1 -1
  6. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/base/producer.py +1 -1
  7. trustgraph-base-0.21.1/trustgraph/base/publisher.py +67 -0
  8. trustgraph-base-0.21.1/trustgraph/base/subscriber.py +120 -0
  9. trustgraph-base-0.21.1/trustgraph/base_version.py +1 -0
  10. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/exceptions.py +3 -0
  11. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/schema/__init__.py +1 -0
  12. trustgraph-base-0.21.1/trustgraph/schema/library.py +56 -0
  13. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph_base.egg-info/PKG-INFO +2 -2
  14. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph_base.egg-info/SOURCES.txt +3 -0
  15. trustgraph-base-0.21.0/trustgraph/base_version.py +0 -1
  16. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/README.md +0 -0
  17. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/setup.cfg +0 -0
  18. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/setup.py +0 -0
  19. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/api/__init__.py +0 -0
  20. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/api/api.py +0 -0
  21. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/clients/__init__.py +0 -0
  22. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/clients/agent_client.py +0 -0
  23. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/clients/base.py +0 -0
  24. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/clients/document_embeddings_client.py +0 -0
  25. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/clients/document_rag_client.py +0 -0
  26. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/clients/embeddings_client.py +0 -0
  27. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/clients/graph_embeddings_client.py +0 -0
  28. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/clients/graph_rag_client.py +0 -0
  29. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/clients/llm_client.py +0 -0
  30. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/clients/prompt_client.py +0 -0
  31. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/clients/triples_query_client.py +0 -0
  32. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/knowledge/__init__.py +0 -0
  33. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/knowledge/defs.py +0 -0
  34. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/knowledge/document.py +0 -0
  35. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/knowledge/identifier.py +0 -0
  36. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/knowledge/organization.py +0 -0
  37. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/knowledge/publication.py +0 -0
  38. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/log_level.py +0 -0
  39. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/objects/__init__.py +0 -0
  40. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/objects/field.py +0 -0
  41. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/objects/object.py +0 -0
  42. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/rdf.py +0 -0
  43. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/schema/agent.py +0 -0
  44. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/schema/documents.py +0 -0
  45. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/schema/graph.py +0 -0
  46. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/schema/lookup.py +0 -0
  47. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/schema/metadata.py +0 -0
  48. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/schema/models.py +0 -0
  49. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/schema/object.py +0 -0
  50. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/schema/prompt.py +0 -0
  51. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/schema/retrieval.py +0 -0
  52. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/schema/topic.py +0 -0
  53. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph/schema/types.py +0 -0
  54. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph_base.egg-info/dependency_links.txt +0 -0
  55. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/trustgraph_base.egg-info/requires.txt +0 -0
  56. {trustgraph-base-0.21.0 → trustgraph-base-0.21.1}/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.0
3
+ Version: 0.21.1
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.0.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.21.1.tar.gz
7
7
  Author: trustgraph.ai
8
8
  Author-email: security@trustgraph.ai
9
9
  Classifier: Programming Language :: Python :: 3
@@ -3,4 +3,6 @@ from . base_processor import BaseProcessor
3
3
  from . consumer import Consumer
4
4
  from . producer import Producer
5
5
  from . consumer_producer import ConsumerProducer
6
+ from . publisher import Publisher
7
+ from . subscriber import Subscriber
6
8
 
@@ -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 run(self):
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 start(cls, prog, doc):
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
- p = cls(**args)
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)
@@ -42,7 +42,7 @@ class ConsumerProducer(Consumer):
42
42
 
43
43
  print("Initialised consumer/producer.")
44
44
 
45
- def send(self, msg, properties={}):
45
+ async def send(self, msg, properties={}):
46
46
  self.producer.send(msg, properties)
47
47
  __class__.output_metric.inc()
48
48
 
@@ -37,7 +37,7 @@ class Producer(BaseProcessor):
37
37
  chunking_enabled=True,
38
38
  )
39
39
 
40
- def send(self, msg, properties={}):
40
+ async def send(self, msg, properties={}):
41
41
  self.producer.send(msg, properties)
42
42
  __class__.output_metric.inc()
43
43
 
@@ -0,0 +1,67 @@
1
+
2
+ import queue
3
+ import time
4
+ import pulsar
5
+ import threading
6
+
7
+ class Publisher:
8
+
9
+ def __init__(self, pulsar_host, topic, schema=None, max_size=10,
10
+ chunking_enabled=True, listener=None):
11
+ self.pulsar_host = pulsar_host
12
+ self.topic = topic
13
+ self.schema = schema
14
+ self.q = queue.Queue(maxsize=max_size)
15
+ self.chunking_enabled = chunking_enabled
16
+ self.listener_name = listener
17
+ self.running = True
18
+
19
+ def start(self):
20
+ self.task = threading.Thread(target=self.run)
21
+ self.task.start()
22
+
23
+ def stop(self):
24
+ self.running = False
25
+
26
+ def join(self):
27
+ self.stop()
28
+ self.task.join()
29
+
30
+ def run(self):
31
+
32
+ while self.running:
33
+
34
+ try:
35
+
36
+ client = pulsar.Client(
37
+ self.pulsar_host, listener_name=self.listener_name
38
+ )
39
+
40
+ producer = client.create_producer(
41
+ topic=self.topic,
42
+ schema=self.schema,
43
+ chunking_enabled=self.chunking_enabled,
44
+ )
45
+
46
+ while self.running:
47
+
48
+ try:
49
+ id, item = self.q.get(timeout=0.5)
50
+ except queue.Empty:
51
+ continue
52
+
53
+ if id:
54
+ producer.send(item, { "id": id })
55
+ else:
56
+ producer.send(item)
57
+
58
+ except Exception as e:
59
+ print("Exception:", e, flush=True)
60
+
61
+ # If handler drops out, sleep a retry
62
+ time.sleep(2)
63
+
64
+ def send(self, id, msg):
65
+ self.q.put((id, msg))
66
+
67
+
@@ -0,0 +1,120 @@
1
+
2
+ import queue
3
+ import pulsar
4
+ import threading
5
+ import time
6
+
7
+ class Subscriber:
8
+
9
+ def __init__(self, pulsar_host, topic, subscription, consumer_name,
10
+ schema=None, max_size=100, listener=None):
11
+ self.pulsar_host = pulsar_host
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.listener_name = listener
21
+ self.running = True
22
+
23
+ def start(self):
24
+ self.task = threading.Thread(target=self.run)
25
+ self.task.start()
26
+
27
+ def stop(self):
28
+ self.running = False
29
+
30
+ def join(self):
31
+ self.task.join()
32
+
33
+ def run(self):
34
+
35
+ while self.running:
36
+
37
+ try:
38
+
39
+ client = pulsar.Client(
40
+ self.pulsar_host,
41
+ listener_name=self.listener_name,
42
+ )
43
+
44
+ consumer = client.subscribe(
45
+ topic=self.topic,
46
+ subscription_name=self.subscription,
47
+ consumer_name=self.consumer_name,
48
+ schema=self.schema,
49
+ )
50
+
51
+ while self.running:
52
+
53
+ msg = consumer.receive()
54
+
55
+ # Acknowledge successful reception of the message
56
+ consumer.acknowledge(msg)
57
+
58
+ try:
59
+ id = msg.properties()["id"]
60
+ except:
61
+ id = None
62
+
63
+ value = msg.value()
64
+
65
+ with self.lock:
66
+
67
+ if id in self.q:
68
+ try:
69
+ # FIXME: Timeout means data goes missing
70
+ self.q[id].put(value, timeout=0.5)
71
+ except:
72
+ pass
73
+
74
+ for q in self.full.values():
75
+ try:
76
+ # FIXME: Timeout means data goes missing
77
+ q.put(value, timeout=0.5)
78
+ except:
79
+ pass
80
+
81
+ except Exception as e:
82
+ print("Exception:", e, flush=True)
83
+
84
+ # If handler drops out, sleep a retry
85
+ time.sleep(2)
86
+
87
+ def subscribe(self, id):
88
+
89
+ with self.lock:
90
+
91
+ q = queue.Queue(maxsize=self.max_size)
92
+ self.q[id] = q
93
+
94
+ return q
95
+
96
+ def unsubscribe(self, id):
97
+
98
+ with self.lock:
99
+
100
+ if id in self.q:
101
+ # self.q[id].shutdown(immediate=True)
102
+ del self.q[id]
103
+
104
+ def subscribe_all(self, id):
105
+
106
+ with self.lock:
107
+
108
+ q = queue.Queue(maxsize=self.max_size)
109
+ self.full[id] = q
110
+
111
+ return q
112
+
113
+ def unsubscribe_all(self, id):
114
+
115
+ with self.lock:
116
+
117
+ if id in self.full:
118
+ # self.full[id].shutdown(immediate=True)
119
+ del self.full[id]
120
+
@@ -0,0 +1 @@
1
+ __version__ = "0.21.1"
@@ -8,3 +8,6 @@ class LlmError(Exception):
8
8
  class ParseError(Exception):
9
9
  pass
10
10
 
11
+ class RequestError(Exception):
12
+ pass
13
+
@@ -10,5 +10,6 @@ from . retrieval import *
10
10
  from . metadata import *
11
11
  from . agent import *
12
12
  from . lookup import *
13
+ from . library import *
13
14
 
14
15
 
@@ -0,0 +1,56 @@
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
+
26
+ class DocumentInfo(Record):
27
+ metadata = Array(Triple())
28
+ kind = String()
29
+ user = String()
30
+ collection = String()
31
+
32
+ class Criteria(Record):
33
+ key = String()
34
+ value = String()
35
+ operator = String()
36
+
37
+ class LibrarianRequest(Record):
38
+ operation = String()
39
+ id = String()
40
+ document = DocumentPackage()
41
+ user = String()
42
+ collection = String()
43
+ criteria = Array(Criteria())
44
+
45
+ class LibrarianResponse(Record):
46
+ error = Error()
47
+ document = DocumentPackage()
48
+ info = Array(DocumentInfo())
49
+
50
+ librarian_request_queue = topic(
51
+ 'librarian', kind='non-persistent', namespace='request'
52
+ )
53
+ librarian_response_queue = topic(
54
+ 'librarian', kind='non-persistent', namespace='response',
55
+ )
56
+
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trustgraph-base
3
- Version: 0.21.0
3
+ Version: 0.21.1
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.0.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.21.1.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"