trustgraph-base 0.21.19__tar.gz → 0.22.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 (58) hide show
  1. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/PKG-INFO +2 -2
  2. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/api/api.py +29 -0
  3. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/base/base_processor.py +56 -3
  4. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/base/consumer.py +1 -1
  5. trustgraph-base-0.22.1/trustgraph/base_version.py +1 -0
  6. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/clients/base.py +8 -5
  7. trustgraph-base-0.22.1/trustgraph/clients/config_client.py +161 -0
  8. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/__init__.py +1 -0
  9. trustgraph-base-0.22.1/trustgraph/schema/config.py +71 -0
  10. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph_base.egg-info/PKG-INFO +2 -2
  11. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph_base.egg-info/SOURCES.txt +2 -0
  12. trustgraph-base-0.21.19/trustgraph/base_version.py +0 -1
  13. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/README.md +0 -0
  14. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/setup.cfg +0 -0
  15. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/setup.py +0 -0
  16. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/api/__init__.py +0 -0
  17. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/base/__init__.py +0 -0
  18. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/base/consumer_producer.py +0 -0
  19. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/base/producer.py +0 -0
  20. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/base/publisher.py +0 -0
  21. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/base/subscriber.py +0 -0
  22. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/clients/__init__.py +0 -0
  23. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/clients/agent_client.py +0 -0
  24. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/clients/document_embeddings_client.py +0 -0
  25. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/clients/document_rag_client.py +0 -0
  26. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/clients/embeddings_client.py +0 -0
  27. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/clients/graph_embeddings_client.py +0 -0
  28. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/clients/graph_rag_client.py +0 -0
  29. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/clients/llm_client.py +0 -0
  30. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/clients/prompt_client.py +0 -0
  31. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/clients/triples_query_client.py +0 -0
  32. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/exceptions.py +0 -0
  33. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/knowledge/__init__.py +0 -0
  34. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/knowledge/defs.py +0 -0
  35. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/knowledge/document.py +0 -0
  36. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/knowledge/identifier.py +0 -0
  37. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/knowledge/organization.py +0 -0
  38. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/knowledge/publication.py +0 -0
  39. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/log_level.py +0 -0
  40. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/objects/__init__.py +0 -0
  41. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/objects/field.py +0 -0
  42. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/objects/object.py +0 -0
  43. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/rdf.py +0 -0
  44. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/agent.py +0 -0
  45. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/documents.py +0 -0
  46. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/graph.py +0 -0
  47. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/library.py +0 -0
  48. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/lookup.py +0 -0
  49. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/metadata.py +0 -0
  50. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/models.py +0 -0
  51. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/object.py +0 -0
  52. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/prompt.py +0 -0
  53. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/retrieval.py +0 -0
  54. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/topic.py +0 -0
  55. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph/schema/types.py +0 -0
  56. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph_base.egg-info/dependency_links.txt +0 -0
  57. {trustgraph-base-0.21.19 → trustgraph-base-0.22.1}/trustgraph_base.egg-info/requires.txt +0 -0
  58. {trustgraph-base-0.21.19 → trustgraph-base-0.22.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.19
3
+ Version: 0.22.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.19.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.22.1.tar.gz
7
7
  Author: trustgraph.ai
8
8
  Author-email: security@trustgraph.ai
9
9
  Classifier: Programming Language :: Python :: 3
@@ -382,3 +382,32 @@ class Api:
382
382
  if resp.status_code != 200:
383
383
  raise ProtocolException(f"Status code {resp.status_code}")
384
384
 
385
+ def get_config(self):
386
+
387
+ # The input consists of system and prompt strings
388
+ input = {
389
+ "operation": "config"
390
+ }
391
+
392
+ url = f"{self.url}config"
393
+
394
+ # Invoke the API, input is passed as JSON
395
+ resp = requests.post(url, json=input)
396
+
397
+ # Should be a 200 status code
398
+ if resp.status_code != 200:
399
+ raise ProtocolException(f"Status code {resp.status_code}")
400
+
401
+ try:
402
+ # Parse the response as JSON
403
+ object = resp.json()
404
+ except:
405
+ raise ProtocolException(f"Expected JSON response")
406
+
407
+ self.check_error(resp)
408
+
409
+ try:
410
+ return object["config"], object["version"]
411
+ except:
412
+ raise ProtocolException(f"Response not formatted correctly")
413
+
@@ -3,12 +3,18 @@ import asyncio
3
3
  import os
4
4
  import argparse
5
5
  import pulsar
6
+ from pulsar.schema import JsonSchema
6
7
  import _pulsar
7
8
  import time
9
+ import uuid
8
10
  from prometheus_client import start_http_server, Info
9
11
 
12
+ from .. schema import ConfigPush, config_push_queue
10
13
  from .. log_level import LogLevel
11
14
 
15
+ default_config_queue = config_push_queue
16
+ config_subscriber_id = str(uuid.uuid4())
17
+
12
18
  class BaseProcessor:
13
19
 
14
20
  default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://pulsar:6650')
@@ -34,6 +40,11 @@ class BaseProcessor:
34
40
  pulsar_api_key = params.get("pulsar_api_key", None)
35
41
  log_level = params.get("log_level", LogLevel.INFO)
36
42
 
43
+ self.config_push_queue = params.get(
44
+ "config_push_queue",
45
+ default_config_queue
46
+ )
47
+
37
48
  self.pulsar_host = pulsar_host
38
49
  self.pulsar_api_key = pulsar_api_key
39
50
 
@@ -53,6 +64,12 @@ class BaseProcessor:
53
64
 
54
65
  self.pulsar_listener = pulsar_listener
55
66
 
67
+ self.config_subscriber = self.client.subscribe(
68
+ self.config_push_queue, config_subscriber_id,
69
+ consumer_type=pulsar.ConsumerType.Shared,
70
+ schema=JsonSchema(ConfigPush),
71
+ )
72
+
56
73
  def __del__(self):
57
74
 
58
75
  if hasattr(self, "client"):
@@ -74,6 +91,12 @@ class BaseProcessor:
74
91
  help=f'Pulsar API key',
75
92
  )
