trustgraph-cli 1.2.10__tar.gz → 1.2.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.

Potentially problematic release.


This version of trustgraph-cli might be problematic. Click here for more details.

Files changed (64) hide show
  1. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/PKG-INFO +1 -1
  2. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/pyproject.toml +1 -0
  3. trustgraph_cli-1.2.12/trustgraph/cli/load_knowledge.py +202 -0
  4. trustgraph_cli-1.2.12/trustgraph/cli_version.py +1 -0
  5. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph_cli.egg-info/PKG-INFO +1 -1
  6. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph_cli.egg-info/SOURCES.txt +1 -0
  7. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph_cli.egg-info/entry_points.txt +1 -0
  8. trustgraph_cli-1.2.10/trustgraph/cli_version.py +0 -1
  9. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/README.md +0 -0
  10. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/setup.cfg +0 -0
  11. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/__init__.py +0 -0
  12. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/add_library_document.py +0 -0
  13. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/delete_flow_class.py +0 -0
  14. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/delete_kg_core.py +0 -0
  15. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/delete_mcp_tool.py +0 -0
  16. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/delete_tool.py +0 -0
  17. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/dump_msgpack.py +0 -0
  18. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/get_flow_class.py +0 -0
  19. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/get_kg_core.py +0 -0
  20. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/graph_to_turtle.py +0 -0
  21. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/init_pulsar_manager.py +0 -0
  22. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/init_trustgraph.py +0 -0
  23. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/invoke_agent.py +0 -0
  24. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/invoke_document_rag.py +0 -0
  25. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/invoke_graph_rag.py +0 -0
  26. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/invoke_llm.py +0 -0
  27. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/invoke_mcp_tool.py +0 -0
  28. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/invoke_prompt.py +0 -0
  29. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/load_doc_embeds.py +0 -0
  30. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/load_kg_core.py +0 -0
  31. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/load_pdf.py +0 -0
  32. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/load_sample_documents.py +0 -0
  33. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/load_text.py +0 -0
  34. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/load_turtle.py +0 -0
  35. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/put_flow_class.py +0 -0
  36. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/put_kg_core.py +0 -0
  37. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/remove_library_document.py +0 -0
  38. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/save_doc_embeds.py +0 -0
  39. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/set_mcp_tool.py +0 -0
  40. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/set_prompt.py +0 -0
  41. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/set_token_costs.py +0 -0
  42. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/set_tool.py +0 -0
  43. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_config.py +0 -0
  44. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_flow_classes.py +0 -0
  45. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_flow_state.py +0 -0
  46. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_flows.py +0 -0
  47. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_graph.py +0 -0
  48. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_kg_cores.py +0 -0
  49. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_library_documents.py +0 -0
  50. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_library_processing.py +0 -0
  51. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_mcp_tools.py +0 -0
  52. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_processor_state.py +0 -0
  53. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_prompts.py +0 -0
  54. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_token_costs.py +0 -0
  55. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_token_rate.py +0 -0
  56. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/show_tools.py +0 -0
  57. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/start_flow.py +0 -0
  58. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/start_library_processing.py +0 -0
  59. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/stop_flow.py +0 -0
  60. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/stop_library_processing.py +0 -0
  61. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph/cli/unload_kg_core.py +0 -0
  62. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph_cli.egg-info/dependency_links.txt +0 -0
  63. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph_cli.egg-info/requires.txt +0 -0
  64. {trustgraph_cli-1.2.10 → trustgraph_cli-1.2.12}/trustgraph_cli.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trustgraph-cli
3
- Version: 1.2.10
3
+ Version: 1.2.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
  Author-email: "trustgraph.ai" <security@trustgraph.ai>
6
6
  Project-URL: Homepage, https://github.com/trustgraph-ai/trustgraph
@@ -50,6 +50,7 @@ tg-load-pdf = "trustgraph.cli.load_pdf:main"
50
50
  tg-load-sample-documents = "trustgraph.cli.load_sample_documents:main"
51
51
  tg-load-text = "trustgraph.cli.load_text:main"
52
52
  tg-load-turtle = "trustgraph.cli.load_turtle:main"
53
+ tg-load-knowledge = "trustgraph.cli.load_knowledge:main"
53
54
  tg-put-flow-class = "trustgraph.cli.put_flow_class:main"
54
55
  tg-put-kg-core = "trustgraph.cli.put_kg_core:main"
55
56
  tg-remove-library-document = "trustgraph.cli.remove_library_document:main"
@@ -0,0 +1,202 @@
1
+ """
2
+ Loads triples and entity contexts into the knowledge graph.
3
+ """
4
+
5
+ import asyncio
6
+ import argparse
7
+ import os
8
+ import time
9
+ import rdflib
10
+ import json
11
+ from websockets.asyncio.client import connect
12
+ from typing import List, Dict, Any
13
+
14
+ from trustgraph.log_level import LogLevel
15
+
16
+ default_url = os.getenv("TRUSTGRAPH_URL", 'ws://localhost:8088/')
17
+ default_user = 'trustgraph'
18
+ default_collection = 'default'
19
+
20
+ class KnowledgeLoader:
21
+
22
+ def __init__(
23
+ self,
24
+ files,
25
+ flow,
26
+ user,
27
+ collection,
28
+ document_id,
29
+ url = default_url,
30
+ ):
31
+
32
+ if not url.endswith("/"):
33
+ url += "/"
34
+
35
+ self.triples_url = url + f"api/v1/flow/{flow}/import/triples"
36
+ self.entity_contexts_url = url + f"api/v1/flow/{flow}/import/entity-contexts"
37
+
38
+ self.files = files
39
+ self.user = user
40
+ self.collection = collection
41
+ self.document_id = document_id
42
+
43
+ async def run(self):
44
+
45
+ try:
46
+ # Load triples first
47
+ async with connect(self.triples_url) as ws:
48
+ for file in self.files:
49
+ await self.load_triples(file, ws)
50
+
51
+ # Then load entity contexts
52
+ async with connect(self.entity_contexts_url) as ws:
53
+ for file in self.files:
54
+ await self.load_entity_contexts(file, ws)
55
+
56
+ except Exception as e:
57
+ print(e, flush=True)
58
+
59
+ async def load_triples(self, file, ws):
60
+
61
+ g = rdflib.Graph()
62
+ g.parse(file, format="turtle")
63
+
64
+ def Value(value, is_uri):
65
+ return { "v": value, "e": is_uri }
66
+
67
+ for e in g:
68
+ s = Value(value=str(e[0]), is_uri=True)
69
+ p = Value(value=str(e[1]), is_uri=True)
70
+ if type(e[2]) == rdflib.term.URIRef:
71
+ o = Value(value=str(e[2]), is_uri=True)
72
+ else:
73
+ o = Value(value=str(e[2]), is_uri=False)
74
+
75
+ req = {
76
+ "metadata": {
77
+ "id": self.document_id,
78
+ "metadata": [],
79
+ "user": self.user,
80
+ "collection": self.collection
81
+ },
82
+ "triples": [
83
+ {
84
+ "s": s,
85
+ "p": p,
86
+ "o": o,
87
+ }
88
+ ]
89
+ }
90
+
91
+ await ws.send(json.dumps(req))
92
+
93
+ async def load_entity_contexts(self, file, ws):
94
+ """
95
+ Load entity contexts by extracting entities from the RDF graph
96
+ and generating contextual descriptions based on their relationships.
97
+ """
98
+
99
+ g = rdflib.Graph()
100
+ g.parse(file, format="turtle")
101
+
102
+ for s, p, o in g:
103
+ # If object is a URI, do nothing
104
+ if isinstance(o, rdflib.term.URIRef):
105
+ continue
106
+
107
+ # If object is a literal, create entity context for subject with literal as context
108
+ s_str = str(s)
109
+ o_str = str(o)
110
+
111
+ req = {
112
+ "metadata": {
113
+ "id": self.document_id,
114
+ "metadata": [],
115
+ "user": self.user,
116
+ "collection": self.collection
117
+ },
118
+ "entities": [
119
+ {
120
+ "entity": {
121
+ "v": s_str,
122
+ "e": True
123
+ },
124
+ "context": o_str
125
+ }
126
+ ]
127
+ }
128
+
129
+ await ws.send(json.dumps(req))
130
+
131
+
132
+ def main():
133
+
134
+ parser = argparse.ArgumentParser(
135
+ prog='tg-load-knowledge',
136
+ description=__doc__,
137
+ )
138
+
139
+ parser.add_argument(
140
+ '-u', '--api-url',
141
+ default=default_url,
142
+ help=f'API URL (default: {default_url})',
143
+ )
144
+
145
+ parser.add_argument(
146
+ '-i', '--document-id',
147
+ required=True,
148
+ help=f'Document ID)',
149
+ )
150
+
151
+ parser.add_argument(
152
+ '-f', '--flow-id',
153
+ default="default",
154
+ help=f'Flow ID (default: default)'
155
+ )
156
+
157
+ parser.add_argument(
158
+ '-U', '--user',
159
+ default=default_user,
160
+ help=f'User ID (default: {default_user})'
161
+ )
162
+
163
+ parser.add_argument(
164
+ '-C', '--collection',
165
+ default=default_collection,
166
+ help=f'Collection ID (default: {default_collection})'
167
+ )
168
+
169
+
170
+ parser.add_argument(
171
+ 'files', nargs='+',
172
+ help=f'Turtle files to load'
173
+ )
174
+
175
+ args = parser.parse_args()
176
+
177
+ while True:
178
+
179
+ try:
180
+ loader = KnowledgeLoader(
181
+ document_id = args.document_id,
182
+ url = args.api_url,
183
+ flow = args.flow_id,
184
+ files = args.files,
185
+ user = args.user,
186
+ collection = args.collection,
187
+ )
188
+
189
+ asyncio.run(loader.run())
190
+
191
+ print("Triples and entity contexts loaded.")
192
+ break
193
+
194
+ except Exception as e:
195
+
196
+ print("Exception:", e, flush=True)
197
+ print("Will retry...", flush=True)
198
+
199
+ time.sleep(10)
200
+
201
+ if __name__ == "__main__":
202
+ main()
@@ -0,0 +1 @@
1
+ __version__ = "1.2.12"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trustgraph-cli
3
- Version: 1.2.10
3
+ Version: 1.2.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
  Author-email: "trustgraph.ai" <security@trustgraph.ai>
