From 66d273cf5addb174dd46c077f525cb3239229931 Mon Sep 17 00:00:00 2001 From: cybermaggedon Date: Thu, 7 Nov 2024 21:01:51 +0000 Subject: [PATCH] Fix/cli docs (#143) * Improved documentation in tg-invoke-prompt. Added tg-invoke-llm. These are diagnostics for the text-completion and prompt services. * Fix command name --- trustgraph-cli/scripts/tg-invoke-llm | 63 +++++++++++++++++++++++++ trustgraph-cli/scripts/tg-invoke-prompt | 13 +++-- trustgraph-cli/setup.py | 1 + 3 files changed, 73 insertions(+), 4 deletions(-) create mode 100755 trustgraph-cli/scripts/tg-invoke-llm diff --git a/trustgraph-cli/scripts/tg-invoke-llm b/trustgraph-cli/scripts/tg-invoke-llm new file mode 100755 index 00000000..d7289b5f --- /dev/null +++ b/trustgraph-cli/scripts/tg-invoke-llm @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 + +""" +Invokes the text completion service by specifying an LLM system prompt +and user prompt. Both arguments are required. +""" + +import argparse +import os +import json +from trustgraph.clients.llm_client import LlmClient + +default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650') + +def query(pulsar_host, system, prompt): + + cli = LlmClient(pulsar_host=pulsar_host) + + resp = cli.request(system=system, prompt=prompt) + + print(resp) + +def main(): + + parser = argparse.ArgumentParser( + prog='tg-invoke-llm', + description=__doc__, + ) + + parser.add_argument( + '-p', '--pulsar-host', + default=default_pulsar_host, + help=f'Pulsar host (default: {default_pulsar_host})', + ) + + parser.add_argument( + 'system', + nargs=1, + help='LLM system prompt e.g. You are a helpful assistant', + ) + + parser.add_argument( + 'prompt', + nargs=1, + help='LLM prompt e.g. What is 2 + 2?', + ) + + args = parser.parse_args() + + try: + + query( + pulsar_host=args.pulsar_host, + system=args.system[0], + prompt=args.prompt[0], + ) + + except Exception as e: + + print("Exception:", e, flush=True) + +main() + diff --git a/trustgraph-cli/scripts/tg-invoke-prompt b/trustgraph-cli/scripts/tg-invoke-prompt index 8f62965c..95923ec5 100755 --- a/trustgraph-cli/scripts/tg-invoke-prompt +++ b/trustgraph-cli/scripts/tg-invoke-prompt @@ -1,7 +1,11 @@ #!/usr/bin/env python3 """ -Uses the GraphRAG service to answer a query +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. """ import argparse @@ -25,7 +29,7 @@ def query(pulsar_host, id, terms): def main(): parser = argparse.ArgumentParser( - prog='tg-graph-query-rag', + prog='tg-invoke-prompt', description=__doc__, ) @@ -38,13 +42,14 @@ def main(): parser.add_argument( 'id', nargs=1, - help=f'Prompt identifier', + help=f'Prompt identifier e.g. question', ) parser.add_argument( 'term', nargs='*', - help=f'Prompt terms', + help='''Prompt template terms of the form key=value, can be specified +multiple times''', ) args = parser.parse_args() diff --git a/trustgraph-cli/setup.py b/trustgraph-cli/setup.py index 76b2e3a0..4189d3f4 100644 --- a/trustgraph-cli/setup.py +++ b/trustgraph-cli/setup.py @@ -52,5 +52,6 @@ "scripts/tg-init-pulsar", "scripts/tg-processor-state", "scripts/tg-invoke-prompt", + "scripts/tg-invoke-llm", ] )