Migrate cli utils to REST API (#239)

* 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-...
This commit is contained in:
cybermaggedon 2025-01-02 19:49:22 +00:00 committed by GitHub
parent 44c0d6f347
commit 44f8ce8834
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 223 additions and 277 deletions

View file

@ -12,15 +12,15 @@ using key=value arguments on the command line, and these replace
import argparse
import os
import json
from trustgraph.clients.prompt_client import PromptClient
from trustgraph.api import Api
default_pulsar_host = os.getenv("PULSAR_HOST", 'pulsar://localhost:6650')
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
def query(pulsar_host, template_id, variables):
def query(url, template_id, variables):
cli = PromptClient(pulsar_host=pulsar_host)
api = Api(url)
resp = cli.request(id=template_id, variables=variables)
resp = api.prompt(id=template_id, variables=variables)
if isinstance(resp, str):
print(resp)
@ -35,9 +35,9 @@ def main():
)
parser.add_argument(
'-p', '--pulsar-host',
default=default_pulsar_host,
help=f'Pulsar host (default: {default_pulsar_host})',
'-u', '--url',
default=default_url,
help=f'API URL (default: {default_url})',
)
parser.add_argument(
@ -70,7 +70,7 @@ specified multiple times''',
try:
query(
pulsar_host=args.pulsar_host,
url=args.url,
template_id=args.id[0],
variables=variables,
)