mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-05-06 05:42:36 +02:00
Fix/improve command line help (#145)
* Make command line consistent, fix incorrect documentation. * Improve tg-invoke-prompt help
This commit is contained in:
parent
f97856245c
commit
ae8661fe2e
7 changed files with 36 additions and 32 deletions
|
|
@ -57,13 +57,13 @@ class PromptClient(BaseClient):
|
||||||
output_schema=PromptResponse,
|
output_schema=PromptResponse,
|
||||||
)
|
)
|
||||||
|
|
||||||
def request(self, id, terms, timeout=300):
|
def request(self, id, variables, timeout=300):
|
||||||
|
|
||||||
resp = self.call(
|
resp = self.call(
|
||||||
id=id,
|
id=id,
|
||||||
terms={
|
terms={
|
||||||
k: json.dumps(v)
|
k: json.dumps(v)
|
||||||
for k, v in terms.items()
|
for k, v in variables.items()
|
||||||
},
|
},
|
||||||
timeout=timeout
|
timeout=timeout
|
||||||
)
|
)
|
||||||
|
|
@ -76,7 +76,7 @@ class PromptClient(BaseClient):
|
||||||
|
|
||||||
defs = self.request(
|
defs = self.request(
|
||||||
id="extract-definitions",
|
id="extract-definitions",
|
||||||
terms={
|
variables={
|
||||||
"text": chunk
|
"text": chunk
|
||||||
},
|
},
|
||||||
timeout=timeout
|
timeout=timeout
|
||||||
|
|
@ -91,7 +91,7 @@ class PromptClient(BaseClient):
|
||||||
|
|
||||||
rels = self.request(
|
rels = self.request(
|
||||||
id="extract-relationships",
|
id="extract-relationships",
|
||||||
terms={
|
variables={
|
||||||
"text": chunk
|
"text": chunk
|
||||||
},
|
},
|
||||||
timeout=timeout
|
timeout=timeout
|
||||||
|
|
@ -111,7 +111,7 @@ class PromptClient(BaseClient):
|
||||||
|
|
||||||
topics = self.request(
|
topics = self.request(
|
||||||
id="extract-topics",
|
id="extract-topics",
|
||||||
terms={
|
variables={
|
||||||
"text": chunk
|
"text": chunk
|
||||||
},
|
},
|
||||||
timeout=timeout
|
timeout=timeout
|
||||||
|
|
@ -126,7 +126,7 @@ class PromptClient(BaseClient):
|
||||||
|
|
||||||
return self.request(
|
return self.request(
|
||||||
id="extract-rows",
|
id="extract-rows",
|
||||||
terms={
|
variables={
|
||||||
"chunk": chunk,
|
"chunk": chunk,
|
||||||
"row-schema": {
|
"row-schema": {
|
||||||
"name": schema.name,
|
"name": schema.name,
|
||||||
|
|
@ -148,7 +148,7 @@ class PromptClient(BaseClient):
|
||||||
|
|
||||||
return self.request(
|
return self.request(
|
||||||
id="kg-prompt",
|
id="kg-prompt",
|
||||||
terms={
|
variables={
|
||||||
"query": query,
|
"query": query,
|
||||||
"knowledge": [
|
"knowledge": [
|
||||||
{ "s": v[0], "p": v[1], "o": v[2] }
|
{ "s": v[0], "p": v[1], "o": v[2] }
|
||||||
|
|
@ -162,7 +162,7 @@ class PromptClient(BaseClient):
|
||||||
|
|
||||||
return self.request(
|
return self.request(
|
||||||
id="document-prompt",
|
id="document-prompt",
|
||||||
terms={
|
variables={
|
||||||
"query": query,
|
"query": query,
|
||||||
"documents": documents,
|
"documents": documents,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ def show_graph(pulsar, user, collection):
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog='graph-show',
|
prog='tg-graph-show',
|
||||||
description=__doc__,
|
description=__doc__,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
#!/usr/bin/env python3
|
#!/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
|
import argparse
|
||||||
|
|
@ -50,7 +51,7 @@ def show_graph(pulsar):
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog='graph-show',
|
prog='tg-graph-to-turtle',
|
||||||
description=__doc__,
|
description=__doc__,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Initialises Pulsar with Trustgraph tenant / namespaces & policy
|
Initialises Pulsar with Trustgraph tenant / namespaces & policy.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Invokes the LLM prompt service by specifying a prompt identifier and template
|
Invokes the LLM prompt service by specifying the prompt template to use
|
||||||
terms. The prompt identifier identifies which prompt template to use.
|
and values for the variables in the prompt template. The
|
||||||
Standard template identifiers are: question, extract-relationship.
|
prompt template is identified by its template identifier e.g.
|
||||||
The prompt terms specify keyword terms in the template to be replaced, and
|
question, extract-definitions. Template variable values are specified
|
||||||
provide the values to replace them with.
|
using key=value arguments on the command line, and these replace
|
||||||
|
{{key}} placeholders in the template.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
@ -15,11 +16,11 @@ from trustgraph.clients.prompt_client import PromptClient
|
||||||
|
|
||||||
default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
|
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)
|
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):
|
if isinstance(resp, str):
|
||||||
print(resp)
|
print(resp)
|
||||||
|
|
@ -41,35 +42,37 @@ def main():
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'id',
|
'id',
|
||||||
|
metavar='template-id',
|
||||||
nargs=1,
|
nargs=1,
|
||||||
help=f'Prompt identifier e.g. question',
|
help=f'Prompt identifier e.g. question, extract-definitions',
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'term',
|
'variable',
|
||||||
nargs='*',
|
nargs='*',
|
||||||
help='''Prompt template terms of the form key=value, can be specified
|
metavar="variable=value",
|
||||||
multiple times''',
|
help='''Prompt template terms of the form variable=value, can be
|
||||||
|
specified multiple times''',
|
||||||
)
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
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:
|
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:
|
try:
|
||||||
|
|
||||||
query(
|
query(
|
||||||
pulsar_host=args.pulsar_host,
|
pulsar_host=args.pulsar_host,
|
||||||
id=args.id[0],
|
template_id=args.id[0],
|
||||||
terms=terms,
|
variables=variables,
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ class Loader:
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog='loader',
|
prog='tg-load-pdf',
|
||||||
description=__doc__,
|
description=__doc__,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ class Loader:
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog='loader',
|
prog='tg-load-text',
|
||||||
description=__doc__,
|
description=__doc__,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue