Make command line consistent, fix incorrect documentation.

This commit is contained in:
Cyber MacGeddon 2024-11-08 18:11:07 +00:00
parent f97856245c
commit 09729096b5
7 changed files with 32 additions and 29 deletions

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 identifier 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,12 +42,13 @@ def main():
parser.add_argument(
'id',
metavar='template-id',
nargs=1,
help=f'Prompt identifier e.g. question',
)
parser.add_argument(
'term',
'variable',
nargs='*',
help='''Prompt template terms of the form key=value, can be specified
multiple times''',
@ -54,22 +56,22 @@ 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: