mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-19 18:21:03 +02:00
tg-show-config CLI command
This commit is contained in:
parent
6828ca8fc6
commit
36f3cdc94c
3 changed files with 80 additions and 0 deletions
|
|
@ -382,3 +382,33 @@ class Api:
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
raise ProtocolException(f"Status code {resp.status_code}")
|
raise ProtocolException(f"Status code {resp.status_code}")
|
||||||
|
|
||||||
|
def get_config(self):
|
||||||
|
|
||||||
|
# The input consists of system and prompt strings
|
||||||
|
input = {
|
||||||
|
"operation": "config"
|
||||||
|
}
|
||||||
|
|
||||||
|
url = f"{self.url}config"
|
||||||
|
|
||||||
|
# Invoke the API, input is passed as JSON
|
||||||
|
resp = requests.post(url, json=input)
|
||||||
|
|
||||||
|
# Should be a 200 status code
|
||||||
|
if resp.status_code != 200:
|
||||||
|
raise ProtocolException(f"Status code {resp.status_code}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Parse the response as JSON
|
||||||
|
object = resp.json()
|
||||||
|
except:
|
||||||
|
raise ProtocolException(f"Expected JSON response")
|
||||||
|
|
||||||
|
self.check_error(resp)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return object["config"], object["version"]
|
||||||
|
except:
|
||||||
|
raise ProtocolException(f"Response not formatted correctly")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
49
trustgraph-cli/scripts/tg-show-config
Executable file
49
trustgraph-cli/scripts/tg-show-config
Executable file
|
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Dumps out the current configuration
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
from trustgraph.api import Api
|
||||||
|
import json
|
||||||
|
|
||||||
|
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||||
|
|
||||||
|
def show_config(url):
|
||||||
|
|
||||||
|
api = Api(url)
|
||||||
|
|
||||||
|
config, version = api.get_config()
|
||||||
|
|
||||||
|
print("Version:", version)
|
||||||
|
print(json.dumps(config, indent=4))
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog='tg-show-config',
|
||||||
|
description=__doc__,
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
'-u', '--api-url',
|
||||||
|
default=default_url,
|
||||||
|
help=f'API URL (default: {default_url})',
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
show_config(
|
||||||
|
url=args.api_url,
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
|
||||||
|
print("Exception:", e, flush=True)
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
@ -62,5 +62,6 @@ setuptools.setup(
|
||||||
"scripts/tg-processor-state",
|
"scripts/tg-processor-state",
|
||||||
"scripts/tg-save-kg-core",
|
"scripts/tg-save-kg-core",
|
||||||
"scripts/tg-save-doc-embeds",
|
"scripts/tg-save-doc-embeds",
|
||||||
|
"scripts/tg-show-config",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue