trustgraph-base 1.2.0__tar.gz → 1.2.4__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 (114) hide show
  1. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/PKG-INFO +6 -7
  2. trustgraph_base-1.2.4/pyproject.toml +28 -0
  3. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/api/api.py +0 -5
  4. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/api/config.py +5 -1
  5. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/api/library.py +7 -4
  6. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/agent_service.py +6 -2
  7. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/async_processor.py +36 -13
  8. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/consumer.py +14 -13
  9. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/document_embeddings_client.py +6 -1
  10. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/document_embeddings_query_service.py +10 -5
  11. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/document_embeddings_store_service.py +6 -1
  12. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/embeddings_service.py +8 -4
  13. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/flow_processor.py +10 -6
  14. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/graph_embeddings_client.py +6 -1
  15. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/graph_embeddings_query_service.py +10 -5
  16. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/graph_embeddings_store_service.py +6 -1
  17. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/llm_service.py +6 -2
  18. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/producer.py +8 -4
  19. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/publisher.py +5 -1
  20. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/request_response_spec.py +8 -4
  21. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/subscriber.py +9 -6
  22. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/tool_service.py +6 -2
  23. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/triples_query_service.py +10 -5
  24. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/triples_store_service.py +6 -1
  25. trustgraph_base-1.2.4/trustgraph/base_version.py +1 -0
  26. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph_base.egg-info/PKG-INFO +6 -7
  27. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph_base.egg-info/SOURCES.txt +1 -1
  28. trustgraph-base-1.2.0/setup.py +0 -42
  29. trustgraph-base-1.2.0/trustgraph/base_version.py +0 -1
  30. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/README.md +0 -0
  31. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/setup.cfg +0 -0
  32. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/api/__init__.py +0 -0
  33. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/api/exceptions.py +0 -0
  34. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/api/flow.py +0 -0
  35. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/api/knowledge.py +0 -0
  36. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/api/types.py +0 -0
  37. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/__init__.py +0 -0
  38. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/agent_client.py +0 -0
  39. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/consumer_spec.py +0 -0
  40. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/embeddings_client.py +0 -0
  41. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/flow.py +0 -0
  42. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/graph_rag_client.py +0 -0
  43. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/metrics.py +0 -0
  44. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/producer_spec.py +0 -0
  45. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/prompt_client.py +0 -0
  46. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/pubsub.py +0 -0
  47. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/setting_spec.py +0 -0
  48. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/spec.py +0 -0
  49. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/subscriber_spec.py +0 -0
  50. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/text_completion_client.py +0 -0
  51. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/tool_client.py +0 -0
  52. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/base/triples_client.py +0 -0
  53. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/clients/__init__.py +0 -0
  54. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/clients/agent_client.py +0 -0
  55. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/clients/base.py +0 -0
  56. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/clients/config_client.py +0 -0
  57. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/clients/document_embeddings_client.py +0 -0
  58. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/clients/document_rag_client.py +0 -0
  59. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/clients/embeddings_client.py +0 -0
  60. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/clients/graph_embeddings_client.py +0 -0
  61. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/clients/graph_rag_client.py +0 -0
  62. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/clients/llm_client.py +0 -0
  63. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/clients/prompt_client.py +0 -0
  64. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/clients/triples_query_client.py +0 -0
  65. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/exceptions.py +0 -0
  66. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/knowledge/__init__.py +0 -0
  67. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/knowledge/defs.py +0 -0
  68. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/knowledge/document.py +0 -0
  69. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/knowledge/identifier.py +0 -0
  70. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/knowledge/organization.py +0 -0
  71. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/knowledge/publication.py +0 -0
  72. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/log_level.py +0 -0
  73. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/__init__.py +0 -0
  74. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/registry.py +0 -0
  75. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/__init__.py +0 -0
  76. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/agent.py +0 -0
  77. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/base.py +0 -0
  78. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/config.py +0 -0
  79. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/document_loading.py +0 -0
  80. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/embeddings.py +0 -0
  81. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/embeddings_query.py +0 -0
  82. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/flow.py +0 -0
  83. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/knowledge.py +0 -0
  84. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/library.py +0 -0
  85. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/metadata.py +0 -0
  86. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/primitives.py +0 -0
  87. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/prompt.py +0 -0
  88. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/retrieval.py +0 -0
  89. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/text_completion.py +0 -0
  90. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/tool.py +0 -0
  91. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/messaging/translators/triples.py +0 -0
  92. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/objects/__init__.py +0 -0
  93. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/objects/field.py +0 -0
  94. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/objects/object.py +0 -0
  95. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/rdf.py +0 -0
  96. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/__init__.py +0 -0
  97. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/agent.py +0 -0
  98. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/config.py +0 -0
  99. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/documents.py +0 -0
  100. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/flows.py +0 -0
  101. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/graph.py +0 -0
  102. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/knowledge.py +0 -0
  103. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/library.py +0 -0
  104. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/lookup.py +0 -0
  105. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/metadata.py +0 -0
  106. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/models.py +0 -0
  107. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/object.py +0 -0
  108. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/prompt.py +0 -0
  109. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/retrieval.py +0 -0
  110. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/topic.py +0 -0
  111. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph/schema/types.py +0 -0
  112. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph_base.egg-info/dependency_links.txt +0 -0
  113. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph_base.egg-info/requires.txt +1 -1
  114. {trustgraph-base-1.2.0 → trustgraph_base-1.2.4}/trustgraph_base.egg-info/top_level.txt +0 -0
