trustgraph-base 1.0.11__tar.gz → 1.0.12__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 (92) hide show
  1. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/PKG-INFO +2 -2
  2. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/consumer.py +81 -48
  3. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/consumer_spec.py +3 -1
  4. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/llm_service.py +19 -3
  5. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/subscriber.py +4 -0
  6. trustgraph-base-1.0.12/trustgraph/base_version.py +1 -0
  7. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph_base.egg-info/PKG-INFO +2 -2
  8. trustgraph-base-1.0.11/trustgraph/base_version.py +0 -1
  9. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/README.md +0 -0
  10. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/setup.cfg +0 -0
  11. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/setup.py +0 -0
  12. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/api/__init__.py +0 -0
  13. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/api/api.py +0 -0
  14. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/api/config.py +0 -0
  15. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/api/exceptions.py +0 -0
  16. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/api/flow.py +0 -0
  17. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/api/knowledge.py +0 -0
  18. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/api/library.py +0 -0
  19. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/api/types.py +0 -0
  20. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/__init__.py +0 -0
  21. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/agent_client.py +0 -0
  22. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/agent_service.py +0 -0
  23. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/async_processor.py +0 -0
  24. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/document_embeddings_client.py +0 -0
  25. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/document_embeddings_query_service.py +0 -0
  26. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/document_embeddings_store_service.py +0 -0
  27. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/embeddings_client.py +0 -0
  28. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/embeddings_service.py +0 -0
  29. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/flow.py +0 -0
  30. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/flow_processor.py +0 -0
  31. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/graph_embeddings_client.py +0 -0
  32. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/graph_embeddings_query_service.py +0 -0
  33. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/graph_embeddings_store_service.py +0 -0
  34. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/graph_rag_client.py +0 -0
  35. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/metrics.py +0 -0
  36. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/producer.py +0 -0
  37. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/producer_spec.py +0 -0
  38. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/prompt_client.py +0 -0
  39. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/publisher.py +0 -0
  40. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/pubsub.py +0 -0
  41. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/request_response_spec.py +0 -0
  42. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/setting_spec.py +0 -0
  43. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/spec.py +0 -0
  44. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/subscriber_spec.py +0 -0
  45. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/text_completion_client.py +0 -0
  46. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/triples_client.py +0 -0
  47. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/triples_query_service.py +0 -0
  48. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/base/triples_store_service.py +0 -0
  49. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/clients/__init__.py +0 -0
  50. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/clients/agent_client.py +0 -0
  51. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/clients/base.py +0 -0
  52. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/clients/config_client.py +0 -0
  53. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/clients/document_embeddings_client.py +0 -0
  54. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/clients/document_rag_client.py +0 -0
  55. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/clients/embeddings_client.py +0 -0
  56. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/clients/graph_embeddings_client.py +0 -0
  57. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/clients/graph_rag_client.py +0 -0
  58. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/clients/llm_client.py +0 -0
  59. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/clients/prompt_client.py +0 -0
  60. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/clients/triples_query_client.py +0 -0
  61. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/exceptions.py +0 -0
  62. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/knowledge/__init__.py +0 -0
  63. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/knowledge/defs.py +0 -0
  64. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/knowledge/document.py +0 -0
  65. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/knowledge/identifier.py +0 -0
  66. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/knowledge/organization.py +0 -0
  67. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/knowledge/publication.py +0 -0
  68. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/log_level.py +0 -0
  69. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/objects/__init__.py +0 -0
  70. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/objects/field.py +0 -0
  71. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/objects/object.py +0 -0
  72. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/rdf.py +0 -0
  73. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/__init__.py +0 -0
  74. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/agent.py +0 -0
  75. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/config.py +0 -0
  76. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/documents.py +0 -0
  77. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/flows.py +0 -0
  78. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/graph.py +0 -0
  79. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/knowledge.py +0 -0
  80. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/library.py +0 -0
  81. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/lookup.py +0 -0
  82. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/metadata.py +0 -0
  83. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/models.py +0 -0
  84. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/object.py +0 -0
  85. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/prompt.py +0 -0
  86. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/retrieval.py +0 -0
  87. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/topic.py +0 -0
  88. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph/schema/types.py +0 -0
  89. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph_base.egg-info/SOURCES.txt +0 -0
  90. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph_base.egg-info/dependency_links.txt +0 -0
  91. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/trustgraph_base.egg-info/requires.txt +0 -0
  92. {trustgraph-base-1.0.11 → trustgraph-base-1.0.12}/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: 1.0.11
3
+ Version: 1.0.12
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/v1.0.11.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v1.0.12.tar.gz
7
7
  Author: trustgraph.ai
8
8
  Author-email: security@trustgraph.ai
9
9
  Classifier: Programming Language :: Python :: 3
@@ -1,4 +1,14 @@
1
1
 
