trustgraph-base 0.23.4__tar.gz → 0.23.6__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 (86) hide show
  1. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/PKG-INFO +2 -2
  2. trustgraph-base-0.23.6/trustgraph/api/api.py +493 -0
  3. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/publisher.py +7 -2
  4. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/subscriber.py +9 -2
  5. trustgraph-base-0.23.6/trustgraph/base_version.py +1 -0
  6. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/clients/embeddings_client.py +0 -8
  7. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph_base.egg-info/PKG-INFO +2 -2
  8. trustgraph-base-0.23.4/trustgraph/api/api.py +0 -794
  9. trustgraph-base-0.23.4/trustgraph/base_version.py +0 -1
  10. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/README.md +0 -0
  11. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/setup.cfg +0 -0
  12. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/setup.py +0 -0
  13. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/api/__init__.py +0 -0
  14. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/__init__.py +0 -0
  15. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/agent_client.py +0 -0
  16. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/agent_service.py +0 -0
  17. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/async_processor.py +0 -0
  18. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/consumer.py +0 -0
  19. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/consumer_spec.py +0 -0
  20. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/document_embeddings_client.py +0 -0
  21. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/document_embeddings_query_service.py +0 -0
  22. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/document_embeddings_store_service.py +0 -0
  23. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/embeddings_client.py +0 -0
  24. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/embeddings_service.py +0 -0
  25. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/flow.py +0 -0
  26. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/flow_processor.py +0 -0
  27. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/graph_embeddings_client.py +0 -0
  28. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/graph_embeddings_query_service.py +0 -0
  29. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/graph_embeddings_store_service.py +0 -0
  30. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/graph_rag_client.py +0 -0
  31. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/llm_service.py +0 -0
  32. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/metrics.py +0 -0
  33. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/producer.py +0 -0
  34. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/producer_spec.py +0 -0
  35. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/prompt_client.py +0 -0
  36. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/pubsub.py +0 -0
  37. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/request_response_spec.py +0 -0
  38. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/setting_spec.py +0 -0
  39. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/spec.py +0 -0
  40. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/subscriber_spec.py +0 -0
  41. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/text_completion_client.py +0 -0
  42. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/triples_client.py +0 -0
  43. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/triples_query_service.py +0 -0
  44. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/base/triples_store_service.py +0 -0
  45. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/clients/__init__.py +0 -0
  46. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/clients/agent_client.py +0 -0
  47. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/clients/base.py +0 -0
  48. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/clients/config_client.py +0 -0
  49. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/clients/document_embeddings_client.py +0 -0
  50. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/clients/document_rag_client.py +0 -0
  51. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/clients/graph_embeddings_client.py +0 -0
  52. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/clients/graph_rag_client.py +0 -0
  53. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/clients/llm_client.py +0 -0
  54. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/clients/prompt_client.py +0 -0
  55. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/clients/triples_query_client.py +0 -0
  56. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/exceptions.py +0 -0
  57. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/knowledge/__init__.py +0 -0
  58. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/knowledge/defs.py +0 -0
  59. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/knowledge/document.py +0 -0
  60. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/knowledge/identifier.py +0 -0
  61. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/knowledge/organization.py +0 -0
  62. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/knowledge/publication.py +0 -0
  63. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/log_level.py +0 -0
  64. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/objects/__init__.py +0 -0
  65. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/objects/field.py +0 -0
  66. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/objects/object.py +0 -0
  67. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/rdf.py +0 -0
  68. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/__init__.py +0 -0
  69. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/agent.py +0 -0
  70. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/config.py +0 -0
  71. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/documents.py +0 -0
  72. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/flows.py +0 -0
  73. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/graph.py +0 -0
  74. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/library.py +0 -0
  75. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/lookup.py +0 -0
  76. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/metadata.py +0 -0
  77. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/models.py +0 -0
  78. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/object.py +0 -0
  79. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/prompt.py +0 -0
  80. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/retrieval.py +0 -0
  81. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/topic.py +0 -0
  82. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph/schema/types.py +0 -0
  83. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph_base.egg-info/SOURCES.txt +0 -0
  84. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph_base.egg-info/dependency_links.txt +0 -0
  85. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/trustgraph_base.egg-info/requires.txt +0 -0
  86. {trustgraph-base-0.23.4 → trustgraph-base-0.23.6}/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.23.4
3
+ Version: 0.23.6
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.23.4.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.23.6.tar.gz
7
7
  Author: trustgraph.ai
8
8
  Author-email: security@trustgraph.ai
9
9
  Classifier: Programming Language :: Python :: 3
@@ -0,0 +1,493 @@
1
+
2
+ import requests
3
+ import json
4
+ import dataclasses
5
+ import base64
6
+
7
+ from trustgraph.knowledge import hash, Uri, Literal
8
+
9
+ class ProtocolException(Exception):
10
+ pass
11
+
12
+ class ApplicationException(Exception):
13
+ pass
14
+
15
+ @dataclasses.dataclass
16
+ class Triple:
17
+ s : str
18
+ p : str
19
+ o : str
20
+
21
+ @dataclasses.dataclass
22
+ class ConfigKey:
23
+ type : str
24
+ key : str
25
+
26
+ @dataclasses.dataclass
27
+ class ConfigValue:
28
+ type : str
29
+ key : str
30
+ value : str
31
+
32
+ def check_error(response):
33
+
34
+ if "error" in response:
35
+
36
+ try:
37
+ msg = response["error"]["message"]
38
+ tp = response["error"]["type"]
39
+ except:
40
+ raise ApplicationException(response["error"])
41
+
42
+ raise ApplicationException(f"{tp}: {msg}")
43
+
44
+ class Api:
45
+
46
+ def __init__(self, url="http://localhost:8088/"):
47
+
48
+ self.url = url
49
+
50
+ if not url.endswith("/"):
51
+ self.url += "/"
52
+
53
+ self.url += "api/v1/"
54
+
55
+ def flow(self, flow="0000"):
56
+ return Flow(api=self, flow=flow)
57
+
58
+ def request(self, path, request):
59
+
60
+ url = f"{self.url}{path}"
61
+
62
+ # Invoke the API, input is passed as JSON
63
+ resp = requests.post(url, json=request)
64
+
65
+ # Should be a 200 status code
66
+ if resp.status_code != 200:
67
+ raise ProtocolException(f"Status code {resp.status_code}")
68
+
69
+ try:
70
+ # Parse the response as JSON
71
+ object = resp.json()
72
+ except:
73
+ raise ProtocolException(f"Expected JSON response")
74
+
75
+ check_error(object)
76
+
77
+ return object
78
+
79
+ def config_all(self):
80
+
81
+ # The input consists of system and prompt strings
82
+ input = {
83
+ "operation": "config"
84
+ }
85
+
86
+ object = self.request("config", input)
87
+
88
+ try:
89
+ return object["config"], object["version"]
90
+ except:
91
+ raise ProtocolException(f"Response not formatted correctly")
92
+
93
+ def config_get(self, keys):
94
+
95
+ # The input consists of system and prompt strings
96
+ input = {
97
+ "operation": "get",
98
+ "keys": [
99
+ { "type": k.type, "key": k.key }
100
+ for k in keys
101
+ ]
102
+ }
103
+
104
+ object = self.request("config", input)
105
+
106
+ try:
107
+ return [
108
+ ConfigValue(
109
+ type = v["type"],
110
+ key = v["key"],
111
+ value = v["value"]
112
+ )
113
+ for v in object["values"]
114
+ ]
115
+ except:
116
+ raise ProtocolException(f"Response not formatted correctly")
117
+
118
+ def config_put(self, values):
119
+
120
+ # The input consists of system and prompt strings
121
+ input = {
122
+ "operation": "put",
123
+ "values": [
124
+ { "type": v.type, "key": v.key, "value": v.value }
125
+ for v in values
126
+ ]
127
+ }
128
+
129
+ self.request("config", input)
130
+
131
+ def config_list(self, type):
132
+
133
+ # The input consists of system and prompt strings
134
+ input = {
135
+ "operation": "list",
136
+ "type": type,
137
+ }
138
+
139
+ return self.request("config", input)["directory"]
140
+
141
+ def config_getvalues(self, type):
142
+
143
+ # The input consists of system and prompt strings
144
+ input = {
145
+ "operation": "getvalues",
146
+ "type": type,
147
+ }
148
+
149
+ object = self.request("config", input)["directory"]
150
+
151
+ try:
152
+ return [
153
+ ConfigValue(
154
+ type = v["type"],
155
+ key = v["key"],
156
+ value = v["value"]
157
+ )
158
+ for v in object["values"]
159
+ ]
160
+ except:
161
+ raise ProtocolException(f"Response not formatted correctly")
162
+
163
+ def flow_list_classes(self):
164
+
165
+ # The input consists of system and prompt strings
166
+ input = {
167
+ "operation": "list-classes",
168
+ }
169
+
170
+ return self.request("flow", input)["class-names"]
171
+
172
+ def flow_get_class(self, class_name):
173
+
174
+ # The input consists of system and prompt strings
175
+ input = {
176
+ "operation": "get-class",
177
+ "class-name": class_name,
178
+ }
179
+
180
+ return json.loads(self.request("flow", input)["class-definition"])
181
+
182
+ def flow_put_class(self, class_name, definition):
183
+
184
+ # The input consists of system and prompt strings
185
+ input = {
186
+ "operation": "put-class",
187
+ "class-name": class_name,
188
+ "class-definition": json.dumps(definition),
189
+ }
190
+
191
+ self.request("flow", input)
192
+
193
+ def flow_delete_class(self, class_name):
194
+
195
+ # The input consists of system and prompt strings
196
+ input = {
197
+ "operation": "delete-class",
198
+ "class-name": class_name,
199
+ }
200
+
201
+ self.request("flow", input)
202
+
203
+ def flow_list(self):
204
+
205
+ # The input consists of system and prompt strings
206
+ input = {
207
+ "operation": "list-flows",
208
+ }
209
+
210
+ return self.request("flow", input)["flow-ids"]
211
+
212
+ def flow_get(self, id):
213
+
214
+ # The input consists of system and prompt strings
215
+ input = {
216
+ "operation": "get-flow",
217
+ "flow-id": id,
218
+ }
219
+
220
+ return json.loads(self.request("flow", input)["flow"])
221
+
222
+ def flow_start(self, class_name, id, description):
223
+
224
+ # The input consists of system and prompt strings
225
+ input = {
226
+ "operation": "start-flow",
227
+ "flow-id": id,
228
+ "class-name": class_name,
229
+ "description": description,
230
+ }
231
+
232
+ self.request("flow", input)
233
+
234
+ def flow_stop(self, id):
235
+
236
+ # The input consists of system and prompt strings
237
+ input = {
238
+ "operation": "stop-flow",
239
+ "flow-id": id,
240
+ }
241
+
242
+ self.request("flow", input)
243
+
244
+ class Flow:
245
+
246
+ def __init__(self, api, flow):
247
+ self.api = api
248
+ self.flow = flow
249
+
250
+ def text_completion(self, system, prompt):
251
+
252
+ # The input consists of system and prompt strings
253
+ input = {
254
+ "system": system,
255
+ "prompt": prompt
256
+ }
257
+
258
+ return self.api.request(
259
+ f"flow/{self.flow}/service/text-completion",
260
+ input
261
+ )["response"]
262
+
263
+ def agent(self, question):
264
+
265
+ # The input consists of a question
266
+ input = {
267
+ "question": question
268
+ }
269
+
270
+ return self.api.request(
271
+ f"flow/{self.flow}/service/agent",
272
+ input
273
+ )["answer"]
274
+
275
+ def graph_rag(
276
+ self, question, user="trustgraph", collection="default",
277
+ entity_limit=50, triple_limit=30, max_subgraph_size=150,
278
+ max_path_length=2,
279
+ ):
280
+
281
+ # The input consists of a question
282
+ input = {
283
+ "query": question,
284
+ "user": user,
285
+ "collection": collection,
286
+ "entity-limit": entity_limit,
287
+ "triple-limit": triple_limit,
288
+ "max-subgraph-size": max_subgraph_size,
289
+ "max-path-length": max_path_length,
290
+ }
291
+
292
+ return self.api.request(
293
+ f"flow/{self.flow}/service/graph-rag",
294
+ input
295
+ )["response"]
296
+
297
+ def document_rag(
298
+ self, question, user="trustgraph", collection="default",
299
+ doc_limit=10,
300
+ ):
301
+
302
+ # The input consists of a question
303
+ input = {
304
+ "query": question,
305
+ "user": user,
306
+ "collection": collection,
307
+ "doc-limit": doc_limit,
308
+ }
309
+
310
+ return self.api.request(
311
+ f"flow/{self.flow}/service/document-rag",
312
+ input
313
+ )["response"]
314
+
315
+ def embeddings(self, text):
316
+
317
+ # The input consists of a text block
318
+ input = {
319
+ "text": text
320
+ }
321
+
322
+ return self.api.request(
323
+ f"flow/{self.flow}/service/embeddings",
324
+ input
325
+ )["vectors"]
326
+
327
+ def prompt(self, id, variables):
328
+
329
+ # The input consists of system and prompt strings
330
+ input = {
331
+ "id": id,
332
+ "variables": variables
333
+ }
334
+
335
+ object = self.api.request(
336
+ f"flow/{self.flow}/service/prompt",
337
+ input
338
+ )
339
+
340
+ if "text" in object:
341
+ return object["text"]
342
+
343
+ if "object" in object:
344
+ try:
345
+ return json.loads(object["object"])
346
+ except Exception as e:
347
+ raise ProtocolException(
348
+ "Returned object not well-formed JSON"
349
+ )
350
+
351
+ raise ProtocolException("Response not formatted correctly")
352
+
353
+ def triples_query(
354
+ self, s=None, p=None, o=None,
355
+ user=None, collection=None, limit=10000
356
+ ):
357
+
358
+ # The input consists of system and prompt strings
359
+ input = {
360
+ "limit": limit
361
+ }
362
+
363
+ if user:
364
+ input["user"] = user
365
+
366
+ if collection:
367
+ input["collection"] = collection
368
+
369
+ if s:
370
+ if not isinstance(s, Uri):
371
+ raise RuntimeError("s must be Uri")
372
+ input["s"] = { "v": str(s), "e": isinstance(s, Uri), }
373
+
374
+ if p:
375
+ if not isinstance(p, Uri):
376
+ raise RuntimeError("p must be Uri")
377
+ input["p"] = { "v": str(p), "e": isinstance(p, Uri), }
378
+
379
+ if o:
380
+ if not isinstance(o, Uri) and not isinstance(o, Literal):
381
+ raise RuntimeError("o must be Uri or Literal")
382
+ input["o"] = { "v": str(o), "e": isinstance(o, Uri), }
383
+
384
+ object = self.api.request(
385
+ f"flow/{self.flow}/service/triples",
386
+ input
387
+ )
388
+
389
+ def to_value(x):
390
+ if x["e"]: return Uri(x["v"])
391
+ return Literal(x["v"])
392
+
393
+ return [
394
+ Triple(
395
+ s=to_value(t["s"]),
396
+ p=to_value(t["p"]),
397
+ o=to_value(t["o"])
398
+ )
399
+ for t in object["response"]
400
+ ]
401
+
402
+ def load_document(
403
+ self, document, id=None, metadata=None, user=None,
404
+ collection=None,
405
+ ):
406
+
407
+ if id is None:
408
+
409
+ if metadata is not None:
410
+
411
+ # Situation makes no sense. What can the metadata possibly
412
+ # mean if the caller doesn't know the document ID.
413
+ # Metadata should relate to the document by ID
414
+ raise RuntimeError("Can't specify metadata without id")
415
+
416
+ id = hash(document)
417
+
418
+ triples = []
419
+
420
+ def emit(t):
421
+ triples.append(t)
422
+
423
+ if metadata:
424
+ metadata.emit(
425
+ lambda t: triples.append({
426
+ "s": { "v": t["s"], "e": isinstance(t["s"], Uri) },
427
+ "p": { "v": t["p"], "e": isinstance(t["p"], Uri) },
428
+ "o": { "v": t["o"], "e": isinstance(t["o"], Uri) }
429
+ })
430
+ )
431
+
432
+ input = {
433
+ "id": id,
434
+ "metadata": triples,
435
+ "data": base64.b64encode(document).decode("utf-8"),
436
+ }
437
+
438
+ if user:
439
+ input["user"] = user
440
+
441
+ if collection:
442
+ input["collection"] = collection
443
+
444
+ return self.api.request(
445
+ f"flow/{self.flow}/service/document-load",
446
+ input
447
+ )
448
+
449
+ def load_text(
450
+ self, text, id=None, metadata=None, charset="utf-8",
451
+ user=None, collection=None,
452
+ ):
453
+
454
+ if id is None:
455
+
456
+ if metadata is not None:
457
+
458
+ # Situation makes no sense. What can the metadata possibly
459
+ # mean if the caller doesn't know the document ID.
460
+ # Metadata should relate to the document by ID
461
+ raise RuntimeError("Can't specify metadata without id")
462
+
463
+ id = hash(text)
464
+
465
+ triples = []
466
+
467
+ if metadata:
468
+ metadata.emit(
469
+ lambda t: triples.append({
470
+ "s": { "v": t["s"], "e": isinstance(t["s"], Uri) },
471
+ "p": { "v": t["p"], "e": isinstance(t["p"], Uri) },
472
+ "o": { "v": t["o"], "e": isinstance(t["o"], Uri) }
473
+ })
474
+ )
475
+
476
+ input = {
477
+ "id": id,
478
+ "metadata": triples,
479
+ "charset": charset,
480
+ "text": base64.b64encode(text).decode("utf-8"),
481
+ }
482
+
483
+ if user:
484
+ input["user"] = user
485
+
486
+ if collection:
487
+ input["collection"] = collection
488
+
489
+ return self.api.request(
490
+ f"flow/{self.flow}/service/text-load",
491
+ input
492
+ )
493
+
@@ -15,17 +15,22 @@ class Publisher:
15
15
  self.q = asyncio.Queue(maxsize=max_size)