@@ -1,15 +1,14 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: trustgraph-base
3
- Version: 1.2.0
3
+ Version: 1.2.4
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
- Home-page: https://github.com/trustgraph-ai/trustgraph
6
- Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v1.2.0.tar.gz
7
- Author: trustgraph.ai
8
- Author-email: security@trustgraph.ai
5
+ Author-email: "trustgraph.ai" <security@trustgraph.ai>
6
+ Project-URL: Homepage, https://github.com/trustgraph-ai/trustgraph
9
7
  Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
11
8
  Classifier: Operating System :: OS Independent
12
9
  Requires-Python: >=3.8
13
10
  Description-Content-Type: text/markdown
11
+ Requires-Dist: pulsar-client
12
+ Requires-Dist: prometheus-client
14
13
 
15
14
  See https://trustgraph.ai/
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "trustgraph-base"
7
+ dynamic = ["version"]
8
+ authors = [{name = "trustgraph.ai", email = "security@trustgraph.ai"}]
9
+ description = "TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline."
10
+ readme = "README.md"
11
+ requires-python = ">=3.8"
12
+ dependencies = [
13
+ "pulsar-client",
14
+ "prometheus-client",
15
+ ]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Operating System :: OS Independent",
19
+ ]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/trustgraph-ai/trustgraph"
23
+
24
+ [tool.setuptools.packages.find]
25
+ include = ["trustgraph*"]
26
+
27
+ [tool.setuptools.dynamic]
28
+ version = {attr = "trustgraph.base_version.__version__"}
@@ -49,9 +49,6 @@ class Api:
49
49
 
50
50
  url = f"{self.url}{path}"
51
51
 
52
- # print("uri:", url)
53
- # print(json.dumps(request, indent=4))
54
-
55
52
  # Invoke the API, input is passed as JSON
56
53
  resp = requests.post(url, json=request, timeout=self.timeout)
57
54
 
@@ -59,8 +56,6 @@ class Api:
59
56
  if resp.status_code != 200:
60
57
  raise ProtocolException(f"Status code {resp.status_code}")
61
58
 
62
- # print(resp.text)
63
-
64
59
  try:
65
60
  # Parse the response as JSON
66
61
  object = resp.json()
@@ -1,7 +1,11 @@
1
1
 