2
+ # Consumer is similar to subscriber: It takes information from a queue
3
+ # and passes on to a processor function. This is the main receiving
4
+ # loop for TrustGraph processors. Incorporates retry functionality
5
+
6
+ # Note: there is a 'defect' in the system which is tolerated, althought
7
+ # the processing handlers are async functions, ideally implementation
8
+ # would use all async code. In practice if the processor only implements
9
+ # one handler, and a single thread of concurrency, nothing too outrageous
10
+ # will happen if synchronous / blocking code is used
11
+
2
12
  from pulsar.schema import JsonSchema
3
13
  import pulsar
4
14
  import _pulsar
@@ -16,6 +26,7 @@ class Consumer:
16
26
  start_of_messages=False,
17
27
  rate_limit_retry_time = 10, rate_limit_timeout = 7200,
18
28
  reconnect_time = 5,
29
+ concurrency = 1, # Number of concurrent requests to handle
19
30
  ):
20
31
 
21
32
  self.taskgroup = taskgroup
@@ -34,7 +45,9 @@ class Consumer:
34
45
  self.start_of_messages = start_of_messages
35
46
 
36
47
  self.running = True
37
- self.task = None
48
+ self.consumer_task = None
49
+
50
+ self.concurrency = concurrency
38
51
 
39
52
  self.metrics = metrics
40
53
 
@@ -52,7 +65,11 @@ class Consumer:
52
65
  async def stop(self):
53
66
 
54
67
  self.running = False
55
- await self.task
68
+
69
+ if self.consumer_task:
70
+ await self.consumer_task
71
+
72
+ self.consumer_task = None
56
73
 
57
74
  async def start(self):
58
75
 
@@ -62,9 +79,9 @@ class Consumer:
62
79
  if self.metrics:
63
80
  self.metrics.state("stopped")
64
81
 
65
- self.task = self.taskgroup.create_task(self.run())
82
+ self.consumer_task = self.taskgroup.create_task(self.consumer_run())
66
83
 
67
- async def run(self):
84
+ async def consumer_run(self):
68
85
 
69
86
  while self.running:
70
87
 
@@ -102,7 +119,19 @@ class Consumer:
102
119
 
103
120
  try:
104
121
 
105
- await self.consume()
122
+ print(
123
+ "Starting", self.concurrency, "receiver threads",
124
+ flush=True
125
+ )
126
+
127
+ async with asyncio.TaskGroup() as tg:
128
+
129
+ tasks = []
130
+
131
+ for i in range(0, self.concurrency):
132
+ tasks.append(
133
+ tg.create_task(self.consume_from_queue())
134
+ )
106
135
 
107
136
  if self.metrics:
108
137
  self.metrics.state("stopped")
@@ -120,7 +149,7 @@ class Consumer:
120
149
  self.consumer.unsubscribe()
121
150
  self.consumer.close()
122
151
 
123
- async def consume(self):
152
+ async def consume_from_queue(self):
124
153
 
125
154
  while self.running:
126
155
 
@@ -134,71 +163,75 @@ class Consumer:
134
163
  except Exception as e:
135
164
  raise e
136
165
 
137
- expiry = time.time() + self.rate_limit_timeout
166
+ await self.handle_one_from_queue(msg)
138
167
 
139
- # This loop is for retry on rate-limit / resource limits
140
- while self.running:
168
+ async def handle_one_from_queue(self, msg):
141
169
 
142
- if time.time() > expiry:
170
+ expiry = time.time() + self.rate_limit_timeout
143
171
 
144
- print("Gave up waiting for rate-limit retry", flush=True)
172
+ # This loop is for retry on rate-limit / resource limits
173
+ while self.running:
145
174
 
146
- # Message failed to be processed, this causes it to
147
- # be retried
148
- self.consumer.negative_acknowledge(msg)
175
+ if time.time() > expiry:
149
176
 
150
- if self.metrics:
151
- self.metrics.process("error")
177
+ print("Gave up waiting for rate-limit retry", flush=True)
152
178
 
153
- # Break out of retry loop, processes next message
154
- break
179
+ # Message failed to be processed, this causes it to
180
+ # be retried
181
+ self.consumer.negative_acknowledge(msg)
155
182
 
156
- try:
183
+ if self.metrics:
184
+ self.metrics.process("error")
157
185
 
158
- print("Handle...", flush=True)
186
+ # Break out of retry loop, processes next message
187
+ break
159
188
 
160
- if self.metrics:
189
+ try:
190
+
191
+ print("Handle...", flush=True)
161
192
 
162
- with self.metrics.record_time():
163
- await self.handler(msg, self, self.flow)
193
+ if self.metrics:
164
194
 
165
- else:
195
+ with self.metrics.record_time():
166
196
  await self.handler(msg, self, self.flow)
167
197
 
168
- print("Handled.", flush=True)
198
+ else:
199
+ await self.handler(msg, self, self.flow)
200
+
201
+ print("Handled.", flush=True)
169
202
 
170
- # Acknowledge successful processing of the message
171
- self.consumer.acknowledge(msg)
203
+ # Acknowledge successful processing of the message
204
+ self.consumer.acknowledge(msg)
172
205
 
173
- if self.metrics:
174
- self.metrics.process("success")
206
+ if self.metrics:
207
+ self.metrics.process("success")
175
208
 
