mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 08:26:21 +02:00
* Port a number of commands to use API gateway instead of Pulsar * Ported tg-invoke-agent to websockets API * Rename the 2 RAG commands: tg-query-... to tg-invoke-...
63 lines
1.1 KiB
Python
Executable file
63 lines
1.1 KiB
Python
Executable file
#!/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.api import Api
|
|
|
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|
|
|
def query(url, system, prompt):
|
|
|
|
api = Api(url)
|
|
|
|
resp = api.text_completion(system=system, prompt=prompt)
|
|
|
|
print(resp)
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(
|
|
prog='tg-invoke-llm',
|
|
description=__doc__,
|
|
)
|
|
|
|
parser.add_argument(
|
|
'-u', '--url',
|
|
default=default_url,
|
|
help=f'API URL (default: {default_url})',
|
|
)
|
|
|
|
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(
|
|
url=args.url,
|
|
system=args.system[0],
|
|
prompt=args.prompt[0],
|
|
)
|
|
|
|
except Exception as e:
|
|
|
|
print("Exception:", e, flush=True)
|
|
|
|
main()
|
|
|