mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-22 11:41:02 +02:00
Major Python client API rework, break down API & colossal class
This commit is contained in:
parent
c49568dd34
commit
46a60d891c
29 changed files with 688 additions and 623 deletions
|
|
@ -13,9 +13,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def delete_flow_class(url, class_name):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).flow()
|
||||
|
||||
class_names = api.flow_delete_class(class_name)
|
||||
class_names = api.delete_class(class_name)
|
||||
|
||||
def main():
|
||||
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def get_flow_class(url, class_name):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).flow()
|
||||
|
||||
cls = api.flow_get_class(class_name)
|
||||
cls = api.get_class(class_name)
|
||||
|
||||
print(json.dumps(cls, indent=4))
|
||||
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ default_collection = 'default'
|
|||
|
||||
def show_graph(url, flow_id, user, collection):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).flow().id(flow_id)
|
||||
|
||||
rows = api.flow(flow_id).triples_query(
|
||||
rows = api.triples_query(
|
||||
user=user, collection=collection,
|
||||
s=None, p=None, o=None, limit=10_000,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ default_collection = 'default'
|
|||
|
||||
def show_graph(url, flow_id, user, collection):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).flow().id(flow_id)
|
||||
|
||||
rows = api.flow(flow_id).triples_query(
|
||||
rows = api.triples_query(
|
||||
s=None, p=None, o=None,
|
||||
user=user, collection=collection,
|
||||
limit=10_000)
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ default_doc_limit = 10
|
|||
|
||||
def question(url, flow_id, question, user, collection, doc_limit):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).flow().id(flow_id)
|
||||
|
||||
resp = api.flow(flow_id).document_rag(
|
||||
resp = api.document_rag(
|
||||
question=question, user=user, collection=collection,
|
||||
doc_limit=doc_limit,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ def question(
|
|||
max_subgraph_size, max_path_length
|
||||
):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).flow().id(flow_id)
|
||||
|
||||
resp = api.flow(flow_id).graph_rag(
|
||||
resp = api.graph_rag(
|
||||
question=question, user=user, collection=collection,
|
||||
entity_limit=entity_limit, triple_limit=triple_limit,
|
||||
max_subgraph_size=max_subgraph_size,
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def query(url, flow_id, system, prompt):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).flow().id(flow_id).
|
||||
|
||||
resp = api.flow(flow_id).text_completion(system=system, prompt=prompt)
|
||||
resp = api.text_completion(system=system, prompt=prompt)
|
||||
|
||||
print(resp)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def query(url, flow_id, template_id, variables):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).flow().id(flow_id)
|
||||
|
||||
resp = api.flow(flow_id).prompt(id=template_id, variables=variables)
|
||||
resp = api.prompt(id=template_id, variables=variables)
|
||||
|
||||
if isinstance(resp, str):
|
||||
print(resp)
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class Loader:
|
|||
metadata,
|
||||
):
|
||||
|
||||
self.api = Api(url).flow(flow_id)
|
||||
self.api = Api(url).flow().id(flow_id)
|
||||
|
||||
self.user = user
|
||||
self.collection = collection
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class Loader:
|
|||
metadata,
|
||||
):
|
||||
|
||||
self.api = Api(url).flow(flow_id)
|
||||
self.api = Api(url).flow().id(flow_id)
|
||||
|
||||
self.user = user
|
||||
self.collection = collection
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
"""
|
||||
Loads Graph embeddings into TrustGraph processing.
|
||||
|
||||
FIXME: This hasn't been updated following API gateway change.
|
||||
"""
|
||||
|
||||
import pulsar
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ Dumps out the current configuration
|
|||
|
||||
import argparse
|
||||
import os
|
||||
import tabulate
|
||||
from trustgraph.api import Api
|
||||
import json
|
||||
|
||||
|
|
@ -16,7 +15,7 @@ def put_flow_class(url, class_name, config):
|
|||
|
||||
api = Api(url)
|
||||
|
||||
class_names = api.flow_put_class(class_name, config)
|
||||
class_names = api.flow().put_class(class_name, config)
|
||||
|
||||
def main():
|
||||
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def set_system(url, system):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).config()
|
||||
|
||||
api.config_put([
|
||||
api.put([
|
||||
ConfigValue(type="prompt", key="system", value=json.dumps(system))
|
||||
])
|
||||
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def set_costs(api_url, model, input_costs, output_costs):
|
||||
|
||||
api = Api(api_url)
|
||||
api = Api(api_url).config()
|
||||
|
||||
api.config_put([
|
||||
api.put([
|
||||
ConfigValue(
|
||||
type="token-costs", key=model,
|
||||
value=json.dumps({
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def show_config(url):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).config()
|
||||
|
||||
config, version = api.config_all()
|
||||
config, version = api.all()
|
||||
|
||||
print("Version:", version)
|
||||
print(json.dumps(config, indent=4))
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def show_flow_classes(url):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).flow()
|
||||
|
||||
class_names = api.flow_list_classes()
|
||||
class_names = api.list_classes()
|
||||
|
||||
if len(class_names) == 0:
|
||||
print("No flows.")
|
||||
|
|
@ -24,7 +24,7 @@ def show_flow_classes(url):
|
|||
classes = []
|
||||
|
||||
for class_name in class_names:
|
||||
cls = api.flow_get_class(class_name)
|
||||
cls = api.get_class(class_name)
|
||||
classes.append((
|
||||
class_name,
|
||||
cls.get("description", ""),
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def dump_status(metrics_url, api_url, flow_id):
|
||||
|
||||
api = Api(api_url)
|
||||
api = Api(api_url).flow()
|
||||
|
||||
flow = api.flow_get(flow_id)
|
||||
flow = api.get(flow_id)
|
||||
class_name = flow["class-name"]
|
||||
|
||||
print()
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ import json
|
|||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
|
||||
def get_interface(api, i):
|
||||
def get_interface(config_api, i):
|
||||
|
||||
key = ConfigKey("interface-descriptions", i)
|
||||
|
||||
value = api.config_get([key])[0].value
|
||||
value = config_api.get([key])[0].value
|
||||
|
||||
return json.loads(value)
|
||||
|
||||
|
|
@ -49,15 +49,17 @@ def describe_interfaces(intdefs, flow):
|
|||
def show_flows(url):
|
||||
|
||||
api = Api(url)
|
||||
config_api = api.config()
|
||||
flow_api = api.flow()
|
||||
|
||||
interface_names = api.config_list("interface-descriptions")
|
||||
interface_names = config_api.list("interface-descriptions")
|
||||
|
||||
interface_defs = {
|
||||
i: get_interface(api, i)
|
||||
i: get_interface(config_api, i)
|
||||
for i in interface_names
|
||||
}
|
||||
|
||||
flow_ids = api.flow_list()
|
||||
flow_ids = flow_api.list()
|
||||
|
||||
if len(flow_ids) == 0:
|
||||
print("No flows.")
|
||||
|
|
@ -67,7 +69,7 @@ def show_flows(url):
|
|||
|
||||
for id in flow_ids:
|
||||
|
||||
flow = api.flow_get(id)
|
||||
flow = flow_api.get(id)
|
||||
|
||||
table = []
|
||||
table.append(("id", id))
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def show_config(url):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).config()
|
||||
|
||||
values = api.config_get([
|
||||
values = api.get([
|
||||
ConfigKey(type="prompt", key="system"),
|
||||
ConfigKey(type="prompt", key="template-index")
|
||||
])
|
||||
|
|
@ -25,7 +25,7 @@ def show_config(url):
|
|||
system = json.loads(values[0].value)
|
||||
ix = json.loads(values[1].value)
|
||||
|
||||
values = api.config_get([
|
||||
values = api.get([
|
||||
ConfigKey(type="prompt", key=f"template.{v}")
|
||||
for v in ix
|
||||
])
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def show_config(url):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).config()
|
||||
|
||||
models = api.config_list("token-costs")
|
||||
models = api.list("token-costs")
|
||||
|
||||
costs = []
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ def show_config(url):
|
|||
for model in models:
|
||||
|
||||
try:
|
||||
values = json.loads(api.config_get([
|
||||
values = json.loads(api.get([
|
||||
ConfigKey(type="token-costs", key=model),
|
||||
])[0].value)
|
||||
costs.append((
|
||||
|
|
|
|||
|
|
@ -15,15 +15,15 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def show_config(url):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).config()
|
||||
|
||||
values = api.config_get([
|
||||
values = api.get([
|
||||
ConfigKey(type="agent", key="tool-index")
|
||||
])
|
||||
|
||||
ix = json.loads(values[0].value)
|
||||
|
||||
values = api.config_get([
|
||||
values = api.get([
|
||||
ConfigKey(type="agent", key=f"tool.{v}")
|
||||
for v in ix
|
||||
])
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def start_flow(url, class_name, flow_id, description):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).flow()
|
||||
|
||||
api.flow_start(
|
||||
api.start(
|
||||
class_name = class_name,
|
||||
id = flow_id,
|
||||
description = description,
|
||||
|
|
|
|||
|
|
@ -13,9 +13,9 @@ default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
|||
|
||||
def stop_flow(url, flow_id):
|
||||
|
||||
api = Api(url)
|
||||
api = Api(url).flow()
|
||||
|
||||
api.flow_stop(id = flow_id)
|
||||
api.stop(id = flow_id)
|
||||
|
||||
def main():
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue