trustgraph-cli 1.6.5__tar.gz → 1.7.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.

Potentially problematic release.


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

Files changed (84) hide show
  1. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/PKG-INFO +2 -2
  2. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/pyproject.toml +2 -1
  3. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/delete_config_item.py +10 -2
  4. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/get_config_item.py +10 -2
  5. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/get_kg_core.py +12 -1
  6. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/invoke_agent.py +74 -104
  7. trustgraph_cli-1.7.4/trustgraph/cli/invoke_document_rag.py +128 -0
  8. trustgraph_cli-1.7.4/trustgraph/cli/invoke_graph_rag.py +164 -0
  9. trustgraph_cli-1.7.4/trustgraph/cli/invoke_llm.py +103 -0
  10. trustgraph_cli-1.7.4/trustgraph/cli/invoke_prompt.py +123 -0
  11. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/list_config_items.py +10 -2
  12. trustgraph_cli-1.7.4/trustgraph/cli/load_knowledge.py +213 -0
  13. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/load_sample_documents.py +10 -2
  14. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/load_structured_data.py +36 -63
  15. trustgraph_cli-1.7.4/trustgraph/cli/load_turtle.py +166 -0
  16. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/put_config_item.py +10 -2
  17. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/put_flow_class.py +10 -2
  18. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/put_kg_core.py +12 -1
  19. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/remove_library_document.py +10 -3
  20. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/set_collection.py +11 -3
  21. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/set_mcp_tool.py +11 -2
  22. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/set_prompt.py +14 -7
  23. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/set_token_costs.py +9 -2
  24. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/set_tool.py +10 -1
  25. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_config.py +10 -2
  26. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_flow_classes.py +10 -2
  27. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_flow_state.py +10 -3
  28. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_flows.py +10 -2
  29. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_graph.py +10 -2
  30. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_kg_cores.py +12 -3
  31. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_library_documents.py +12 -3
  32. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_library_processing.py +10 -3
  33. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_mcp_tools.py +10 -2
  34. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_parameter_types.py +13 -6
  35. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_prompts.py +10 -2
  36. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_token_costs.py +10 -2
  37. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_tools.py +10 -2
  38. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/start_flow.py +10 -2
  39. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/start_library_processing.py +11 -3
  40. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/stop_flow.py +10 -2
  41. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/stop_library_processing.py +10 -2
  42. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/unload_kg_core.py +10 -2
  43. trustgraph_cli-1.7.4/trustgraph/cli/verify_system_status.py +492 -0
  44. trustgraph_cli-1.7.4/trustgraph/cli_version.py +1 -0
  45. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph_cli.egg-info/PKG-INFO +2 -2
  46. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph_cli.egg-info/SOURCES.txt +1 -0
  47. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph_cli.egg-info/entry_points.txt +1 -0
  48. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph_cli.egg-info/requires.txt +1 -1
  49. trustgraph_cli-1.6.5/trustgraph/cli/invoke_document_rag.py +0 -170
  50. trustgraph_cli-1.6.5/trustgraph/cli/invoke_graph_rag.py +0 -208
  51. trustgraph_cli-1.6.5/trustgraph/cli/invoke_llm.py +0 -121
  52. trustgraph_cli-1.6.5/trustgraph/cli/invoke_prompt.py +0 -151
  53. trustgraph_cli-1.6.5/trustgraph/cli/load_knowledge.py +0 -202
  54. trustgraph_cli-1.6.5/trustgraph/cli/load_turtle.py +0 -159
  55. trustgraph_cli-1.6.5/trustgraph/cli_version.py +0 -1
  56. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/README.md +0 -0
  57. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/setup.cfg +0 -0
  58. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/__init__.py +0 -0
  59. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/add_library_document.py +0 -0
  60. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/delete_collection.py +0 -0
  61. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/delete_flow_class.py +0 -0
  62. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/delete_kg_core.py +0 -0
  63. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/delete_mcp_tool.py +0 -0
  64. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/delete_tool.py +0 -0
  65. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/dump_msgpack.py +0 -0
  66. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/dump_queues.py +0 -0
  67. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/get_flow_class.py +0 -0
  68. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/graph_to_turtle.py +0 -0
  69. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/init_pulsar_manager.py +0 -0
  70. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/init_trustgraph.py +0 -0
  71. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/invoke_mcp_tool.py +0 -0
  72. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/invoke_nlp_query.py +0 -0
  73. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/invoke_objects_query.py +0 -0
  74. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/invoke_structured_query.py +0 -0
  75. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/list_collections.py +0 -0
  76. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/load_doc_embeds.py +0 -0
  77. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/load_kg_core.py +0 -0
  78. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/load_pdf.py +0 -0
  79. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/load_text.py +0 -0
  80. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/save_doc_embeds.py +0 -0
  81. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_processor_state.py +0 -0
  82. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph/cli/show_token_rate.py +0 -0
  83. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/trustgraph_cli.egg-info/dependency_links.txt +0 -0
  84. {trustgraph_cli-1.6.5 → trustgraph_cli-1.7.4}/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.6.5
