Fix/improve command line help (#145)

* Make command line consistent, fix incorrect documentation.

* Improve tg-invoke-prompt help
This commit is contained in:
cybermaggedon 2024-11-08 18:14:14 +00:00 committed by GitHub
parent f97856245c
commit ae8661fe2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 36 additions and 32 deletions

View file

@ -27,7 +27,7 @@ def show_graph(pulsar, user, collection):
def main():
parser = argparse.ArgumentParser(
prog='graph-show',
prog='tg-graph-show',
description=__doc__,
)

View file

@ -1,7 +1,8 @@
#!/usr/bin/env python3
"""
Connects to the graph query service and dumps all graph edges.
Connects to the graph query service and dumps all graph edges in Turtle
format.
"""
import argparse
@ -50,7 +51,7 @@ def show_graph(pulsar):
def main():
parser = argparse.ArgumentParser(
prog='graph-show',
prog='tg-graph-to-turtle',
description=__doc__,
)

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""
Initialises Pulsar with Trustgraph tenant / namespaces & policy
Initialises Pulsar with Trustgraph tenant / namespaces & policy.
"""
import requests

View file

@ -1,11 +1,12 @@
#!/usr/bin/env python3
"""
Invokes the LLM prompt service by specifying a prompt identifier and template
terms. The prompt identifier identifies which prompt template to use.
Standard template identifiers are: question, extract-relationship.
The prompt terms specify keyword terms in the template to be replaced, and
provide the values to replace them with.
Invokes the LLM prompt service by specifying the prompt template to use
and values for the variables in the prompt template. The
prompt template is identified by its template identifier e.g.
question, extract-definitions. Template variable values are specified
using key=value arguments on the command line, and these replace
{{key}} placeholders in the template.
"""
import argparse
@ -15,11 +16,11 @@ from trustgraph.clients.prompt_client import PromptClient
default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
def query(pulsar_host, id, terms):
def query(pulsar_host, template_id, variables):
cli = PromptClient(pulsar_host=pulsar_host)
resp = cli.request(id=id, terms=terms)
resp = cli.request(id=template_id, variables=variables)
if isinstance(resp, str):
print(resp)
@ -41,35 +42,37 @@ def main():
parser.add_argument(
'id',
metavar='template-id',
nargs=1,
help=f'Prompt identifier e.g. question',
help=f'Prompt identifier e.g. question, extract-definitions',
)
parser.add_argument(
'term',
'variable',
nargs='*',
help='''Prompt template terms of the form key=value, can be specified
multiple times''',
metavar="variable=value",
help='''Prompt template terms of the form variable=value, can be
specified multiple times''',
)
args = parser.parse_args()
terms = {}
variables = {}
for term in args.term:
for variable in args.variable:
toks = term.split("=", 1)
toks = variable.split("=", 1)
if len(toks) != 2:
raise RuntimeError(f"Malformed term: {term}")
raise RuntimeError(f"Malformed variable: {variable}")
terms[toks[0]] = toks[1]
variables[toks[0]] = toks[1]
try:
query(
pulsar_host=args.pulsar_host,
id=args.id[0],
terms=terms,
template_id=args.id[0],
variables=variables,
)
except Exception as e:

View file

@ -99,7 +99,7 @@ class Loader:
def main():
parser = argparse.ArgumentParser(
prog='loader',
prog='tg-load-pdf',
description=__doc__,
)

View file

@ -99,7 +99,7 @@ class Loader:
def main():
parser = argparse.ArgumentParser(
prog='loader',
prog='tg-load-text',
description=__doc__,
)