trustgraph-base 0.20.1__tar.gz → 0.20.3__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 (55) hide show
  1. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/PKG-INFO +2 -2
  2. trustgraph-base-0.20.3/trustgraph/base/consumer.py +172 -0
  3. trustgraph-base-0.20.3/trustgraph/base/consumer_producer.py +62 -0
  4. trustgraph-base-0.20.3/trustgraph/base_version.py +1 -0
  5. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/exceptions.py +0 -4
  6. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph_base.egg-info/PKG-INFO +2 -2
  7. trustgraph-base-0.20.1/trustgraph/base/consumer.py +0 -109
  8. trustgraph-base-0.20.1/trustgraph/base/consumer_producer.py +0 -142
  9. trustgraph-base-0.20.1/trustgraph/base_version.py +0 -1
  10. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/README.md +0 -0
  11. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/setup.cfg +0 -0
  12. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/setup.py +0 -0
  13. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/api/__init__.py +0 -0
  14. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/api/api.py +0 -0
  15. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/base/__init__.py +0 -0
  16. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/base/base_processor.py +0 -0
  17. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/base/producer.py +0 -0
  18. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/clients/__init__.py +0 -0
  19. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/clients/agent_client.py +0 -0
  20. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/clients/base.py +0 -0
  21. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/clients/document_embeddings_client.py +0 -0
  22. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/clients/document_rag_client.py +0 -0
  23. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/clients/embeddings_client.py +0 -0
  24. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/clients/graph_embeddings_client.py +0 -0
  25. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/clients/graph_rag_client.py +0 -0
  26. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/clients/llm_client.py +0 -0
  27. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/clients/prompt_client.py +0 -0
  28. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/clients/triples_query_client.py +0 -0
  29. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/knowledge/__init__.py +0 -0
  30. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/knowledge/defs.py +0 -0
  31. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/knowledge/document.py +0 -0
  32. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/knowledge/identifier.py +0 -0
  33. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/knowledge/organization.py +0 -0
  34. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/knowledge/publication.py +0 -0
  35. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/log_level.py +0 -0
  36. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/objects/__init__.py +0 -0
  37. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/objects/field.py +0 -0
  38. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/objects/object.py +0 -0
  39. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/rdf.py +0 -0
  40. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/schema/__init__.py +0 -0
  41. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/schema/agent.py +0 -0
  42. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/schema/documents.py +0 -0
  43. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/schema/graph.py +0 -0
  44. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/schema/lookup.py +0 -0
  45. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/schema/metadata.py +0 -0
  46. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/schema/models.py +0 -0
  47. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/schema/object.py +0 -0
  48. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/schema/prompt.py +0 -0
  49. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/schema/retrieval.py +0 -0
  50. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/schema/topic.py +0 -0
  51. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph/schema/types.py +0 -0
  52. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph_base.egg-info/SOURCES.txt +0 -0
  53. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph_base.egg-info/dependency_links.txt +0 -0
  54. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/trustgraph_base.egg-info/requires.txt +0 -0
  55. {trustgraph-base-0.20.1 → trustgraph-base-0.20.3}/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.20.1
3
+ Version: 0.20.3
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.20.1.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.20.3.tar.gz
7
7
  Author: trustgraph.ai
8
8
  Author-email: security@trustgraph.ai
9
9
  Classifier: Programming Language :: Python :: 3
@@ -0,0 +1,172 @@
1
+
2
+ from pulsar.schema import JsonSchema
3
+ import pulsar
4
+ from prometheus_client import Histogram, Info, Counter, Enum
5
+ import time
6
+
7
+ from . base_processor import BaseProcessor
8
+ from .. exceptions import TooManyRequests
9
+
10
+ default_rate_limit_retry = 10
11
+ default_rate_limit_timeout = 7200
12
+
13
+ class Consumer(BaseProcessor):
14
+
15
+ def __init__(self, **params):
16
+
17
+ if not hasattr(__class__, "state_metric"):
18
+ __class__.state_metric = Enum(
19
+ 'processor_state', 'Processor state',
20
+ states=['starting', 'running', 'stopped']
21
+ )
22
+ __class__.state_metric.state('starting')
23
+
24
+ __class__.state_metric.state('starting')
25
+
26
+ super(Consumer, self).__init__(**params)
27
+
28
+ self.input_queue = params.get("input_queue")
29
+ self.subscriber = params.get("subscriber")
30
+ self.input_schema = params.get("input_schema")
31
+
32
+ self.rate_limit_retry = params.get(
33
+ "rate_limit_retry", default_rate_limit_retry
34
+ )
35
+ self.rate_limit_timeout = params.get(
36
+ "rate_limit_timeout", default_rate_limit_timeout
37
+ )
38
+
39
+ if self.input_schema == None:
40
+ raise RuntimeError("input_schema must be specified")
41
+
42
+ if not hasattr(__class__, "request_metric"):
43
+ __class__.request_metric = Histogram(
44
+ 'request_latency', 'Request latency (seconds)'
45
+ )
46
+
47
+ if not hasattr(__class__, "pubsub_metric"):
48
+ __class__.pubsub_metric = Info(
49
+ 'pubsub', 'Pub/sub configuration'
50
+ )
51
+
52
+ if not hasattr(__class__, "processing_metric"):
53
+ __class__.processing_metric = Counter(
54
+ 'processing_count', 'Processing count', ["status"]
55
+ )
56
+
57
+ if not hasattr(__class__, "rate_limit_metric"):
58
+ __class__.rate_limit_metric = Counter(
59
+ 'rate_limit_count', 'Rate limit event count',
60
+ )
61
+
62
+ __class__.pubsub_metric.info({
63
+ "input_queue": self.input_queue,
64
+ "subscriber": self.subscriber,
65
+ "input_schema": self.input_schema.__name__,
66
+ "rate_limit_retry": str(self.rate_limit_retry),
67
+ "rate_limit_timeout": str(self.rate_limit_timeout),
68
+ })
69
+
70
+ self.consumer = self.client.subscribe(
71
+ self.input_queue, self.subscriber,
72
+ consumer_type=pulsar.ConsumerType.Shared,
73
+ schema=JsonSchema(self.input_schema),
74
+ )
75
+
76
+ print("Initialised consumer.", flush=True)
77
+
78
+ def run(self):
79
+
80
+ __class__.state_metric.state('running')
81
+
82
+ while True:
83
+
84
+ msg = self.consumer.receive()
85
+
86
+ expiry = time.time() + self.rate_limit_timeout
87
+
88
+ # This loop is for retry on rate-limit / resource limits
89
+ while True:
90
+
91
+ if time.time() > expiry:
92
+
93
+ print("Gave up waiting for rate-limit retry", flush=True)
94
+
95
+ # Message failed to be processed, this causes it to
96
+ # be retried
97
+ self.consumer.negative_acknowledge(msg)
98
+
99
+ __class__.processing_metric.labels(status="error").inc()
100
+
101
+ # Break out of retry loop, processes next message
102
+ break
103
+
104
+ try:
105
+
106
+ with __class__.request_metric.time():
107
+ self.handle(msg)
108
+
109
+ # Acknowledge successful processing of the message
110
+ self.consumer.acknowledge(msg)
111
+
112
+ __class__.processing_metric.labels(status="success").inc()
113
+
114
+ # Break out of retry loop
115
+ break
116
+
117
+ except TooManyRequests:
118
+
119
+ print("TooManyRequests: will retry...", flush=True)
120
+
121
+ __class__.rate_limit_metric.inc()
122
+
123
+ # Sleep
124
+ time.sleep(self.rate_limit_retry)
125
+
126
+ # Contine from retry loop, just causes a reprocessing
127
+ continue
128
+
129
+ except Exception as e:
130
+
131
+ print("Exception:", e, flush=True)
132
+
133
+ # Message failed to be processed, this causes it to
134
+ # be retried
135
+ self.consumer.negative_acknowledge(msg)
136
+
137
+ __class__.processing_metric.labels(status="error").inc()
138
+
139
+ # Break out of retry loop, processes next message
140
+ break
141
+
142
+ @staticmethod
143
+ def add_args(parser, default_input_queue, default_subscriber):
144
+
145
+ BaseProcessor.add_args(parser)
146
+
147
+ parser.add_argument(
148
+ '-i', '--input-queue',
149
+ default=default_input_queue,
150
+ help=f'Input queue (default: {default_input_queue})'
151
+ )
152
+
153
+ parser.add_argument(
154
+ '-s', '--subscriber',
155
+ default=default_subscriber,
156
+ help=f'Queue subscriber name (default: {default_subscriber})'
157
+ )
158
+
159
+ parser.add_argument(
160
+ '--rate-limit-retry',
161
+ type=int,
162
+ default=default_rate_limit_retry,
163
+ help=f'Rate limit retry (default: {default_rate_limit_retry})'
164
+ )
165
+
166
+ parser.add_argument(
167
+ '--rate-limit-timeout',
168
+ type=int,
169
+ default=default_rate_limit_timeout,
170
+ help=f'Rate limit timeout (default: {default_rate_limit_timeout})'
171
+ )
172
+
@@ -0,0 +1,62 @@
1
+
2
+ from pulsar.schema import JsonSchema
3
+ import pulsar
4
+ from prometheus_client import Histogram, Info, Counter, Enum
5
+ import time
6
+
7
+ from . consumer import Consumer
8
+ from .. exceptions import TooManyRequests
9
+
10
+ class ConsumerProducer(Consumer):
11
+
12
+ def __init__(self, **params):
13
+
14
+ super(ConsumerProducer, self).__init__(**params)
15
+
16
+ self.output_queue = params.get("output_queue")
17
+ self.output_schema = params.get("output_schema")
18
+
19
+ if not hasattr(__class__, "output_metric"):
20
+ __class__.output_metric = Counter(
21
+ 'output_count', 'Output items created'
22
+ )
23
+
24
+ __class__.pubsub_metric.info({
25
+ "input_queue": self.input_queue,
26
+ "output_queue": self.output_queue,
27
+ "subscriber": self.subscriber,
28
+ "input_schema": self.input_schema.__name__,
29
+ "output_schema": self.output_schema.__name__,
30
+ "rate_limit_retry": str(self.rate_limit_retry),
31
+ "rate_limit_timeout": str(self.rate_limit_timeout),
32
+ })
33
+
34
+ if self.output_schema == None:
35
+ raise RuntimeError("output_schema must be specified")
36
+
37
+ self.producer = self.client.create_producer(
38
+ topic=self.output_queue,
39
+ schema=JsonSchema(self.output_schema),
40
+ chunking_enabled=True,
41
+ )
42
+
43
+ print("Initialised consumer/producer.")
44
+
45
+ def send(self, msg, properties={}):
46
+ self.producer.send(msg, properties)
47
+ __class__.output_metric.inc()
48
+
49
+ @staticmethod
50
+ def add_args(
51
+ parser, default_input_queue, default_subscriber,
52
+ default_output_queue,
53
+ ):
54
+
55
+ Consumer.add_args(parser, default_input_queue, default_subscriber)
56
+
57
+ parser.add_argument(
58
+ '-o', '--output-queue',
59
+ default=default_output_queue,
60
+ help=f'Output queue (default: {default_output_queue})'
61
+ )
62
+
@@ -0,0 +1 @@
1
+ __version__ = "0.20.3"
@@ -8,7 +8,3 @@ class LlmError(Exception):
8
8
  class ParseError(Exception):
9
9
  pass
10
10
 
11
-
12
-
13
-
14
-
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trustgraph-base
3
- Version: 0.20.1
3
+ Version: 0.20.3
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.20.1.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.20.3.tar.gz
7
7
  Author: trustgraph.ai
8
8
  Author-email: security@trustgraph.ai
9
9
  Classifier: Programming Language :: Python :: 3
@@ -1,109 +0,0 @@
1
-
2
- from pulsar.schema import JsonSchema
3
- import pulsar
4
- from prometheus_client import Histogram, Info, Counter, Enum
5
- import time
6
-
7
- from . base_processor import BaseProcessor
8
- from .. exceptions import TooManyRequests
9
-
10
- class Consumer(BaseProcessor):
11
-
12
- def __init__(self, **params):
13
-
14
- if not hasattr(__class__, "state_metric"):
15
- __class__.state_metric = Enum(
16
- 'processor_state', 'Processor state',
17
- states=['starting', 'running', 'stopped']
18
- )
19
- __class__.state_metric.state('starting')
20
-
21
- __class__.state_metric.state('starting')
22
-
23
- super(Consumer, self).__init__(**params)
24
-
25
- input_queue = params.get("input_queue")
26
- subscriber = params.get("subscriber")
27
- input_schema = params.get("input_schema")
28
-
29
- if input_schema == None:
30
- raise RuntimeError("input_schema must be specified")
31
-
32
- if not hasattr(__class__, "request_metric"):
33
- __class__.request_metric = Histogram(
34
- 'request_latency', 'Request latency (seconds)'
35
- )
36
-
37
- if not hasattr(__class__, "pubsub_metric"):
38
- __class__.pubsub_metric = Info(
39
- 'pubsub', 'Pub/sub configuration'
40
- )
41
-
42
- if not hasattr(__class__, "processing_metric"):
43
- __class__.processing_metric = Counter(
44
- 'processing_count', 'Processing count', ["status"]
45
- )
46
-
47
- __class__.pubsub_metric.info({
48
- "input_queue": input_queue,
49
- "subscriber": subscriber,
50
- "input_schema": input_schema.__name__,
51
- })
52
-
53
- self.consumer = self.client.subscribe(
54
- input_queue, subscriber,
55
- consumer_type=pulsar.ConsumerType.Shared,
56
- schema=JsonSchema(input_schema),
57
- )
58
-
59
- def run(self):
60
-
61
- __class__.state_metric.state('running')
62
-
63
- while True:
64
-
65
- msg = self.consumer.receive()
66
-
67
- try:
68
-
69
- with __class__.request_metric.time():
70
- self.handle(msg)
71
-
72
- # Acknowledge successful processing of the message
73
- self.consumer.acknowledge(msg)
74
-
75
- __class__.processing_metric.labels(status="success").inc()
76
-
77
- except TooManyRequests:
78
- self.consumer.negative_acknowledge(msg)
79
- print("TooManyRequests: will retry")
80
- __class__.processing_metric.labels(status="rate-limit").inc()
81
- time.sleep(5)
82
- continue
83
-
84
- except Exception as e:
85
-
86
- print("Exception:", e, flush=True)
87
-
88
- # Message failed to be processed
89
- self.consumer.negative_acknowledge(msg)
90
-
91
- __class__.processing_metric.labels(status="error").inc()
92
-
93
- @staticmethod
94
- def add_args(parser, default_input_queue, default_subscriber):
95
-
96
- BaseProcessor.add_args(parser)
97
-
98
- parser.add_argument(
99
- '-i', '--input-queue',
100
- default=default_input_queue,
101
- help=f'Input queue (default: {default_input_queue})'
102
- )
103
-
104
- parser.add_argument(
105
- '-s', '--subscriber',
106
- default=default_subscriber,
107
- help=f'Queue subscriber name (default: {default_subscriber})'
108
- )
109
-
@@ -1,142 +0,0 @@
1
-
2
- from pulsar.schema import JsonSchema
3
- import pulsar
4
- from prometheus_client import Histogram, Info, Counter, Enum
5
- import time
6
-
7
- from . base_processor import BaseProcessor
8
- from .. exceptions import TooManyRequests
9
-
10
- # FIXME: Derive from consumer? And producer?
11
-
12
- class ConsumerProducer(BaseProcessor):
13
-
14
- def __init__(self, **params):
15
-
16
- if not hasattr(__class__, "state_metric"):
17
- __class__.state_metric = Enum(
18
- 'processor_state', 'Processor state',
19
- states=['starting', 'running', 'stopped']
20
- )
21
- __class__.state_metric.state('starting')
22
-
23
- __class__.state_metric.state('starting')
24
-
25
- input_queue = params.get("input_queue")
26
- output_queue = params.get("output_queue")
27
- subscriber = params.get("subscriber")
28
- input_schema = params.get("input_schema")
29
- output_schema = params.get("output_schema")
30
-
31
- if not hasattr(__class__, "request_metric"):
32
- __class__.request_metric = Histogram(
33
- 'request_latency', 'Request latency (seconds)'
34
- )
35
-
36
- if not hasattr(__class__, "output_metric"):
37
- __class__.output_metric = Counter(
38
- 'output_count', 'Output items created'
39
- )
40
-
41
- if not hasattr(__class__, "pubsub_metric"):
42
- __class__.pubsub_metric = Info(
43
- 'pubsub', 'Pub/sub configuration'
44
- )
45
-
46
- if not hasattr(__class__, "processing_metric"):
47
- __class__.processing_metric = Counter(
48
- 'processing_count', 'Processing count', ["status"]
49
- )
50
-
51
- __class__.pubsub_metric.info({
52
- "input_queue": input_queue,
53
- "output_queue": output_queue,
54
- "subscriber": subscriber,
55
- "input_schema": input_schema.__name__,
56
- "output_schema": output_schema.__name__,
57
- })
58
-
59
- super(ConsumerProducer, self).__init__(**params)
60
-
61
- if input_schema == None:
62
- raise RuntimeError("input_schema must be specified")
63
-
64
- if output_schema == None:
65
- raise RuntimeError("output_schema must be specified")
66
-
67
- self.producer = self.client.create_producer(
68
- topic=output_queue,
69
- schema=JsonSchema(output_schema),
70
- chunking_enabled=True,
71
- )
72
-
73
- self.consumer = self.client.subscribe(
74
- input_queue, subscriber,
75
- consumer_type=pulsar.ConsumerType.Shared,
76
- schema=JsonSchema(input_schema),
77
- )
78
-
79
- def run(self):
80
-
81
- __class__.state_metric.state('running')
82
-
83
- while True:
84
-
85
- msg = self.consumer.receive()
86
-
87
- try:
88
-
89
- with __class__.request_metric.time():
90
- resp = self.handle(msg)
91
-
92
- # Acknowledge successful processing of the message
93
- self.consumer.acknowledge(msg)
94
-
95
- __class__.processing_metric.labels(status="success").inc()
96
-
97
- except TooManyRequests:
98
- self.consumer.negative_acknowledge(msg)
99
- print("TooManyRequests: will retry")
100
- __class__.processing_metric.labels(status="rate-limit").inc()
101
- time.sleep(5)
102
- continue
103
-
104
- except Exception as e:
105
-
106
- print("Exception:", e, flush=True)
107
-
108
- # Message failed to be processed
109
- self.consumer.negative_acknowledge(msg)
110
-
111
- __class__.processing_metric.labels(status="error").inc()
112
-
113
- def send(self, msg, properties={}):
114
- self.producer.send(msg, properties)
115
- __class__.output_metric.inc()
116
-
117
- @staticmethod
118
- def add_args(
119
- parser, default_input_queue, default_subscriber,
120
- default_output_queue,
121
- ):
122
-
123
- BaseProcessor.add_args(parser)
124
-
125
- parser.add_argument(
126
- '-i', '--input-queue',
127
- default=default_input_queue,
128
- help=f'Input queue (default: {default_input_queue})'
129
- )
130
-
131
- parser.add_argument(
132
- '-s', '--subscriber',
133
- default=default_subscriber,
134
- help=f'Queue subscriber name (default: {default_subscriber})'
135
- )
136
-
137
- parser.add_argument(
138
- '-o', '--output-queue',
139
- default=default_output_queue,
140
- help=f'Output queue (default: {default_output_queue})'
141
- )
142
-
@@ -1 +0,0 @@
1
- __version__ = "0.20.1"