3
+ Version: 1.7.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
5
  Author-email: "trustgraph.ai" <security@trustgraph.ai>
6
6
  Project-URL: Homepage, https://github.com/trustgraph-ai/trustgraph
@@ -8,7 +8,7 @@ Classifier: Programming Language :: Python :: 3
8
8
  Classifier: Operating System :: OS Independent
9
9
  Requires-Python: >=3.8
10
10
  Description-Content-Type: text/markdown
11
- Requires-Dist: trustgraph-base<1.7,>=1.6
11
+ Requires-Dist: trustgraph-base<1.8,>=1.7
12
12
  Requires-Dist: requests
13
13
  Requires-Dist: pulsar-client
14
14
  Requires-Dist: aiohttp
@@ -10,7 +10,7 @@ description = "TrustGraph provides a means to run a pipeline of flexible AI proc
10
10
  readme = "README.md"
11
11
  requires-python = ">=3.8"
12
12
  dependencies = [
13
- "trustgraph-base>=1.6,<1.7",
13
+ "trustgraph-base>=1.7,<1.8",
14
14
  "requests",
15
15
  "pulsar-client",
16
16
  "aiohttp",
@@ -84,6 +84,7 @@ tg-unload-kg-core = "trustgraph.cli.unload_kg_core:main"
84
84
  tg-start-library-processing = "trustgraph.cli.start_library_processing:main"
85
85
  tg-stop-flow = "trustgraph.cli.stop_flow:main"
86
86
  tg-stop-library-processing = "trustgraph.cli.stop_library_processing:main"
87
+ tg-verify-system-status = "trustgraph.cli.verify_system_status:main"
87
88
  tg-list-config-items = "trustgraph.cli.list_config_items:main"
88
89
  tg-get-config-item = "trustgraph.cli.get_config_item:main"
89
90
  tg-put-config-item = "trustgraph.cli.put_config_item:main"
@@ -8,10 +8,11 @@ from trustgraph.api import Api
8
8
  from trustgraph.api.types import ConfigKey
9
9
 
10
10
  default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
11
+ default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
11
12
 
12
- def delete_config_item(url, config_type, key):
13
+ def delete_config_item(url, config_type, key, token=None):
13
14
 
14
- api = Api(url).config()
15
+ api = Api(url, token=token).config()
15
16
 
16
17
  config_key = ConfigKey(type=config_type, key=key)
17
18
  api.delete([config_key])
@@ -43,6 +44,12 @@ def main():
43
44
  help=f'API URL (default: {default_url})',
44
45
  )
45
46
 
47
+ parser.add_argument(
48
+ '-t', '--token',
49
+ default=default_token,
50
+ help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
51
+ )
52
+
46
53
  args = parser.parse_args()
47
54
 
48
55
  try:
@@ -51,6 +58,7 @@ def main():
51
58
  url=args.api_url,
52
59
  config_type=args.type,
53
60
  key=args.key,
61
+ token=args.token,
54
62
  )
55
63
 
56
64
  except Exception as e:
@@ -9,10 +9,11 @@ from trustgraph.api import Api
9
9
  from trustgraph.api.types import ConfigKey
10
10
 
11
11
  default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
12
+ default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
12
13
 
13
- def get_config_item(url, config_type, key, format_type):
14
+ def get_config_item(url, config_type, key, format_type, token=None):
14
15
 
15
- api = Api(url).config()
16
+ api = Api(url, token=token).config()
16
17
 
17
18
  config_key = ConfigKey(type=config_type, key=key)
18
19
  values = api.get([config_key])
@@ -59,6 +60,12 @@ def main():
59
60
  help=f'API URL (default: {default_url})',