76
93
 
94
+ parser.add_argument(
95
+ '--config-push-queue',
96
+ default=default_config_queue,
97
+ help=f'Config push queue {default_config_queue}',
98
+ )
99
+
77
100
  parser.add_argument(
78
101
  '--pulsar-listener',
79
102
  help=f'Pulsar listener (default: none)',
@@ -104,14 +127,44 @@ class BaseProcessor:
104
127
  async def start(self):
105
128
  pass
106
129
 
130
+ async def run_config_queue(self):
131
+
132
+ if self.module == "config.service":
133
+ print("I am config-svc, not looking at config queue", flush=True)
134
+ return
135
+
136
+ print("Config thread running", flush=True)
137
+
138
+ while True:
139
+
140
+ try:
141
+ msg = await asyncio.to_thread(
142
+ self.config_subscriber.receive, timeout_millis=2000
143
+ )
144
+ except pulsar.Timeout:
145
+ continue
146
+
147
+ v = msg.value()
148
+ print("Got config version", v.version, flush=True)
149
+
150
+ await self.on_config(v.version, v.config)
151
+
152
+ async def on_config(self, version, config):
153
+ pass
154
+
107
155
  async def run(self):
108
156
  raise RuntimeError("Something should have implemented the run method")
109
157
 
110
158
  @classmethod
111
- async def launch_async(cls, args):
159
+ async def launch_async(cls, args, prog):
112
160
  p = cls(**args)
161
+ p.module = prog
113
162
  await p.start()
114
- await p.run()
163
+
164
+ task1 = asyncio.create_task(p.run_config_queue())
165
+ task2 = asyncio.create_task(p.run())
166
+
167
+ await asyncio.gather(task1, task2)
115
168
 
116
169
  @classmethod
117
170
  def launch(cls, prog, doc):
@@ -135,7 +188,7 @@ class BaseProcessor:
135
188
 
136
189
  try:
137
190
 
138
- asyncio.run(cls.launch_async(args))
191
+ asyncio.run(cls.launch_async(args, prog))
139
192
 
140
193
  except KeyboardInterrupt:
141
194
  print("Keyboard interrupt.")
@@ -82,7 +82,7 @@ class Consumer(BaseProcessor):
82
82
 
83
83
  while True:
84
84
 
85
- msg = self.consumer.receive()
85
+ msg = await asyncio.to_thread(self.consumer.receive)
86
86
 
87
87
  expiry = time.time() + self.rate_limit_timeout
88
88
 
@@ -0,0 +1 @@
1
+ __version__ = "0.22.1"
@@ -28,6 +28,7 @@ class BaseClient:
28
28
  output_schema=None,
29
29
  pulsar_host="pulsar://pulsar:6650",
30
30
  pulsar_api_key=None,
31
+ listener=None,
31
32
  ):