176
- # Break out of retry loop
177
- break
209
+ # Break out of retry loop
210
+ break
178
211
 
179
- except TooManyRequests:
212
+ except TooManyRequests:
180
213
 
181
- print("TooManyRequests: will retry...", flush=True)
214
+ print("TooManyRequests: will retry...", flush=True)
182
215
 
183
- if self.metrics:
184
- self.metrics.rate_limit()
216
+ if self.metrics:
217
+ self.metrics.rate_limit()
185
218
 
186
- # Sleep
187
- await asyncio.sleep(self.rate_limit_retry_time)
219
+ # Sleep
220
+ await asyncio.sleep(self.rate_limit_retry_time)
188
221
 
189
- # Contine from retry loop, just causes a reprocessing
190
- continue
222
+ # Contine from retry loop, just causes a reprocessing
223
+ continue
191
224
 
192
- except Exception as e:
225
+ except Exception as e:
193
226
 
194
- print("consume exception:", e, flush=True)
227
+ print("consume exception:", e, flush=True)
195
228
 
196
- # Message failed to be processed, this causes it to
197
- # be retried
198
- self.consumer.negative_acknowledge(msg)
229
+ # Message failed to be processed, this causes it to
230
+ # be retried
231
+ self.consumer.negative_acknowledge(msg)
199
232
 
200
- if self.metrics:
201
- self.metrics.process("error")
233
+ if self.metrics:
234
+ self.metrics.process("error")
202
235
 
203
- # Break out of retry loop, processes next message
204
- break
236
+ # Break out of retry loop, processes next message
237
+ break
@@ -4,10 +4,11 @@ from . consumer import Consumer
4
4
  from . spec import Spec
5
5
 
6
6
  class ConsumerSpec(Spec):
7
- def __init__(self, name, schema, handler):
7
+ def __init__(self, name, schema, handler, concurrency = 1):
8
8
  self.name = name
9
9
  self.schema = schema
10
10
  self.handler = handler
11
+ self.concurrency = concurrency
11
12
 
12
13
  def add(self, flow, processor, definition):
13
14
 
@@ -24,6 +25,7 @@ class ConsumerSpec(Spec):
24
25
  schema = self.schema,
25
26
  handler = self.handler,
26
27
  metrics = consumer_metrics,
28
+ concurrency = self.concurrency
27
29
  )
28
30
 
29
31
  # Consumer handle gets access to producers and other
@@ -11,9 +11,13 @@ from .. exceptions import TooManyRequests
11
11
  from .. base import FlowProcessor, ConsumerSpec, ProducerSpec
12
12
 
13
13
  default_ident = "text-completion"
14
+ default_concurrency = 1
14
15
 
15
16
  class LlmResult:
16
- def __init__(self, text=None, in_token=None, out_token=None, model=None):
17
+ def __init__(
18
+ self, text = None, in_token = None, out_token = None,
19
+ model = None,
20
+ ):
17
21
  self.text = text
18
22
  self.in_token = in_token
19
23
  self.out_token = out_token
@@ -25,14 +29,19 @@ class LlmService(FlowProcessor):
25
29
  def __init__(self, **params):
26
30
 
27
31
  id = params.get("id")
32
+ concurrency = params.get("concurrency", 1)
28
33
 
29
- super(LlmService, self).__init__(**params | { "id": id })
34
+ super(LlmService, self).__init__(**params | {
35
+ "id": id,
36
+ "concurrency": concurrency,
37
+ })
30
38
 
31
39
  self.register_specification(
32
40
  ConsumerSpec(
33
41
  name = "request",
34
42
  schema = TextCompletionRequest,
35
- handler = self.on_request
43
+ handler = self.on_request,
44
+ concurrency = concurrency,
36
45
  )
37
46
  )
38
47
 
@@ -115,5 +124,12 @@ class LlmService(FlowProcessor):
115
124
  @staticmethod
116
125
  def add_args(parser):
117
126
 
127
+ parser.add_argument(
128
+ '-c', '--concurrency',
129
+ type=int,
130
+ default=default_concurrency,
131
+ help=f'LLM max output tokens (default: {default_concurrency})'
132
+ )
133
+
118
134
  FlowProcessor.add_args(parser)
119
135
 
@@ -1,4 +1,8 @@
1
1
 
2
+ # Subscriber is similar to consumer: It provides a service to take stuff
3
+ # off of a queue and make it available using an internal broker system,
4
+ # so suitable for when multiple recipients are reading from the same queue
5
+
2
6
  from pulsar.schema import JsonSchema
3
7
  import asyncio
4
8
  import _pulsar
@@ -0,0 +1 @@
1
+ __version__ = "1.0.12"
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trustgraph-base
3
- Version: 1.0.11
3
+ Version: 1.0.12
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/v1.0.11.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v1.0.12.tar.gz
7
7
  Author: trustgraph.ai
8
8
  Author-email: security@trustgraph.ai
9
9
  Classifier: Programming Language :: Python :: 3
@@ -1 +0,0 @@
1
- __version__ = "1.0.11"