60
61
  )
61
62
 
63
+ parser.add_argument(
64
+ '-t', '--token',
65
+ default=default_token,
66
+ help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
67
+ )
68
+
62
69
  args = parser.parse_args()
63
70
 
64
71
  try:
@@ -68,6 +75,7 @@ def main():
68
75
  config_type=args.type,
69
76
  key=args.key,
70
77
  format_type=args.format,
78
+ token=args.token,
71
79
  )
72
80
 
73
81
  except Exception as e:
@@ -14,6 +14,7 @@ import msgpack
14
14
 
15
15
  default_url = os.getenv("TRUSTGRAPH_URL", 'ws://localhost:8088/')
16
16
  default_user = 'trustgraph'
17
+ default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
17
18
 
18
19
  def write_triple(f, data):
19
20
  msg = (
@@ -51,13 +52,16 @@ def write_ge(f, data):
51
52
  )
52
53
  f.write(msgpack.packb(msg, use_bin_type=True))
53
54
 
54
- async def fetch(url, user, id, output):
55
+ async def fetch(url, user, id, output, token=None):
55
56
 
56
57
  if not url.endswith("/"):
57
58
  url += "/"
58
59
 
59
60
  url = url + "api/v1/socket"
60
61
 
62
+ if token:
63
+ url = f"{url}?token={token}"
64
+
61
65
  mid = str(uuid.uuid4())
62
66
 
63
67
  async with connect(url) as ws:
@@ -138,6 +142,12 @@ def main():
138
142
  help=f'Output file'
139
143
  )
140
144
 
145
+ parser.add_argument(
146
+ '-t', '--token',
147
+ default=default_token,
148
+ help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
149
+ )
150
+
141
151
  args = parser.parse_args()
142
152
 
143
153
  try:
@@ -148,6 +158,7 @@ def main():
148
158
  user = args.user,
149
159
  id = args.id,
150
160
  output = args.output,
161
+ token = args.token,
151
162
  )
152
163
  )
153
164
 
@@ -5,12 +5,10 @@ Uses the agent service to answer a question
5
5
  import argparse
6
6
  import os
7
7
  import textwrap
8
- import uuid
9
- import asyncio
10
- import json
11
- from websockets.asyncio.client import connect
8
+ from trustgraph.api import Api
12
9
 
13
- default_url = os.getenv("TRUSTGRAPH_URL", 'ws://localhost:8088/')
10
+ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
11
+ default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
14
12
  default_user = 'trustgraph'
15
13
  default_collection = 'default'
16
14
 
@@ -99,79 +97,47 @@ def output(text, prefix="> ", width=78):
99
97
  )
100
98
  print(out)
101
99
 
102
- async def question(
100
+ def question(
103
101
  url, question, flow_id, user, collection,
104
- plan=None, state=None, group=None, verbose=False, streaming=True
102
+ plan=None, state=None, group=None, verbose=False, streaming=True,
103
+ token=None
105
104
  ):
106
105
 
107
- if not url.endswith("/"):
108
- url += "/"
109
-
110
- url = url + "api/v1/socket"
111
-
112
106
  if verbose:
113
107
  output(wrap(question), "\U00002753 ")
114
108
  print()
115
109
 
116
- # Track last chunk type and current outputter for streaming
117
- last_chunk_type = None
118
- current_outputter = None
119
-
120
- def think(x):
121
- if verbose:
122
- output(wrap(x), "\U0001f914 ")
123
- print()
124
-
125
- def observe(x):
126
- if verbose:
127
- output(wrap(x), "\U0001f4a1 ")
128
- print()
129
-
130
- mid = str(uuid.uuid4())
131
-
132
- async with connect(url) as ws:
133
-
134
- req = {
135
- "id": mid,
136
- "service": "agent",
137
- "flow": flow_id,
138
- "request": {
139
- "question": question,
140
- "user": user,
141
- "history": [],
142
- "streaming": streaming
143
- }
144
- }
145
-
146
- # Only add optional fields if they have values
147
- if state is not None:
148
- req["request"]["state"] = state
149
- if group is not None:
150
- req["request"]["group"] = group
151
-
152
- req = json.dumps(req)
153
-
154
- await ws.send(req)
155
-
156
- while True:
110
+ # Create API client
111
+ api = Api(url=url, token=token)
112
+ socket = api.socket()
113
+ flow = socket.flow(flow_id)
157
114
 
158
- msg = await ws.recv()
115
+ # Prepare request parameters
116
+ request_params = {
117
+ "question": question,
118
+ "user": user,
119
+ "streaming": streaming,
120
+ }
159
121
 
160
- obj = json.loads(msg)
122
+ # Only add optional fields if they have values
123
+ if state is not None:
124
+ request_params["state"] = state
125
+ if group is not None:
126
+ request_params["group"] = group
161
127
 
162
- if "error" in obj:
163
- raise RuntimeError(obj["error"])
164
-
165
- if obj["id"] != mid:
166
- print("Ignore message")
167
- continue
128
+ try:
129
+ # Call agent
130
+ response = flow.agent(**request_params)
168
131
 
169
- response = obj["response"]
132
+ # Handle streaming response
133
+ if streaming:
134
+ # Track last chunk type and current outputter for streaming
135
+ last_chunk_type = None
136
+ current_outputter = None
170
137
 
171
- # Handle streaming format (new format with chunk_type)
172
- if "chunk_type" in response:
173
- chunk_type = response["chunk_type"]
174
- content = response.get("content", "")
138
+ for chunk in response:
139
+ chunk_type = chunk.chunk_type
140
+ content = chunk.content
175
141
 
176
142
  # Check if we're switching to a new message type
177
143
  if last_chunk_type != chunk_type:
@@ -195,33 +161,32 @@ async def question(
195
161
  # Output the chunk
196
162
  if current_outputter:
197
163
  current_outputter.output(content)
198
- elif chunk_type == "answer":
164
+ # Flush word buffer after each chunk to avoid delay
165
+ if current_outputter.word_buffer:
166
+ print(current_outputter.word_buffer, end="", flush=True)
167
+ current_outputter.column += len(current_outputter.word_buffer)
168
+ current_outputter.word_buffer = ""
169
+ elif chunk_type == "final-answer":
199
170
  print(content, end="", flush=True)
200
- else:
201
- # Handle legacy format (backward compatibility)
202
- if "thought" in response:
203
- think(response["thought"])
204
171
 
205
- if "observation" in response:
206
- observe(response["observation"])
207
-
208
- if "answer" in response:
209
- print(response["answer"])
210
-
211
- if "error" in response:
212
- raise RuntimeError(response["error"])
213
-
214
- if obj["complete"]:
215
- # Close any remaining outputter
216
- if current_outputter:
217
- current_outputter.__exit__(None, None, None)
218
- current_outputter = None
219
- # Add final newline if we were outputting answer
220
- elif last_chunk_type == "answer":
221
- print()
222
- break
223
-
224
- await ws.close()
172
+ # Close any remaining outputter
173
+ if current_outputter:
174
+ current_outputter.__exit__(None, None, None)
175
+ current_outputter = None
176
+ # Add final newline if we were outputting answer
177
+ elif last_chunk_type == "final-answer":
178
+ print()
179
+
180
+ else:
181
+ # Non-streaming response
182
+ if "answer" in response:
183
+ print(response["answer"])
184
+ if "error" in response:
185
+ raise RuntimeError(response["error"])
186
+
187
+ finally:
188
+ # Clean up socket connection
189
+ socket.close()
225
190
 
226
191
  def main():
227
192
 
@@ -236,6 +201,12 @@ def main():
236
201
  help=f'API URL (default: {default_url})',
237
202
  )
238
203
 
204
+ parser.add_argument(
205
+ '-t', '--token',
206
+ default=default_token,
207
+ help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
208
+ )
209
+
239
210
  parser.add_argument(
240
211
  '-f', '--flow-id',
241
212
  default="default",
@@ -292,19 +263,18 @@ def main():
292
263
 
293
264
  try:
294
265
 
295
- asyncio.run(
296
- question(
297
- url = args.url,
298
- flow_id = args.flow_id,
299
- question = args.question,
300
- user = args.user,
301
- collection = args.collection,
302
- plan = args.plan,
303
- state = args.state,
304
- group = args.group,
305
- verbose = args.verbose,
306
- streaming = not args.no_streaming,
307
- )
266
+ question(
267
+ url = args.url,
268
+ flow_id = args.flow_id,
269
+ question = args.question,
270
+ user = args.user,
271
+ collection = args.collection,
272
+ plan = args.plan,
273
+ state = args.state,
274
+ group = args.group,
275
+ verbose = args.verbose,
276
+ streaming = not args.no_streaming,
277
+ token = args.token,
308
278
  )
309
279
 
310
280
  except Exception as e:
@@ -0,0 +1,128 @@
1
+ """
2
+ Uses the DocumentRAG service to answer a question
3
+ """
4
+
5
+ import argparse
6
+ import os
7
+ from trustgraph.api import Api
8
+
9
+ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
10
+ default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
11
+ default_user = 'trustgraph'
12
+ default_collection = 'default'
13
+ default_doc_limit = 10
14
+
15
+ def question(url, flow_id, question, user, collection, doc_limit, streaming=True, token=None):
16
+
17
+ # Create API client
18
+ api = Api(url=url, token=token)
19
+
20
+ if streaming:
21
+ # Use socket client for streaming
22
+ socket = api.socket()
23
+ flow = socket.flow(flow_id)
24
+
25
+ try:
26
+ response = flow.document_rag(
27
+ question=question,
28
+ user=user,
29
+ collection=collection,
30
+ doc_limit=doc_limit,
31
+ streaming=True
32
+ )
33
+
34
+ # Stream output
35
+ for chunk in response:
36
+ print(chunk, end="", flush=True)
37
+ print() # Final newline
38
+
39
+ finally:
40
+ socket.close()
41
+ else:
42
+ # Use REST API for non-streaming
43
+ flow = api.flow().id(flow_id)
44
+ resp = flow.document_rag(
45
+ question=question,
46
+ user=user,
47
+ collection=collection,
48
+ doc_limit=doc_limit,
49
+ )
50
+ print(resp)
51
+
52
+ def main():
53
+
54
+ parser = argparse.ArgumentParser(
55
+ prog='tg-invoke-document-rag',
56
+ description=__doc__,
57
+ )
58
+
59
+ parser.add_argument(
60
+ '-u', '--url',
61
+ default=default_url,
62
+ help=f'API URL (default: {default_url})',
63
+ )
64
+
65
+ parser.add_argument(
66
+ '-t', '--token',
67
+ default=default_token,
68
+ help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
69
+ )
70
+
71
+ parser.add_argument(
72
+ '-f', '--flow-id',
73
+ default="default",
74
+ help=f'Flow ID (default: default)'
75
+ )
76
+
77
+ parser.add_argument(
78
+ '-q', '--question',
79
+ required=True,
80
+ help=f'Question to answer',
81
+ )
82
+
83
+ parser.add_argument(
84
+ '-U', '--user',
85
+ default=default_user,
86
+ help=f'User ID (default: {default_user})'
87
+ )
88
+
89
+ parser.add_argument(
90
+ '-C', '--collection',
91
+ default=default_collection,
92
+ help=f'Collection ID (default: {default_collection})'
93
+ )
94
+
95
+ parser.add_argument(
96
+ '-d', '--doc-limit',
97
+ type=int,
98
+ default=default_doc_limit,
99
+ help=f'Document limit (default: {default_doc_limit})'
100
+ )
101
+
102
+ parser.add_argument(
103
+ '--no-streaming',
104
+ action='store_true',
105
+ help='Disable streaming (use non-streaming mode)'
106
+ )
107
+
108
+ args = parser.parse_args()
109
+
110
+ try:
111
+
112
+ question(
113
+ url=args.url,
114
+ flow_id=args.flow_id,
115
+ question=args.question,
116
+ user=args.user,
117
+ collection=args.collection,
118
+ doc_limit=args.doc_limit,
119
+ streaming=not args.no_streaming,
120
+ token=args.token,
121
+ )
122
+
123
+ except Exception as e:
124
+
125
+ print("Exception:", e, flush=True)
126
+
127
+ if __name__ == "__main__":
128
+ main()
@@ -0,0 +1,164 @@
1
+ """
2
+ Uses the GraphRAG service to answer a question
3
+ """
4
+
5
+ import argparse
6
+ import os
7
+ from trustgraph.api import Api
8
+
9
+ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
10
+ default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
11
+ default_user = 'trustgraph'
12
+ default_collection = 'default'
13
+ default_entity_limit = 50
14
+ default_triple_limit = 30
15
+ default_max_subgraph_size = 150
16
+ default_max_path_length = 2
17
+
18
+ def question(
19
+ url, flow_id, question, user, collection, entity_limit, triple_limit,
20
+ max_subgraph_size, max_path_length, streaming=True, token=None
21
+ ):
22
+
23
+ # Create API client
24
+ api = Api(url=url, token=token)
25
+
26
+ if streaming:
27
+ # Use socket client for streaming
28
+ socket = api.socket()
29
+ flow = socket.flow(flow_id)
30
+
31
+ try:
32
+ response = flow.graph_rag(
33
+ question=question,
34
+ user=user,
35
+ collection=collection,
36
+ entity_limit=entity_limit,
37
+ triple_limit=triple_limit,
38
+ max_subgraph_size=max_subgraph_size,
39
+ max_path_length=max_path_length,
40
+ streaming=True
41
+ )
42
+
43
+ # Stream output
44
+ for chunk in response:
45
+ print(chunk, end="", flush=True)
46
+ print() # Final newline
47
+
48
+ finally:
49
+ socket.close()
50
+ else:
51
+ # Use REST API for non-streaming
52
+ flow = api.flow().id(flow_id)
53
+ resp = flow.graph_rag(
54
+ question=question,
55
+ user=user,
56
+ collection=collection,
57
+ entity_limit=entity_limit,
58
+ triple_limit=triple_limit,
59
+ max_subgraph_size=max_subgraph_size,
60
+ max_path_length=max_path_length
61
+ )
62
+ print(resp)
63
+
64
+ def main():
65
+
66
+ parser = argparse.ArgumentParser(
67
+ prog='tg-invoke-graph-rag',
68
+ description=__doc__,
69
+ )
70
+
71
+ parser.add_argument(
72
+ '-u', '--url',
73
+ default=default_url,
74
+ help=f'API URL (default: {default_url})',
75
+ )
76
+
77
+ parser.add_argument(
78
+ '-t', '--token',
79
+ default=default_token,
80
+ help='Authentication token (default: $TRUSTGRAPH_TOKEN)',
81
+ )
82
+
83
+ parser.add_argument(
84
+ '-f', '--flow-id',
85
+ default="default",
86
+ help=f'Flow ID (default: default)'
87
+ )
88
+
89
+ parser.add_argument(
90
+ '-q', '--question',
91
+ required=True,
92
+ help=f'Question to answer',
93
+ )
94
+
95
+ parser.add_argument(
96
+ '-U', '--user',
97
+ default=default_user,
98
+ help=f'User ID (default: {default_user})'
99
+ )
100
+
101
+ parser.add_argument(
102
+ '-C', '--collection',
103
+ default=default_collection,
104
+ help=f'Collection ID (default: {default_collection})'
105
+ )
106
+
107
+ parser.add_argument(
108
+ '-e', '--entity-limit',
109
+ type=int,
110
+ default=default_entity_limit,
111
+ help=f'Entity limit (default: {default_entity_limit})'
112
+ )
113
+
114
+ parser.add_argument(
115
+ '--triple-limit',
116
+ type=int,
117
+ default=default_triple_limit,
118
+ help=f'Triple limit (default: {default_triple_limit})'
119
+ )
120
+
121
+ parser.add_argument(
122
+ '-s', '--max-subgraph-size',
123
+ type=int,
124
+ default=default_max_subgraph_size,
125
+ help=f'Max subgraph size (default: {default_max_subgraph_size})'
126
+ )
127
+
128
+ parser.add_argument(
129
+ '-p', '--max-path-length',
130
+ type=int,
131
+ default=default_max_path_length,
132
+ help=f'Max path length (default: {default_max_path_length})'
133
+ )
134
+
135
+ parser.add_argument(
136
+ '--no-streaming',
137
+ action='store_true',
138
+ help='Disable streaming (use non-streaming mode)'
139
+ )
140
+
141
+ args = parser.parse_args()
142
+
143
+ try:
144
+
145
+ question(
146
+ url=args.url,
147
+ flow_id=args.flow_id,
148
+ question=args.question,
149
+ user=args.user,
150
+ collection=args.collection,
151
+ entity_limit=args.entity_limit,
152
+ triple_limit=args.triple_limit,
153
+ max_subgraph_size=args.max_subgraph_size,
154
+ max_path_length=args.max_path_length,
155
+ streaming=not args.no_streaming,
156
+ token=args.token,
157
+ )
158
+
159
+ except Exception as e:
160
+
161
+ print("Exception:", e, flush=True)
162
+
163
+ if __name__ == "__main__":
164
+ main()