2
+ import logging
3
+
2
4
  from . exceptions import *
3
5
  from . types import ConfigValue
4
6
 
7
+ logger = logging.getLogger(__name__)
8
+
5
9
  class Config:
6
10
 
7
11
  def __init__(self, api):
@@ -33,7 +37,7 @@ class Config:
33
37
  for v in object["values"]
34
38
  ]
35
39
  except Exception as e:
36
- print(e)
40
+ logger.error("Failed to parse config get response", exc_info=True)
37
41
  raise ProtocolException("Response not formatted correctly")
38
42
 
39
43
  def put(self, values):
@@ -2,11 +2,14 @@
2
2
  import datetime
3
3
  import time
4
4
  import base64
5
+ import logging
5
6
 
6
7
  from . types import DocumentMetadata, ProcessingMetadata, Triple
7
8
  from .. knowledge import hash, Uri, Literal
8
9
  from . exceptions import *
9
10
 
11
+ logger = logging.getLogger(__name__)
12
+
10
13
  def to_value(x):
11
14
  if x["e"]: return Uri(x["v"])
12
15
  return Literal(x["v"])
@@ -112,7 +115,7 @@ class Library:
112
115
  for v in object["document-metadatas"]
113
116
  ]
114
117
  except Exception as e:
115
- print(e)
118
+ logger.error("Failed to parse document list response", exc_info=True)
116
119
  raise ProtocolException(f"Response not formatted correctly")
117
120
 
118
121
  def get_document(self, user, id):
@@ -145,7 +148,7 @@ class Library:
145
148
  tags = doc["tags"]
146
149
  )
147
150
  except Exception as e:
148
- print(e)
151
+ logger.error("Failed to parse document response", exc_info=True)
149
152
  raise ProtocolException(f"Response not formatted correctly")
150
153
 
151
154
  def update_document(self, user, id, metadata):
@@ -192,7 +195,7 @@ class Library:
192
195
  tags = doc["tags"]
193
196
  )
194
197
  except Exception as e:
195
- print(e)
198
+ logger.error("Failed to parse document update response", exc_info=True)
196
199
  raise ProtocolException(f"Response not formatted correctly")
197
200
 
198
201
  def remove_document(self, user, id):
@@ -266,6 +269,6 @@ class Library:
266
269
  for v in object["processing-metadatas"]
267
270
  ]
268
271
  except Exception as e:
269
- print(e)
272
+ logger.error("Failed to parse processing list response", exc_info=True)
270
273
  raise ProtocolException(f"Response not formatted correctly")
271
274
 
@@ -4,12 +4,16 @@ Agent manager service completion base class
4
4
  """
5
5
 
6
6
  import time
7
+ import logging
7
8
  from prometheus_client import Histogram
8
9
 
9
10
  from .. schema import AgentRequest, AgentResponse, Error
10
11
  from .. exceptions import TooManyRequests
11
12
  from .. base import FlowProcessor, ConsumerSpec, ProducerSpec
12
13
 
14
+ # Module logger
15
+ logger = logging.getLogger(__name__)
16
+
13
17
  default_ident = "agent-manager"
14
18
 
15
19
  class AgentService(FlowProcessor):
@@ -76,9 +80,9 @@ class AgentService(FlowProcessor):
76
80
  except Exception as e:
77
81
 
78
82
  # Apart from rate limits, treat all exceptions as unrecoverable
79
- print(f"on_request Exception: {e}")
83
+ logger.error(f"Exception in agent service on_request: {e}", exc_info=True)
80
84
 
81
- print("Send error response...", flush=True)
85
+ logger.info("Sending error response...")
82
86
 
83
87
  await flow.producer["response"].send(
84
88
  AgentResponse(
@@ -9,6 +9,8 @@ import argparse
9
9
  import _pulsar
10
10
  import time
11
11
  import uuid
12
+ import logging
13
+ import os
12
14
  from prometheus_client import start_http_server, Info
13
15
 
14
16
  from .. schema import ConfigPush, config_push_queue
@@ -20,6 +22,9 @@ from . metrics import ProcessorMetrics, ConsumerMetrics
20
22
 
21
23
  default_config_queue = config_push_queue
22
24
 
25
+ # Module logger
26
+ logger = logging.getLogger(__name__)
27
+
23
28
  # Async processor
24
29
  class AsyncProcessor:
25
30
 
@@ -113,7 +118,7 @@ class AsyncProcessor:
113
118
  version = message.value().version
114
119
 
115
120
  # Invoke message handlers
116
- print("Config change event", version, flush=True)
121
+ logger.info(f"Config change event: version={version}")
117
122
  for ch in self.config_handlers:
118
123
  await ch(config, version)
119
124
 
@@ -156,9 +161,23 @@ class AsyncProcessor:
156
161
 
157
162
  # This is here to output a debug message, shouldn't be needed.
158
163
  except Exception as e:
159
- print("Exception, closing taskgroup", flush=True)
164
+ logger.error("Exception, closing taskgroup", exc_info=True)
160
165
  raise e
161
166
 
167
+ @classmethod
168
+ def setup_logging(cls, log_level='INFO'):
169
+ """Configure logging for the entire application"""
170
+ # Support environment variable override
171
+ env_log_level = os.environ.get('TRUSTGRAPH_LOG_LEVEL', log_level)
172
+
173
+ # Configure logging
174
+ logging.basicConfig(
175
+ level=getattr(logging, env_log_level.upper()),
176
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
177
+ handlers=[logging.StreamHandler()]
178
+ )
179
+ logger.info(f"Logging configured with level: {env_log_level}")
180
+
162
181
  # Startup fabric. launch calls launch_async in async mode.
163
182
  @classmethod
164
183
  def launch(cls, ident, doc):
@@ -183,8 +202,11 @@ class AsyncProcessor:
183
202
  args = parser.parse_args()
184
203
  args = vars(args)
185
204
 
205
+ # Setup logging before anything else
206
+ cls.setup_logging(args.get('log_level', 'INFO').upper())
207
+
186
208
  # Debug
187
- print(args, flush=True)
209
+ logger.debug(f"Arguments: {args}")
188
210
 
189
211
  # Start the Prometheus metrics service if needed
190
212
  if args["metrics"]:
@@ -193,7 +215,7 @@ class AsyncProcessor:
193
215
  # Loop forever, exception handler
194
216
  while True:
195
217
 
196
- print("Starting...", flush=True)
218
+ logger.info("Starting...")
197
219
 
198
220
  try:
199
221
 
@@ -203,30 +225,30 @@ class AsyncProcessor:
203
225
  ))
204
226
 
205
227
  except KeyboardInterrupt:
206
- print("Keyboard interrupt.", flush=True)
228
+ logger.info("Keyboard interrupt.")
207
229
  return
208
230
 
209
231
  except _pulsar.Interrupted:
210
- print("Pulsar Interrupted.", flush=True)
232
+ logger.info("Pulsar Interrupted.")
211
233
  return
212
234
 
213
235
  # Exceptions from a taskgroup come in as an exception group
214
236
  except ExceptionGroup as e:
215
237
 
216
- print("Exception group:", flush=True)
238
+ logger.error("Exception group:")
217
239
 
218
240
  for se in e.exceptions:
219
- print(" Type:", type(se), flush=True)
220
- print(f" Exception: {se}", flush=True)
241
+ logger.error(f" Type: {type(se)}")
242
+ logger.error(f" Exception: {se}", exc_info=se)
221
243
 
222
244
  except Exception as e:
223
- print("Type:", type(e), flush=True)
224
- print("Exception:", e, flush=True)
245
+ logger.error(f"Type: {type(e)}")
246
+ logger.error(f"Exception: {e}", exc_info=True)
225
247
 
226
248
  # Retry occurs here
227
- print("Will retry...", flush=True)
249
+ logger.warning("Will retry...")
228
250
  time.sleep(4)
229
- print("Retrying...", flush=True)
251
+ logger.info("Retrying...")
230
252
 
231
253
  # The command-line arguments are built using a stack of add_args
232
254
  # invocations
@@ -254,3 +276,4 @@ class AsyncProcessor:
254
276
  default=8000,
255
277
  help=f'Pulsar host (default: 8000)',
256
278
  )
279
+
@@ -14,9 +14,13 @@ import pulsar
14
14
  import _pulsar
15
15
  import asyncio
16
16
  import time
17
+ import logging
17
18
 
18
19
  from .. exceptions import TooManyRequests
19
20
 
21
+ # Module logger
22
+ logger = logging.getLogger(__name__)
23
+
20
24
  class Consumer:
21
25
 
22
26
  def __init__(
@@ -90,7 +94,7 @@ class Consumer:
90
94
 
91
95
  try:
92
96
 
93
- print(self.topic, "subscribing...", flush=True)
97
+ logger.info(f"Subscribing to topic: {self.topic}")
94
98
 
95
99
  if self.start_of_messages:
96
100
  pos = pulsar.InitialPosition.Earliest
@@ -108,21 +112,18 @@ class Consumer:
108
112
 
109
113
  except Exception as e:
110
114
 
111
- print("consumer subs Exception:", e, flush=True)
115
+ logger.error(f"Consumer subscription exception: {e}", exc_info=True)
112
116
  await asyncio.sleep(self.reconnect_time)
113
117
  continue
114
118
 
115
- print(self.topic, "subscribed", flush=True)
119
+ logger.info(f"Successfully subscribed to topic: {self.topic}")
116
120
 
117
121
  if self.metrics:
118
122
  self.metrics.state("running")
119
123
 
120
124
  try:
121
125
 
122
- print(
123
- "Starting", self.concurrency, "receiver threads",
124
- flush=True
125
- )
126
+ logger.info(f"Starting {self.concurrency} receiver threads")
126
127
 
127
128
  async with asyncio.TaskGroup() as tg:
128
129
 
@@ -138,7 +139,7 @@ class Consumer:
138
139
 
139
140
  except Exception as e:
140
141
 
141
- print("consumer loop exception:", e, flush=True)
142
+ logger.error(f"Consumer loop exception: {e}", exc_info=True)
142
143
  self.consumer.unsubscribe()
143
144
  self.consumer.close()
144
145
  self.consumer = None
@@ -174,7 +175,7 @@ class Consumer:
174
175
 
175
176
  if time.time() > expiry:
176
177
 
177
- print("Gave up waiting for rate-limit retry", flush=True)
178
+ logger.warning("Gave up waiting for rate-limit retry")
178
179
 
179
180
  # Message failed to be processed, this causes it to
180
181
  # be retried
@@ -188,7 +189,7 @@ class Consumer:
188
189
 
189
190
  try:
190
191
 
191
- print("Handle...", flush=True)
192
+ logger.debug("Processing message...")
192
193
 
193
194
  if self.metrics:
194
195
 
@@ -198,7 +199,7 @@ class Consumer:
198
199
  else:
199
200
  await self.handler(msg, self, self.flow)
200
201
 
201
- print("Handled.", flush=True)
202
+ logger.debug("Message processed successfully")
202
203
 
203
204
  # Acknowledge successful processing of the message
204
205
  self.consumer.acknowledge(msg)
@@ -211,7 +212,7 @@ class Consumer:
211
212
 
212
213
  except TooManyRequests:
213
214
 
214
- print("TooManyRequests: will retry...", flush=True)
215
+ logger.warning("Rate limit exceeded, will retry...")
215
216
 
216
217
  if self.metrics:
217
218
  self.metrics.rate_limit()
@@ -224,7 +225,7 @@ class Consumer:
224
225
 
225
226
  except Exception as e:
226
227
 
227
- print("consume exception:", e, flush=True)
228
+ logger.error(f"Message processing exception: {e}", exc_info=True)
228
229
 
229
230
  # Message failed to be processed, this causes it to
230
231
  # be retried
@@ -1,8 +1,13 @@
1
1
 
2
+ import logging
3
+
2
4
  from . request_response_spec import RequestResponse, RequestResponseSpec
3
5
  from .. schema import DocumentEmbeddingsRequest, DocumentEmbeddingsResponse
4
6
  from .. knowledge import Uri, Literal
5
7
 
8
+ # Module logger
9
+ logger = logging.getLogger(__name__)
10
+
6
11
  class DocumentEmbeddingsClient(RequestResponse):
7
12
  async def query(self, vectors, limit=20, user="trustgraph",
8
13
  collection="default", timeout=30):
@@ -17,7 +22,7 @@ class DocumentEmbeddingsClient(RequestResponse):
17
22
  timeout=timeout
18
23
  )
19
24
 
20
- print(resp, flush=True)
25
+ logger.debug(f"Document embeddings response: {resp}")
21
26
 
22
27
  if resp.error:
23
28
  raise RuntimeError(resp.error.message)
@@ -4,6 +4,8 @@ Document embeddings query service. Input is vectors. Output is list of
4
4
  embeddings.
5
5
  """