16
16
  self.chunking_enabled = chunking_enabled
17
17
  self.running = True
18
+ self.task = None
18
19
 
19
20
  async def start(self):
20
21
  self.task = asyncio.create_task(self.run())
21
22
 
22
23
  async def stop(self):
23
24
  self.running = False
24
- await self.task
25
+
26
+ if self.task:
27
+ await self.task
25
28
 
26
29
  async def join(self):
27
30
  await self.stop()
28
- await self.task
31
+
32
+ if self.task:
33
+ await self.task
29
34
 
30
35
  async def run(self):
31
36
 
@@ -19,6 +19,7 @@ class Subscriber:
19
19
  self.lock = asyncio.Lock()
20
20
  self.running = True
21
21
  self.metrics = metrics
22
+ self.task = None
22
23
 
23
24
  def __del__(self):
24
25
  self.running = False
@@ -28,11 +29,15 @@ class Subscriber:
28
29
 
29
30
  async def stop(self):
30
31
  self.running = False
31
- await self.task
32
+
33
+ if self.task:
34
+ await self.task
32
35
 
33
36
  async def join(self):
34
37
  await self.stop()
35
- await self.task
38
+
39
+ if self.task:
40
+ await self.task
36
41
 
37
42
  async def run(self):
38
43
 
@@ -45,6 +50,8 @@ class Subscriber:
45
50
 