32
33
 
33
34
  if input_queue == None: raise RuntimeError("Need input_queue")
@@ -41,14 +42,16 @@ class BaseClient:
41
42
  if pulsar_api_key:
42
43
  auth = pulsar.AuthenticationToken(pulsar_api_key)
43
44
  self.client = pulsar.Client(
44
- pulsar_host,
45
- logger=pulsar.ConsoleLogger(log_level),
46
- authentication=auth,
45
+ pulsar_host,
46
+ logger=pulsar.ConsoleLogger(log_level),
47
+ authentication=auth,
48
+ listener=listener,
47
49
  )
48
50
  else:
49
51
  self.client = pulsar.Client(
50
- pulsar_host,
51
- logger=pulsar.ConsoleLogger(log_level)
52
+ pulsar_host,
53
+ logger=pulsar.ConsoleLogger(log_level),
54
+ listener_name=listener,
52
55
  )
53
56
 
54
57
  self.producer = self.client.create_producer(
@@ -0,0 +1,161 @@
1
+
2
+ import _pulsar
3
+ import json
4
+ import dataclasses
5
+
6
+ from .. schema import ConfigRequest, ConfigResponse, ConfigKey, ConfigValue
7
+ from .. schema import config_request_queue
8
+ from .. schema import config_response_queue
9
+ from . base import BaseClient
10
+
11
+ # Ugly
12
+ ERROR=_pulsar.LoggerLevel.Error
13
+ WARN=_pulsar.LoggerLevel.Warn
14
+ INFO=_pulsar.LoggerLevel.Info
15
+ DEBUG=_pulsar.LoggerLevel.Debug
16
+
17
+ @dataclasses.dataclass
18
+ class Definition:
19
+ name: str
20
+ definition: str
21
+
22
+ @dataclasses.dataclass
23
+ class Relationship:
24
+ s: str
25
+ p: str
26
+ o: str
27
+ o_entity: str
28
+
29
+ @dataclasses.dataclass
30
+ class Topic:
31
+ name: str
32
+ definition: str
33
+
34
+ class ConfigClient(BaseClient):
35
+
36
+ def __init__(
37
+ self, log_level=ERROR,
38
+ subscriber=None,
39
+ input_queue=None,
40
+ output_queue=None,
41
+ pulsar_host="pulsar://pulsar:6650",
42
+ listener=None,
43
+ pulsar_api_key=None,
44
+ ):
45
+
46
+ if input_queue == None:
47
+ input_queue = config_request_queue
48
+
49
+ if output_queue == None:
50
+ output_queue = config_response_queue
51
+
52
+ super(ConfigClient, self).__init__(
53
+ log_level=log_level,
54
+ subscriber=subscriber,
55
+ input_queue=input_queue,
56
+ output_queue=output_queue,
57
+ pulsar_host=pulsar_host,
58
+ pulsar_api_key=pulsar_api_key,
59
+ input_schema=ConfigRequest,
60
+ output_schema=ConfigResponse,
61
+ listener=listener,
62
+ )
63
+
64
+ def request_get(self, keys, timeout=300):
65
+
66
+ resp = self.call(
67
+ id=id,
68
+ operation="get",
69
+ keys=[
70
+ ConfigKey(
71
+ type = k["type"],
72
+ key = k["key"]
73
+ )
74
+ for k in keys
75
+ ],
76
+ timeout=timeout
77
+ )
78
+
79
+ return [
80
+ {
81
+ "type": v.type,
82
+ "key": v.key,
83
+ "value": v.value
84
+ }
85
+ for v in resp.values
86
+ ]
87
+
88
+ def request_list(self, type, timeout=300):
89
+
90
+ resp = self.call(
91
+ id=id,
92
+ operation="list",
93
+ type=type,
94
+ timeout=timeout
95
+ )
96
+
97
+ return resp.directory
98
+
99
+ def request_getvalues(self, type, timeout=300):
100
+
101
+ resp = self.call(
102
+ id=id,
103
+ operation="getvalues",
104
+ type=type,
105
+ timeout=timeout
106
+ )
107
+
108
+ return [
109
+ {
110
+ "type": v.type,
111
+ "key": v.key,
112
+ "value": v.value
113
+ }
114
+ for v in resp.values
115
+ ]
116
+
117
+ def request_delete(self, keys, timeout=300):
118
+
119
+ resp = self.call(
120
+ id=id,
121
+ operation="delete",
122
+ keys=[
123
+ ConfigKey(
124
+ type = k["type"],
125
+ key = k["key"]
126
+ )
127
+ for k in keys
128
+ ],
129
+ timeout=timeout
130
+ )
131
+
132
+ return None
133
+
134
+ def request_put(self, value, timeout=300):
135
+
136
+ resp = self.call(
137
+ id=id,
138
+ operation="put",
139
+ values=[
140
+ ConfigValue(
141
+ type = k["type"],
142
+ key = k["key"],
143
+ value = k["value"]
144
+ )
145
+ for k in keys
146
+ ],
147
+ timeout=timeout
148
+ )
149
+
150
+ return None
151
+
152
+ def request_config(self, timeout=300):
153
+
154
+ resp = self.call(
155
+ id=id,
156
+ operation="config",
157
+ timeout=timeout
158
+ )
159
+
160
+ return resp.config
161
+
@@ -11,5 +11,6 @@ from . metadata import *
11
11
  from . agent import *
12
12
  from . lookup import *
13
13
  from . library import *
14
+ from . config import *
14
15
 
15
16
 
@@ -0,0 +1,71 @@
1
+
2
+ from pulsar.schema import Record, Bytes, String, Boolean, Array, Map, Integer
3
+
4
+ from . topic import topic
5
+ from . types import Error, RowSchema
6
+
7
+ ############################################################################
8
+
9
+ # Config service:
10
+ # get(keys) -> (version, values)
11
+ # list(type) -> (version, values)
12
+ # getvalues(type) -> (version, values)
13
+ # put(values) -> ()
14
+ # delete(keys) -> ()
15
+ # config() -> (version, config)
16
+ class ConfigKey(Record):
17
+ type = String()
18
+ key = String()
19
+
20
+ class ConfigValue(Record):
21
+ type = String()
22
+ key = String()
23
+ value = String()
24
+
25
+ # Prompt services, abstract the prompt generation
26
+ class ConfigRequest(Record):
27
+
28
+ operation = String() # get, list, getvalues, delete, put, config
29
+
30
+ # get, delete
31
+ keys = Array(ConfigKey())
32
+
33
+ # list, getvalues
34
+ type = String()
35
+
36
+ # put
37
+ values = Array(ConfigValue())
38
+
39
+ class ConfigResponse(Record):
40
+
41
+ # get, list, getvalues, config
42
+ version = Integer()
43
+
44
+ # get, getvalues
45
+ values = Array(ConfigValue())
46
+
47
+ # list
48
+ directory = Array(String())
49
+
50
+ # config
51
+ config = Map(Map(String()))
52
+
53
+ # Everything
54
+ error = Error()
55
+
56
+ class ConfigPush(Record):
57
+ version = Integer()
58
+ config = Map(Map(String()))
59
+
60
+ config_request_queue = topic(
61
+ 'config', kind='non-persistent', namespace='request'
62
+ )
63
+ config_response_queue = topic(
64
+ 'config', kind='non-persistent', namespace='response'
65
+ )
66
+ config_push_queue = topic(
67
+ 'config', kind='persistent', namespace='config'
68
+ )
69
+
70
+ ############################################################################
71
+
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trustgraph-base
3
- Version: 0.21.19
3
+ Version: 0.22.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.19.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.22.1.tar.gz
7
7
  Author: trustgraph.ai
8
8
  Author-email: security@trustgraph.ai
9
9
  Classifier: Programming Language :: Python :: 3
@@ -16,6 +16,7 @@ trustgraph/base/subscriber.py
16
16
  trustgraph/clients/__init__.py
17
17
  trustgraph/clients/agent_client.py
18
18
  trustgraph/clients/base.py
19
+ trustgraph/clients/config_client.py
19
20
  trustgraph/clients/document_embeddings_client.py
20
21
  trustgraph/clients/document_rag_client.py
21
22
  trustgraph/clients/embeddings_client.py
@@ -35,6 +36,7 @@ trustgraph/objects/field.py
35
36
  trustgraph/objects/object.py
36
37
  trustgraph/schema/__init__.py
37
38
  trustgraph/schema/agent.py
39
+ trustgraph/schema/config.py
38
40
  trustgraph/schema/documents.py
39
41
  trustgraph/schema/graph.py
40
42
  trustgraph/schema/library.py
@@ -1 +0,0 @@
1
- __version__ = "0.21.19"