6
6
 
7
+ import logging
8
+
7
9
  from .. schema import DocumentEmbeddingsRequest, DocumentEmbeddingsResponse
8
10
  from .. schema import Error, Value
9
11
 
@@ -11,6 +13,9 @@ from . flow_processor import FlowProcessor
11
13
  from . consumer_spec import ConsumerSpec
12
14
  from . producer_spec import ProducerSpec
13
15
 
16
+ # Module logger
17
+ logger = logging.getLogger(__name__)
18
+
14
19
  default_ident = "ge-query"
15
20
 
16
21
  class DocumentEmbeddingsQueryService(FlowProcessor):
@@ -47,21 +52,21 @@ class DocumentEmbeddingsQueryService(FlowProcessor):
47
52
  # Sender-produced ID
48
53
  id = msg.properties()["id"]
49
54
 
50
- print(f"Handling input {id}...", flush=True)
55
+ logger.debug(f"Handling document embeddings query request {id}...")
51
56
 
52
57
  docs = await self.query_document_embeddings(request)
53
58
 
54
- print("Send response...", flush=True)
59
+ logger.debug("Sending document embeddings query response...")
55
60
  r = DocumentEmbeddingsResponse(documents=docs, error=None)
56
61
  await flow("response").send(r, properties={"id": id})
