mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-17 09:11:03 +02:00
Tools to dump out prompts and agent tools
This commit is contained in:
parent
ac03539264
commit
a778b9a126
2 changed files with 182 additions and 0 deletions
96
trustgraph-cli/scripts/tg-show-prompts
Executable file
96
trustgraph-cli/scripts/tg-show-prompts
Executable file
|
|
@ -0,0 +1,96 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Dumps out the current prompts
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from trustgraph.api import Api, ConfigKey
|
||||
import json
|
||||
import tabulate
|
||||
import textwrap
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
|
||||
def show_config(url):
|
||||
|
||||
api = Api(url)
|
||||
|
||||
values = api.config_get([
|
||||
ConfigKey(type="prompt", key="system"),
|
||||
ConfigKey(type="prompt", key="template-index")
|
||||
])
|
||||
|
||||
system = json.loads(values[0].value)
|
||||
ix = json.loads(values[1].value)
|
||||
|
||||
values = api.config_get([
|
||||
ConfigKey(type="prompt", key=f"template.{v}")
|
||||
for v in ix
|
||||
])
|
||||
|
||||
print()
|
||||
|
||||
print("System prompt:")
|
||||
|
||||
print(tabulate.tabulate(
|
||||
[["prompt", system]],
|
||||
tablefmt="pretty",
|
||||
maxcolwidths=[None, 70],
|
||||
stralign="left"
|
||||
))
|
||||
|
||||
for n, key in enumerate(ix):
|
||||
|
||||
data = json.loads(values[n].value)
|
||||
|
||||
table = []
|
||||
|
||||
table.append(("prompt", data["prompt"]))
|
||||
|
||||
if "response-type" in data:
|
||||
table.append(("response", data["response-type"]))
|
||||
|
||||
if "schema" in data:
|
||||
table.append(("schema", data["schema"]))
|
||||
|
||||
print()
|
||||
print(key + ":")
|
||||
|
||||
print(tabulate.tabulate(
|
||||
table,
|
||||
tablefmt="pretty",
|
||||
maxcolwidths=[None, 70],
|
||||
stralign="left"
|
||||
))
|
||||
|
||||
print()
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-show-prompts',
|
||||
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()
|
||||
|
||||
86
trustgraph-cli/scripts/tg-show-tools
Executable file
86
trustgraph-cli/scripts/tg-show-tools
Executable file
|
|
@ -0,0 +1,86 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
"""
|
||||
Dumps out the current agent tools
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
from trustgraph.api import Api, ConfigKey
|
||||
import json
|
||||
import tabulate
|
||||
import textwrap
|
||||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
|
||||
def show_config(url):
|
||||
|
||||
api = Api(url)
|
||||
|
||||
values = api.config_get([
|
||||
ConfigKey(type="agent", key="tool-index")
|
||||
])
|
||||
|
||||
ix = json.loads(values[0].value)
|
||||
|
||||
values = api.config_get([
|
||||
ConfigKey(type="agent", key=f"tool.{v}")
|
||||
for v in ix
|
||||
])
|
||||
|
||||
for n, key in enumerate(ix):
|
||||
|
||||
data = json.loads(values[n].value)
|
||||
|
||||
table = []
|
||||
|
||||
table.append(("id", data["id"]))
|
||||
table.append(("name", data["name"]))
|
||||
table.append(("description", data["description"]))
|
||||
|
||||
for n, arg in enumerate(data["arguments"]):
|
||||
table.append((
|
||||
f"arg {n}",
|
||||
f"{arg['name']}: {arg['type']}\n{arg['description']}"
|
||||
))
|
||||
|
||||
|
||||
print()
|
||||
print(key + ":")
|
||||
|
||||
print(tabulate.tabulate(
|
||||
table,
|
||||
tablefmt="pretty",
|
||||
maxcolwidths=[None, 70],
|
||||
stralign="left"
|
||||
))
|
||||
|
||||
print()
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-show-prompts',
|
||||
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()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue