Port a number of commands to use API gateway instead of Pulsar

This commit is contained in:
Cyber MacGeddon 2025-01-02 17:17:38 +00:00
parent 44c0d6f347
commit cb2e8a3724
6 changed files with 112 additions and 81 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,
)