57
62
 
58
- print("Done.", flush=True)
63
+ logger.debug("Document embeddings query request completed")
59
64
 
60
65
  except Exception as e:
61
66
 
62
- print(f"Exception: {e}")
67
+ logger.error(f"Exception in document embeddings query service: {e}", exc_info=True)
63
68
 
64
- print("Send error response...", flush=True)
69
+ logger.info("Sending error response...")
65
70
 
66
71
  r = DocumentEmbeddingsResponse(
67
72
  error=Error(
@@ -3,10 +3,15 @@
3
3
  Document embeddings store base class
4
4
  """
5
5
 
6
+ import logging
7
+
6
8
  from .. schema import DocumentEmbeddings
7
9
  from .. base import FlowProcessor, ConsumerSpec
8
10
  from .. exceptions import TooManyRequests
9
11
 
12
+ # Module logger
13
+ logger = logging.getLogger(__name__)
14
+
10
15
  default_ident = "document-embeddings-write"
11
16
 
12
17
  class DocumentEmbeddingsStoreService(FlowProcessor):
@@ -40,7 +45,7 @@ class DocumentEmbeddingsStoreService(FlowProcessor):
40
45
 
41
46
  except Exception as e:
42
47
 
43
- print(f"Exception: {e}")
48
+ logger.error(f"Exception in document embeddings store service: {e}", exc_info=True)
44
49
  raise e
45
50
 
46
51
  @staticmethod
@@ -4,12 +4,16 @@ Embeddings resolution base class
4
4
  """
5
5
 
6
6
  import time
7
+ import logging
7
8
  from prometheus_client import Histogram
8
9
 
9
10
  from .. schema import EmbeddingsRequest, EmbeddingsResponse, Error
10
11
  from .. exceptions import TooManyRequests
11
12
  from .. base import FlowProcessor, ConsumerSpec, ProducerSpec
12
13
 
14
+ # Module logger
15
+ logger = logging.getLogger(__name__)
16
+
13
17
  default_ident = "embeddings"
14
18
  default_concurrency = 1
15
19
 
@@ -51,7 +55,7 @@ class EmbeddingsService(FlowProcessor):
51
55
 
52
56
  id = msg.properties()["id"]
53
57
 
54
- print("Handling request", id, "...", flush=True)
58
+ logger.debug(f"Handling embeddings request {id}...")
55
59
 
56
60
  vectors = await self.on_embeddings(request.text)
57
61
 
@@ -63,7 +67,7 @@ class EmbeddingsService(FlowProcessor):
63
67
  properties={"id": id}
64
68
  )
65
69
 
66
- print("Handled.", flush=True)
70
+ logger.debug("Embeddings request handled successfully")
67
71
 
68
72
  except TooManyRequests as e:
69
73
  raise e
@@ -72,9 +76,9 @@ class EmbeddingsService(FlowProcessor):
72
76
 
73
77
  # Apart from rate limits, treat all exceptions as unrecoverable
74
78
 
75
- print(f"Exception: {e}", flush=True)
79
+ logger.error(f"Exception in embeddings service: {e}", exc_info=True)
76
80
 
77
- print("Send error response...", flush=True)
81
+ logger.info("Sending error response...")
78
82
 
79
83
  await flow.producer["response"].send(
80
84
  EmbeddingsResponse(
@@ -4,6 +4,7 @@
4
4
  # configuration service which can't manage itself.
5
5
 
6
6
  import json
7
+ import logging
7
8
 
8
9
  from pulsar.schema import JsonSchema
9
10
 
@@ -14,6 +15,9 @@ from .. log_level import LogLevel
14
15
  from . async_processor import AsyncProcessor
15
16
  from . flow import Flow
16
17
 
18
+ # Module logger
19
+ logger = logging.getLogger(__name__)
20
+
17
21
  # Parent class for configurable processors, configured with flows by
18
22
  # the config service
19
23
  class FlowProcessor(AsyncProcessor):
@@ -34,7 +38,7 @@ class FlowProcessor(AsyncProcessor):
34
38
  # Array of specifications: ConsumerSpec, ProducerSpec, SettingSpec
35
39
  self.specifications = []
36
40
 
37
- print("Service initialised.")
41
+ logger.info("Service initialised.")
38
42
 
39
43
  # Register a configuration variable
40
44
  def register_specification(self, spec):
@@ -44,19 +48,19 @@ class FlowProcessor(AsyncProcessor):
44
48
  async def start_flow(self, flow, defn):
45
49
  self.flows[flow] = Flow(self.id, flow, self, defn)
46
50
  await self.flows[flow].start()
47
- print("Started flow: ", flow)
51
+ logger.info(f"Started flow: {flow}")
48
52
 
49
53
  # Stop processing for a new flow
50
54
  async def stop_flow(self, flow):
51
55
  if flow in self.flows:
52
56
  await self.flows[flow].stop()
53
57
  del self.flows[flow]
54
- print("Stopped flow: ", flow, flush=True)
58
+ logger.info(f"Stopped flow: {flow}")
55
59
 
56
60
  # Event handler - called for a configuration change
57
61
  async def on_configure_flows(self, config, version):
58
62
 
59
- print("Got config version", version, flush=True)
63
+ logger.info(f"Got config version {version}")
60
64
 
61
65
  # Skip over invalid data
62
66
  if "flows-active" not in config: return
@@ -69,7 +73,7 @@ class FlowProcessor(AsyncProcessor):
69
73
 
70
74
  else:
71
75
 
72
- print("No configuration settings for me.", flush=True)
76
+ logger.debug("No configuration settings for me.")
73
77
  flow_config = {}
74
78
 
75
79
  # Get list of flows which should be running and are currently
@@ -88,7 +92,7 @@ class FlowProcessor(AsyncProcessor):
88
92
  if flow not in wanted_flows:
89
93
  await self.stop_flow(flow)
90
94
 
91
- print("Handled config update")
95
+ logger.info("Handled config update")
92
96
 
93
97
  # Start threads, just call parent
94
98
  async def start(self):
@@ -1,8 +1,13 @@
1
1
 
2
+ import logging
3
+
2
4
  from . request_response_spec import RequestResponse, RequestResponseSpec
3
5
  from .. schema import GraphEmbeddingsRequest, GraphEmbeddingsResponse
4
6
  from .. knowledge import Uri, Literal
5
7
 
8
+ # Module logger
9
+ logger = logging.getLogger(__name__)
10
+
6
11
  def to_value(x):
7
12
  if x.is_uri: return Uri(x.value)
8
13
  return Literal(x.value)
@@ -21,7 +26,7 @@ class GraphEmbeddingsClient(RequestResponse):
21
26
  timeout=timeout
22
27
  )
23
28
 
24
- print(resp, flush=True)
29
+ logger.debug(f"Graph embeddings response: {resp}")
25
30
 
26
31
  if resp.error:
27
32
  raise RuntimeError(resp.error.message)
@@ -4,6 +4,8 @@ Graph embeddings query service. Input is vectors. Output is list of
4
4
  embeddings.
5
5
  """
6
6
 
7
+ import logging
8
+
7
9
  from .. schema import GraphEmbeddingsRequest, GraphEmbeddingsResponse
8
10
  from .. schema import Error, Value
9
11
 
@@ -11,6 +13,9 @@ from . flow_processor import FlowProcessor
11
13
  from . consumer_spec import ConsumerSpec
12
14
  from . producer_spec import ProducerSpec
13
15
 
16
+ # Module logger
17
+ logger = logging.getLogger(__name__)
18
+
14
19
  default_ident = "ge-query"
15
20
 
16
21
  class GraphEmbeddingsQueryService(FlowProcessor):
@@ -47,21 +52,21 @@ class GraphEmbeddingsQueryService(FlowProcessor):
47
52
  # Sender-produced ID
48
53
  id = msg.properties()["id"]
49
54
 
50
- print(f"Handling input {id}...", flush=True)
55
+ logger.debug(f"Handling graph embeddings query request {id}...")
51
56
 
52
57
  entities = await self.query_graph_embeddings(request)
53
58
 
54
- print("Send response...", flush=True)
59
+ logger.debug("Sending graph embeddings query response...")
55
60
  r = GraphEmbeddingsResponse(entities=entities, error=None)
56
61
  await flow("response").send(r, properties={"id": id})
57
62
 
58
- print("Done.", flush=True)
63
+ logger.debug("Graph embeddings query request completed")
59
64
 
60
65
  except Exception as e:
61
66
 
62
- print(f"Exception: {e}")
67
+ logger.error(f"Exception in graph embeddings query service: {e}", exc_info=True)
63
68
 
64
- print("Send error response...", flush=True)
69
+ logger.info("Sending error response...")
65
70
 
66
71
  r = GraphEmbeddingsResponse(
67
72
  error=Error(