46
51
  try:
47
52
 
53
+ # FIXME: Create consumer in start method so we know
54
+ # it is definitely running when start completes
48
55
  consumer = self.client.subscribe(
49
56
  topic = self.topic,
50
57
  subscription_name = self.subscription,
@@ -0,0 +1 @@
1
+ __version__ = "0.23.6"
@@ -1,7 +1,6 @@
1
1
 
2
2
  from pulsar.schema import JsonSchema
3
3
  from .. schema import EmbeddingsRequest, EmbeddingsResponse
4
- from .. schema import embeddings_request_queue, embeddings_response_queue
5
4
  from . base import BaseClient
6
5
 
7
6
  import _pulsar
@@ -23,12 +22,6 @@ class EmbeddingsClient(BaseClient):
23
22
  pulsar_api_key=None,
24
23
  ):
25
24
 
26
- if input_queue == None:
27
- input_queue=embeddings_request_queue
28
-
29
- if output_queue == None:
30
- output_queue=embeddings_response_queue
31
-
32
25
  super(EmbeddingsClient, self).__init__(
33
26
  log_level=log_level,
34
27
  subscriber=subscriber,
@@ -43,4 +36,3 @@ class EmbeddingsClient(BaseClient):
43
36
  def request(self, text, timeout=300):
44
37
  return self.call(text=text, timeout=timeout).vectors
45
38
 
46
-
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trustgraph-base
3
- Version: 0.23.4
3
+ Version: 0.23.6
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.23.4.tar.gz
6
+ Download-URL: https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v0.23.6.tar.gz
7
7
  Author: trustgraph.ai
8
8
  Author-email: security@trustgraph.ai
9
9
  Classifier: Programming Language :: Python :: 3