6
6
  Project-URL: Homepage, https://github.com/trustgraph-ai/trustgraph
@@ -21,6 +21,7 @@ trustgraph/cli/invoke_mcp_tool.py
21
21
  trustgraph/cli/invoke_prompt.py
22
22
  trustgraph/cli/load_doc_embeds.py
23
23
  trustgraph/cli/load_kg_core.py
24
+ trustgraph/cli/load_knowledge.py
24
25
  trustgraph/cli/load_pdf.py
25
26
  trustgraph/cli/load_sample_documents.py
26
27
  trustgraph/cli/load_text.py
@@ -17,6 +17,7 @@ tg-invoke-mcp-tool = trustgraph.cli.invoke_mcp_tool:main
17
17
  tg-invoke-prompt = trustgraph.cli.invoke_prompt:main
18
18
  tg-load-doc-embeds = trustgraph.cli.load_doc_embeds:main
19
19
  tg-load-kg-core = trustgraph.cli.load_kg_core:main
20
+ tg-load-knowledge = trustgraph.cli.load_knowledge:main
20
21
  tg-load-pdf = trustgraph.cli.load_pdf:main
21
22
  tg-load-sample-documents = trustgraph.cli.load_sample_documents:main
22
23
  tg-load-text = trustgraph.cli.load_text:main
@@ -1 +0,0 @@
1
- __version__ = "1.2.10"