-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improved documentation in tg-invoke-prompt. Added tg-invoke-llm. These are diagnostics for the text-completion and prompt services. * Fix command name
- Loading branch information
1 parent
c308180
commit 66d273c
Showing
3 changed files
with
73 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters