trustgraph-cli 2.2.26__tar.gz → 2.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/PKG-INFO +2 -2
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/pyproject.toml +1 -1
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_agent.py +38 -20
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_document_rag.py +30 -4
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_graph_rag.py +29 -4
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_llm.py +29 -6
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_prompt.py +29 -7
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_sparql_query.py +5 -0
- trustgraph_cli-2.3.1/trustgraph/cli_version.py +1 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph_cli.egg-info/PKG-INFO +2 -2
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph_cli.egg-info/requires.txt +1 -1
- trustgraph_cli-2.2.26/trustgraph/cli_version.py +0 -1
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/README.md +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/setup.cfg +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/__init__.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/add_library_document.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/delete_collection.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/delete_config_item.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/delete_flow_blueprint.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/delete_kg_core.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/delete_mcp_tool.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/delete_tool.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/dump_msgpack.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/dump_queues.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/get_config_item.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/get_document_content.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/get_flow_blueprint.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/get_kg_core.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/graph_to_turtle.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/init_pulsar_manager.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/init_trustgraph.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_document_embeddings.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_embeddings.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_graph_embeddings.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_mcp_tool.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_nlp_query.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_row_embeddings.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_rows_query.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/invoke_structured_query.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/list_collections.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/list_config_items.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/list_explain_traces.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/load_doc_embeds.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/load_kg_core.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/load_knowledge.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/load_sample_documents.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/load_structured_data.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/load_turtle.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/monitor_prompts.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/put_config_item.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/put_flow_blueprint.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/put_kg_core.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/query_graph.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/remove_library_document.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/save_doc_embeds.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/set_collection.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/set_mcp_tool.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/set_prompt.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/set_token_costs.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/set_tool.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_config.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_explain_trace.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_extraction_provenance.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_flow_blueprints.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_flow_state.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_flows.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_graph.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_kg_cores.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_library_documents.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_library_processing.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_mcp_tools.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_parameter_types.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_processor_state.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_prompts.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_token_costs.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_token_rate.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/show_tools.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/start_flow.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/start_library_processing.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/stop_flow.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/stop_library_processing.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/unload_kg_core.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph/cli/verify_system_status.py +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph_cli.egg-info/SOURCES.txt +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph_cli.egg-info/dependency_links.txt +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/trustgraph_cli.egg-info/entry_points.txt +0 -0
- {trustgraph_cli-2.2.26 → trustgraph_cli-2.3.1}/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: 2.
|
|
3
|
+
Version: 2.3.1
|
|
4
4
|
Summary: TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.
|
|
5
5
|
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<2.
|
|
11
|
+
Requires-Dist: trustgraph-base<2.4,>=2.3
|
|
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>=2.
|
|
13
|
+
"trustgraph-base>=2.3,<2.4",
|
|
14
14
|
"requests",
|
|
15
15
|
"pulsar-client",
|
|
16
16
|
"aiohttp",
|
|
@@ -126,7 +126,7 @@ def question_explainable(
|
|
|
126
126
|
|
|
127
127
|
try:
|
|
128
128
|
# Track last chunk type for formatting
|
|
129
|
-
|
|
129
|
+
last_message_type = None
|
|
130
130
|
current_outputter = None
|
|
131
131
|
|
|
132
132
|
# Stream agent with explainability - process events as they arrive
|
|
@@ -138,7 +138,7 @@ def question_explainable(
|
|
|
138
138
|
group=group,
|
|
139
139
|
):
|
|
140
140
|
if isinstance(item, AgentThought):
|
|
141
|
-
if
|
|
141
|
+
if last_message_type != "thought":
|
|
142
142
|
if current_outputter:
|
|
143
143
|
current_outputter.__exit__(None, None, None)
|
|
144
144
|
current_outputter = None
|
|
@@ -146,7 +146,7 @@ def question_explainable(
|
|
|
146
146
|
if verbose:
|
|
147
147
|
current_outputter = Outputter(width=78, prefix="\U0001f914 ")
|
|
148
148
|
current_outputter.__enter__()
|
|
149
|
-
|
|
149
|
+
last_message_type = "thought"
|
|
150
150
|
if current_outputter:
|
|
151
151
|
current_outputter.output(item.content)
|
|
152
152
|
if current_outputter.word_buffer:
|
|
@@ -155,7 +155,7 @@ def question_explainable(
|
|
|
155
155
|
current_outputter.word_buffer = ""
|
|
156
156
|
|
|
157
157
|
elif isinstance(item, AgentObservation):
|
|
158
|
-
if
|
|
158
|
+
if last_message_type != "observation":
|
|
159
159
|
if current_outputter:
|
|
160
160
|
current_outputter.__exit__(None, None, None)
|
|
161
161
|
current_outputter = None
|
|
@@ -163,7 +163,7 @@ def question_explainable(
|
|
|
163
163
|
if verbose:
|
|
164
164
|
current_outputter = Outputter(width=78, prefix="\U0001f4a1 ")
|
|
165
165
|
current_outputter.__enter__()
|
|
166
|
-
|
|
166
|
+
last_message_type = "observation"
|
|
167
167
|
if current_outputter:
|
|
168
168
|
current_outputter.output(item.content)
|
|
169
169
|
if current_outputter.word_buffer:
|
|
@@ -172,12 +172,12 @@ def question_explainable(
|
|
|
172
172
|
current_outputter.word_buffer = ""
|
|
173
173
|
|
|
174
174
|
elif isinstance(item, AgentAnswer):
|
|
175
|
-
if
|
|
175
|
+
if last_message_type != "answer":
|
|
176
176
|
if current_outputter:
|
|
177
177
|
current_outputter.__exit__(None, None, None)
|
|
178
178
|
current_outputter = None
|
|
179
179
|
print()
|
|
180
|
-
|
|
180
|
+
last_message_type = "answer"
|
|
181
181
|
# Print answer content directly
|
|
182
182
|
print(item.content, end="", flush=True)
|
|
183
183
|
|
|
@@ -261,7 +261,7 @@ def question_explainable(
|
|
|
261
261
|
current_outputter = None
|
|
262
262
|
|
|
263
263
|
# Final newline if we ended with answer
|
|
264
|
-
if
|
|
264
|
+
if last_message_type == "answer":
|
|
265
265
|
print()
|
|
266
266
|
|
|
267
267
|
finally:
|
|
@@ -272,7 +272,8 @@ def question(
|
|
|
272
272
|
url, question, flow_id, user, collection,
|
|
273
273
|
plan=None, state=None, group=None, pattern=None,
|
|
274
274
|
verbose=False, streaming=True,
|
|
275
|
-
token=None, explainable=False, debug=False
|
|
275
|
+
token=None, explainable=False, debug=False,
|
|
276
|
+
show_usage=False
|
|
276
277
|
):
|
|
277
278
|
# Explainable mode uses the API to capture and process provenance events
|
|
278
279
|
if explainable:
|
|
@@ -321,15 +322,16 @@ def question(
|
|
|
321
322
|
# Handle streaming response
|
|
322
323
|
if streaming:
|
|
323
324
|
# Track last chunk type and current outputter for streaming
|
|
324
|
-
|
|
325
|
+
last_message_type = None
|
|
325
326
|
current_outputter = None
|
|
327
|
+
last_answer_chunk = None
|
|
326
328
|
|
|
327
329
|
for chunk in response:
|
|
328
|
-
|
|
330
|
+
message_type = chunk.message_type
|
|
329
331
|
content = chunk.content
|
|
330
332
|
|
|
331
333
|
# Check if we're switching to a new message type
|
|
332
|
-
if
|
|
334
|
+
if last_message_type != message_type:
|
|
333
335
|
# Close previous outputter if exists
|
|
334
336
|
if current_outputter:
|
|
335
337
|
current_outputter.__exit__(None, None, None)
|
|
@@ -337,15 +339,15 @@ def question(
|
|
|
337
339
|
print() # Blank line between message types
|
|
338
340
|
|
|
339
341
|
# Create new outputter for new message type
|
|
340
|
-
if
|
|
342
|
+
if message_type == "thought" and verbose:
|
|
341
343
|
current_outputter = Outputter(width=78, prefix="\U0001f914 ")
|
|
342
344
|
current_outputter.__enter__()
|
|
343
|
-
elif
|
|
345
|
+
elif message_type == "observation" and verbose:
|
|
344
346
|
current_outputter = Outputter(width=78, prefix="\U0001f4a1 ")
|
|
345
347
|
current_outputter.__enter__()
|
|
346
348
|
# For answer, don't use Outputter - just print as-is
|
|
347
349
|
|
|
348
|
-
|
|
350
|
+
last_message_type = message_type
|
|
349
351
|
|
|
350
352
|
# Output the chunk
|
|
351
353
|
if current_outputter:
|
|
@@ -355,33 +357,42 @@ def question(
|
|
|
355
357
|
print(current_outputter.word_buffer, end="", flush=True)
|
|
356
358
|
current_outputter.column += len(current_outputter.word_buffer)
|
|
357
359
|
current_outputter.word_buffer = ""
|
|
358
|
-
elif
|
|
360
|
+
elif message_type == "final-answer":
|
|
359
361
|
print(content, end="", flush=True)
|
|
362
|
+
last_answer_chunk = chunk
|
|
360
363
|
|
|
361
364
|
# Close any remaining outputter
|
|
362
365
|
if current_outputter:
|
|
363
366
|
current_outputter.__exit__(None, None, None)
|
|
364
367
|
current_outputter = None
|
|
365
368
|
# Add final newline if we were outputting answer
|
|
366
|
-
elif
|
|
369
|
+
elif last_message_type == "final-answer":
|
|
367
370
|
print()
|
|
368
371
|
|
|
372
|
+
if show_usage and last_answer_chunk:
|
|
373
|
+
print(
|
|
374
|
+
f"Input tokens: {last_answer_chunk.in_token} "
|
|
375
|
+
f"Output tokens: {last_answer_chunk.out_token} "
|
|
376
|
+
f"Model: {last_answer_chunk.model}",
|
|
377
|
+
file=sys.stderr,
|
|
378
|
+
)
|
|
379
|
+
|
|
369
380
|
else:
|
|
370
381
|
# Non-streaming response - but agents use multipart messaging
|
|
371
382
|
# so we iterate through the chunks (which are complete messages, not text chunks)
|
|
372
383
|
for chunk in response:
|
|
373
384
|
# Display thoughts if verbose
|
|
374
|
-
if chunk.
|
|
385
|
+
if chunk.message_type == "thought" and verbose:
|
|
375
386
|
output(wrap(chunk.content), "\U0001f914 ")
|
|
376
387
|
print()
|
|
377
388
|
|
|
378
389
|
# Display observations if verbose
|
|
379
|
-
elif chunk.
|
|
390
|
+
elif chunk.message_type == "observation" and verbose:
|
|
380
391
|
output(wrap(chunk.content), "\U0001f4a1 ")
|
|
381
392
|
print()
|
|
382
393
|
|
|
383
394
|
# Display answer
|
|
384
|
-
elif chunk.
|
|
395
|
+
elif chunk.message_type == "final-answer" or chunk.message_type == "answer":
|
|
385
396
|
print(chunk.content)
|
|
386
397
|
|
|
387
398
|
finally:
|
|
@@ -477,6 +488,12 @@ def main():
|
|
|
477
488
|
help='Show debug output for troubleshooting'
|
|
478
489
|
)
|
|
479
490
|
|
|
491
|
+
parser.add_argument(
|
|
492
|
+
'--show-usage',
|
|
493
|
+
action='store_true',
|
|
494
|
+
help='Show token usage and model on stderr'
|
|
495
|
+
)
|
|
496
|
+
|
|
480
497
|
args = parser.parse_args()
|
|
481
498
|
|
|
482
499
|
try:
|
|
@@ -496,6 +513,7 @@ def main():
|
|
|
496
513
|
token = args.token,
|
|
497
514
|
explainable = args.explainable,
|
|
498
515
|
debug = args.debug,
|
|
516
|
+
show_usage = args.show_usage,
|
|
499
517
|
)
|
|
500
518
|
|
|
501
519
|
except Exception as e:
|
|
@@ -99,7 +99,8 @@ def question_explainable(
|
|
|
99
99
|
|
|
100
100
|
def question(
|
|
101
101
|
url, flow_id, question_text, user, collection, doc_limit,
|
|
102
|
-
streaming=True, token=None, explainable=False, debug=False
|
|
102
|
+
streaming=True, token=None, explainable=False, debug=False,
|
|
103
|
+
show_usage=False
|
|
103
104
|
):
|
|
104
105
|
# Explainable mode uses the API to capture and process provenance events
|
|
105
106
|
if explainable:
|
|
@@ -133,22 +134,40 @@ def question(
|
|
|
133
134
|
)
|
|
134
135
|
|
|
135
136
|
# Stream output
|
|
137
|
+
last_chunk = None
|
|
136
138
|
for chunk in response:
|
|
137
|
-
print(chunk, end="", flush=True)
|
|
139
|
+
print(chunk.content, end="", flush=True)
|
|
140
|
+
last_chunk = chunk
|
|
138
141
|
print() # Final newline
|
|
139
142
|
|
|
143
|
+
if show_usage and last_chunk:
|
|
144
|
+
print(
|
|
145
|
+
f"Input tokens: {last_chunk.in_token} "
|
|
146
|
+
f"Output tokens: {last_chunk.out_token} "
|
|
147
|
+
f"Model: {last_chunk.model}",
|
|
148
|
+
file=sys.stderr,
|
|
149
|
+
)
|
|
150
|
+
|
|
140
151
|
finally:
|
|
141
152
|
socket.close()
|
|
142
153
|
else:
|
|
143
154
|
# Use REST API for non-streaming
|
|
144
155
|
flow = api.flow().id(flow_id)
|
|
145
|
-
|
|
156
|
+
result = flow.document_rag(
|
|
146
157
|
query=question_text,
|
|
147
158
|
user=user,
|
|
148
159
|
collection=collection,
|
|
149
160
|
doc_limit=doc_limit,
|
|
150
161
|
)
|
|
151
|
-
print(
|
|
162
|
+
print(result.text)
|
|
163
|
+
|
|
164
|
+
if show_usage:
|
|
165
|
+
print(
|
|
166
|
+
f"Input tokens: {result.in_token} "
|
|
167
|
+
f"Output tokens: {result.out_token} "
|
|
168
|
+
f"Model: {result.model}",
|
|
169
|
+
file=sys.stderr,
|
|
170
|
+
)
|
|
152
171
|
|
|
153
172
|
|
|
154
173
|
def main():
|
|
@@ -219,6 +238,12 @@ def main():
|
|
|
219
238
|
help='Show debug output for troubleshooting'
|
|
220
239
|
)
|
|
221
240
|
|
|
241
|
+
parser.add_argument(
|
|
242
|
+
'--show-usage',
|
|
243
|
+
action='store_true',
|
|
244
|
+
help='Show token usage and model on stderr'
|
|
245
|
+
)
|
|
246
|
+
|
|
222
247
|
args = parser.parse_args()
|
|
223
248
|
|
|
224
249
|
try:
|
|
@@ -234,6 +259,7 @@ def main():
|
|
|
234
259
|
token=args.token,
|
|
235
260
|
explainable=args.explainable,
|
|
236
261
|
debug=args.debug,
|
|
262
|
+
show_usage=args.show_usage,
|
|
237
263
|
)
|
|
238
264
|
|
|
239
265
|
except Exception as e:
|
|
@@ -753,7 +753,7 @@ def question(
|
|
|
753
753
|
url, flow_id, question, user, collection, entity_limit, triple_limit,
|
|
754
754
|
max_subgraph_size, max_path_length, edge_score_limit=50,
|
|
755
755
|
edge_limit=25, streaming=True, token=None,
|
|
756
|
-
explainable=False, debug=False
|
|
756
|
+
explainable=False, debug=False, show_usage=False
|
|
757
757
|
):
|
|
758
758
|
|
|
759
759
|
# Explainable mode uses the API to capture and process provenance events
|
|
@@ -798,16 +798,26 @@ def question(
|
|
|
798
798
|
)
|
|
799
799
|
|
|
800
800
|
# Stream output
|
|
801
|
+
last_chunk = None
|
|
801
802
|
for chunk in response:
|
|
802
|
-
print(chunk, end="", flush=True)
|
|
803
|
+
print(chunk.content, end="", flush=True)
|
|
804
|
+
last_chunk = chunk
|
|
803
805
|
print() # Final newline
|
|
804
806
|
|
|
807
|
+
if show_usage and last_chunk:
|
|
808
|
+
print(
|
|
809
|
+
f"Input tokens: {last_chunk.in_token} "
|
|
810
|
+
f"Output tokens: {last_chunk.out_token} "
|
|
811
|
+
f"Model: {last_chunk.model}",
|
|
812
|
+
file=sys.stderr,
|
|
813
|
+
)
|
|
814
|
+
|
|
805
815
|
finally:
|
|
806
816
|
socket.close()
|
|
807
817
|
else:
|
|
808
818
|
# Use REST API for non-streaming
|
|
809
819
|
flow = api.flow().id(flow_id)
|
|
810
|
-
|
|
820
|
+
result = flow.graph_rag(
|
|
811
821
|
query=question,
|
|
812
822
|
user=user,
|
|
813
823
|
collection=collection,
|
|
@@ -818,7 +828,15 @@ def question(
|
|
|
818
828
|
edge_score_limit=edge_score_limit,
|
|
819
829
|
edge_limit=edge_limit,
|
|
820
830
|
)
|
|
821
|
-
print(
|
|
831
|
+
print(result.text)
|
|
832
|
+
|
|
833
|
+
if show_usage:
|
|
834
|
+
print(
|
|
835
|
+
f"Input tokens: {result.in_token} "
|
|
836
|
+
f"Output tokens: {result.out_token} "
|
|
837
|
+
f"Model: {result.model}",
|
|
838
|
+
file=sys.stderr,
|
|
839
|
+
)
|
|
822
840
|
|
|
823
841
|
def main():
|
|
824
842
|
|
|
@@ -923,6 +941,12 @@ def main():
|
|
|
923
941
|
help='Show debug output for troubleshooting'
|
|
924
942
|
)
|
|
925
943
|
|
|
944
|
+
parser.add_argument(
|
|
945
|
+
'--show-usage',
|
|
946
|
+
action='store_true',
|
|
947
|
+
help='Show token usage and model on stderr'
|
|
948
|
+
)
|
|
949
|
+
|
|
926
950
|
args = parser.parse_args()
|
|
927
951
|
|
|
928
952
|
try:
|
|
@@ -943,6 +967,7 @@ def main():
|
|
|
943
967
|
token=args.token,
|
|
944
968
|
explainable=args.explainable,
|
|
945
969
|
debug=args.debug,
|
|
970
|
+
show_usage=args.show_usage,
|
|
946
971
|
)
|
|
947
972
|
|
|
948
973
|
except Exception as e:
|
|
@@ -10,7 +10,8 @@ from trustgraph.api import Api
|
|
|
10
10
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|
11
11
|
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
|
12
12
|
|
|
13
|
-
def query(url, flow_id, system, prompt, streaming=True, token=None
|
|
13
|
+
def query(url, flow_id, system, prompt, streaming=True, token=None,
|
|
14
|
+
show_usage=False):
|
|
14
15
|
|
|
15
16
|
# Create API client
|
|
16
17
|
api = Api(url=url, token=token)
|
|
@@ -26,14 +27,29 @@ def query(url, flow_id, system, prompt, streaming=True, token=None):
|
|
|
26
27
|
)
|
|
27
28
|
|
|
28
29
|
if streaming:
|
|
29
|
-
|
|
30
|
+
last_chunk = None
|
|
30
31
|
for chunk in response:
|
|
31
|
-
print(chunk, end="", flush=True)
|
|
32
|
-
|
|
32
|
+
print(chunk.content, end="", flush=True)
|
|
33
|
+
last_chunk = chunk
|
|
33
34
|
print()
|
|
35
|
+
|
|
36
|
+
if show_usage and last_chunk:
|
|
37
|
+
print(
|
|
38
|
+
f"Input tokens: {last_chunk.in_token} "
|
|
39
|
+
f"Output tokens: {last_chunk.out_token} "
|
|
40
|
+
f"Model: {last_chunk.model}",
|
|
41
|
+
file=__import__('sys').stderr,
|
|
42
|
+
)
|
|
34
43
|
else:
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
print(response.text)
|
|
45
|
+
|
|
46
|
+
if show_usage:
|
|
47
|
+
print(
|
|
48
|
+
f"Input tokens: {response.in_token} "
|
|
49
|
+
f"Output tokens: {response.out_token} "
|
|
50
|
+
f"Model: {response.model}",
|
|
51
|
+
file=__import__('sys').stderr,
|
|
52
|
+
)
|
|
37
53
|
|
|
38
54
|
finally:
|
|
39
55
|
# Clean up socket connection
|
|
@@ -82,6 +98,12 @@ def main():
|
|
|
82
98
|
help='Disable streaming (default: streaming enabled)'
|
|
83
99
|
)
|
|
84
100
|
|
|
101
|
+
parser.add_argument(
|
|
102
|
+
'--show-usage',
|
|
103
|
+
action='store_true',
|
|
104
|
+
help='Show token usage and model on stderr'
|
|
105
|
+
)
|
|
106
|
+
|
|
85
107
|
args = parser.parse_args()
|
|
86
108
|
|
|
87
109
|
try:
|
|
@@ -93,6 +115,7 @@ def main():
|
|
|
93
115
|
prompt=args.prompt[0],
|
|
94
116
|
streaming=not args.no_streaming,
|
|
95
117
|
token=args.token,
|
|
118
|
+
show_usage=args.show_usage,
|
|
96
119
|
)
|
|
97
120
|
|
|
98
121
|
except Exception as e:
|
|
@@ -15,7 +15,8 @@ from trustgraph.api import Api
|
|
|
15
15
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|
16
16
|
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
|
17
17
|
|
|
18
|
-
def query(url, flow_id, template_id, variables, streaming=True, token=None
|
|
18
|
+
def query(url, flow_id, template_id, variables, streaming=True, token=None,
|
|
19
|
+
show_usage=False):
|
|
19
20
|
|
|
20
21
|
# Create API client
|
|
21
22
|
api = Api(url=url, token=token)
|
|
@@ -31,16 +32,30 @@ def query(url, flow_id, template_id, variables, streaming=True, token=None):
|
|
|
31
32
|
)
|
|
32
33
|
|
|
33
34
|
if streaming:
|
|
34
|
-
|
|
35
|
+
last_chunk = None
|
|
35
36
|
for chunk in response:
|
|
36
|
-
if chunk:
|
|
37
|
-
print(chunk, end="", flush=True)
|
|
38
|
-
|
|
37
|
+
if chunk.content:
|
|
38
|
+
print(chunk.content, end="", flush=True)
|
|
39
|
+
last_chunk = chunk
|
|
39
40
|
print()
|
|
40
41
|
|
|
42
|
+
if show_usage and last_chunk:
|
|
43
|
+
print(
|
|
44
|
+
f"Input tokens: {last_chunk.in_token} "
|
|
45
|
+
f"Output tokens: {last_chunk.out_token} "
|
|
46
|
+
f"Model: {last_chunk.model}",
|
|
47
|
+
file=__import__('sys').stderr,
|
|
48
|
+
)
|
|
41
49
|
else:
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
print(response.text)
|
|
51
|
+
|
|
52
|
+
if show_usage:
|
|
53
|
+
print(
|
|
54
|
+
f"Input tokens: {response.in_token} "
|
|
55
|
+
f"Output tokens: {response.out_token} "
|
|
56
|
+
f"Model: {response.model}",
|
|
57
|
+
file=__import__('sys').stderr,
|
|
58
|
+
)
|
|
44
59
|
|
|
45
60
|
finally:
|
|
46
61
|
# Clean up socket connection
|
|
@@ -92,6 +107,12 @@ specified multiple times''',
|
|
|
92
107
|
help='Disable streaming (default: streaming enabled for text responses)'
|
|
93
108
|
)
|
|
94
109
|
|
|
110
|
+
parser.add_argument(
|
|
111
|
+
'--show-usage',
|
|
112
|
+
action='store_true',
|
|
113
|
+
help='Show token usage and model on stderr'
|
|
114
|
+
)
|
|
115
|
+
|
|
95
116
|
args = parser.parse_args()
|
|
96
117
|
|
|
97
118
|
variables = {}
|
|
@@ -113,6 +134,7 @@ specified multiple times''',
|
|
|
113
134
|
variables=variables,
|
|
114
135
|
streaming=not args.no_streaming,
|
|
115
136
|
token=args.token,
|
|
137
|
+
show_usage=args.show_usage,
|
|
116
138
|
)
|
|
117
139
|
|
|
118
140
|
except Exception as e:
|
|
@@ -62,6 +62,11 @@ def sparql_query(url, token, flow_id, query, user, collection, limit,
|
|
|
62
62
|
limit=limit,
|
|
63
63
|
batch_size=batch_size,
|
|
64
64
|
):
|
|
65
|
+
if "error" in response:
|
|
66
|
+
err = response["error"]
|
|
67
|
+
msg = err.get("message", err) if isinstance(err, dict) else err
|
|
68
|
+
raise RuntimeError(msg)
|
|
69
|
+
|
|
65
70
|
query_type = response.get("query-type", "select")
|
|
66
71
|
|
|
67
72
|
# ASK queries - just print and return
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "2.3.1"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: trustgraph-cli
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.1
|
|
4
4
|
Summary: TrustGraph provides a means to run a pipeline of flexible AI processing components in a flexible means to achieve a processing pipeline.
|
|
5
5
|
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<2.
|
|
11
|
+
Requires-Dist: trustgraph-base<2.4,>=2.3
|
|
12
12
|
Requires-Dist: requests
|
|
13
13
|
Requires-Dist: pulsar-client
|
|
14
14
|
Requires-Dist: aiohttp
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.2.26"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|