mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 08:26:21 +02:00
Fix config inconsistency (#609)
* Plural/singular confusion in config key * Flow class vs flow blueprint nomenclature change * Update docs & CLI to reflect the above
This commit is contained in:
parent
99f17d1b9d
commit
b08db761d7
36 changed files with 816 additions and 814 deletions
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Deletes a flow class
|
||||
Deletes a flow blueprint
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
|
@ -10,16 +10,16 @@ import json
|
|||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
|
||||
def delete_flow_class(url, class_name):
|
||||
def delete_flow_blueprint(url, blueprint_name):
|
||||
|
||||
api = Api(url).flow()
|
||||
|
||||
class_names = api.delete_class(class_name)
|
||||
blueprint_names = api.delete_blueprint(blueprint_name)
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-delete-flow-class',
|
||||
prog='tg-delete-flow-blueprint',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
|
|
@ -30,17 +30,17 @@ def main():
|
|||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-n', '--class-name',
|
||||
help=f'Flow class name',
|
||||
'-n', '--blueprint-name',
|
||||
help=f'Flow blueprint name',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
delete_flow_class(
|
||||
delete_flow_blueprint(
|
||||
url=args.api_url,
|
||||
class_name=args.class_name,
|
||||
blueprint_name=args.blueprint_name,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
@ -48,4 +48,4 @@ def main():
|
|||
print("Exception:", e, flush=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Outputs a flow class definition in JSON format.
|
||||
Outputs a flow blueprint definition in JSON format.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
|
@ -10,18 +10,18 @@ import json
|
|||
|
||||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
|
||||
def get_flow_class(url, class_name):
|
||||
def get_flow_blueprint(url, blueprint_name):
|
||||
|
||||
api = Api(url).flow()
|
||||
|
||||
cls = api.get_class(class_name)
|
||||
cls = api.get_blueprint(blueprint_name)
|
||||
|
||||
print(json.dumps(cls, indent=4))
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-get-flow-class',
|
||||
prog='tg-get-flow-blueprint',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
|
|
@ -32,18 +32,18 @@ def main():
|
|||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-n', '--class-name',
|
||||
'-n', '--blueprint-name',
|
||||
required=True,
|
||||
help=f'Flow class name',
|
||||
help=f'Flow blueprint name',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
|
||||
get_flow_class(
|
||||
get_flow_blueprint(
|
||||
url=args.api_url,
|
||||
class_name=args.class_name,
|
||||
blueprint_name=args.blueprint_name,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
|
|
@ -51,4 +51,4 @@ def main():
|
|||
print("Exception:", e, flush=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
"""
|
||||
Uploads a flow class definition. You can take the output of
|
||||
tg-get-flow-class and load it back in using this utility.
|
||||
Uploads a flow blueprint definition. You can take the output of
|
||||
tg-get-flow-blueprint and load it back in using this utility.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
|
@ -11,16 +11,16 @@ import json
|
|||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
||||
|
||||
def put_flow_class(url, class_name, config, token=None):
|
||||
def put_flow_blueprint(url, blueprint_name, config, token=None):
|
||||
|
||||
api = Api(url, token=token)
|
||||
|
||||
class_names = api.flow().put_class(class_name, config)
|
||||
blueprint_names = api.flow().put_blueprint(blueprint_name, config)
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-put-flow-class',
|
||||
prog='tg-put-flow-blueprint',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
|
|
@ -37,8 +37,8 @@ def main():
|
|||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-n', '--class-name',
|
||||
help=f'Flow class name',
|
||||
'-n', '--blueprint-name',
|
||||
help=f'Flow blueprint name',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
|
|
@ -50,9 +50,9 @@ def main():
|
|||
|
||||
try:
|
||||
|
||||
put_flow_class(
|
||||
put_flow_blueprint(
|
||||
url=args.api_url,
|
||||
class_name=args.class_name,
|
||||
blueprint_name=args.blueprint_name,
|
||||
config=json.loads(args.config),
|
||||
token=args.token,
|
||||
)
|
||||
|
|
@ -62,4 +62,4 @@ def main():
|
|||
print("Exception:", e, flush=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Shows all defined flow classes.
|
||||
Shows all defined flow blueprints.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
|
@ -16,7 +16,7 @@ def format_parameters(params_metadata, config_api):
|
|||
Format parameter metadata for display
|
||||
|
||||
Args:
|
||||
params_metadata: Parameter definitions from flow class
|
||||
params_metadata: Parameter definitions from flow blueprint
|
||||
config_api: API client to get parameter type information
|
||||
|
||||
Returns:
|
||||
|
|
@ -41,7 +41,7 @@ def format_parameters(params_metadata, config_api):
|
|||
type_info = param_type
|
||||
if config_api:
|
||||
try:
|
||||
key = ConfigKey("parameter-types", param_type)
|
||||
key = ConfigKey("parameter-type", param_type)
|
||||
type_def_value = config_api.get([key])[0].value
|
||||
param_type_def = json.loads(type_def_value)
|
||||
|
||||
|
|
@ -58,23 +58,23 @@ def format_parameters(params_metadata, config_api):
|
|||
|
||||
return "\n".join(param_list)
|
||||
|
||||
def show_flow_classes(url, token=None):
|
||||
def show_flow_blueprints(url, token=None):
|
||||
|
||||
api = Api(url, token=token)
|
||||
flow_api = api.flow()
|
||||
config_api = api.config()
|
||||
|
||||
class_names = flow_api.list_classes()
|
||||
blueprint_names = flow_api.list_blueprints()
|
||||
|
||||
if len(class_names) == 0:
|
||||
print("No flow classes.")
|
||||
if len(blueprint_names) == 0:
|
||||
print("No flow blueprints.")
|
||||
return
|
||||
|
||||
for class_name in class_names:
|
||||
cls = flow_api.get_class(class_name)
|
||||
for blueprint_name in blueprint_names:
|
||||
cls = flow_api.get_blueprint(blueprint_name)
|
||||
|
||||
table = []
|
||||
table.append(("name", class_name))
|
||||
table.append(("name", blueprint_name))
|
||||
table.append(("description", cls.get("description", "")))
|
||||
|
||||
tags = cls.get("tags", [])
|
||||
|
|
@ -97,7 +97,7 @@ def show_flow_classes(url, token=None):
|
|||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='tg-show-flow-classes',
|
||||
prog='tg-show-flow-blueprints',
|
||||
description=__doc__,
|
||||
)
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ def main():
|
|||
|
||||
try:
|
||||
|
||||
show_flow_classes(
|
||||
show_flow_blueprints(
|
||||
url=args.api_url,
|
||||
token=args.token,
|
||||
)
|
||||
|
|
@ -127,4 +127,4 @@ def main():
|
|||
print("Exception:", e, flush=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
|
@ -16,15 +16,15 @@ def dump_status(metrics_url, api_url, flow_id, token=None):
|
|||
api = Api(api_url, token=token).flow()
|
||||
|
||||
flow = api.get(flow_id)
|
||||
class_name = flow["class-name"]
|
||||
blueprint_name = flow["blueprint-name"]
|
||||
|
||||
print()
|
||||
print(f"Flow {flow_id}")
|
||||
show_processors(metrics_url, flow_id)
|
||||
|
||||
print()
|
||||
print(f"Class {class_name}")
|
||||
show_processors(metrics_url, class_name)
|
||||
print(f"Blueprint {blueprint_name}")
|
||||
show_processors(metrics_url, blueprint_name)
|
||||
|
||||
print()
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
|||
|
||||
def get_interface(config_api, i):
|
||||
|
||||
key = ConfigKey("interface-descriptions", i)
|
||||
key = ConfigKey("interface-description", i)
|
||||
|
||||
value = config_api.get([key])[0].value
|
||||
|
||||
|
|
@ -70,13 +70,13 @@ def get_enum_description(param_value, param_type_def):
|
|||
# If not found in enum, return original value
|
||||
return param_value
|
||||
|
||||
def format_parameters(flow_params, class_params_metadata, config_api):
|
||||
def format_parameters(flow_params, blueprint_params_metadata, config_api):
|
||||
"""
|
||||
Format flow parameters with their human-readable descriptions
|
||||
|
||||
Args:
|
||||
flow_params: The actual parameter values used in the flow
|
||||
class_params_metadata: The parameter metadata from the flow class definition
|
||||
blueprint_params_metadata: The parameter metadata from the flow blueprint definition
|
||||
config_api: API client to retrieve parameter type definitions
|
||||
|
||||
Returns:
|
||||
|
|
@ -89,7 +89,7 @@ def format_parameters(flow_params, class_params_metadata, config_api):
|
|||
|
||||
# Sort parameters by order if available
|
||||
sorted_params = sorted(
|
||||
class_params_metadata.items(),
|
||||
blueprint_params_metadata.items(),
|
||||
key=lambda x: x[1].get("order", 999)
|
||||
)
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ def format_parameters(flow_params, class_params_metadata, config_api):
|
|||
if param_type and config_api:
|
||||
try:
|
||||
from trustgraph.api import ConfigKey
|
||||
key = ConfigKey("parameter-types", param_type)
|
||||
key = ConfigKey("parameter-type", param_type)
|
||||
type_def_value = config_api.get([key])[0].value
|
||||
param_type_def = json.loads(type_def_value)
|
||||
display_value = get_enum_description(value, param_type_def)
|
||||
|
|
@ -122,9 +122,9 @@ def format_parameters(flow_params, class_params_metadata, config_api):
|
|||
|
||||
param_list.append(line)
|
||||
|
||||
# Add any parameters that aren't in the class metadata (shouldn't happen normally)
|
||||
# Add any parameters that aren't in the blueprint metadata (shouldn't happen normally)
|
||||
for param_name, value in flow_params.items():
|
||||
if param_name not in class_params_metadata:
|
||||
if param_name not in blueprint_params_metadata:
|
||||
param_list.append(f"• {param_name}: {value} (undefined)")
|
||||
|
||||
return "\n".join(param_list) if param_list else "None"
|
||||
|
|
@ -135,7 +135,7 @@ def show_flows(url, token=None):
|
|||
config_api = api.config()
|
||||
flow_api = api.flow()
|
||||
|
||||
interface_names = config_api.list("interface-descriptions")
|
||||
interface_names = config_api.list("interface-description")
|
||||
|
||||
interface_defs = {
|
||||
i: get_interface(config_api, i)
|
||||
|
|
@ -156,24 +156,24 @@ def show_flows(url, token=None):
|
|||
|
||||
table = []
|
||||
table.append(("id", id))
|
||||
table.append(("class", flow.get("class-name", "")))
|
||||
table.append(("blueprint", flow.get("blueprint-name", "")))
|
||||
table.append(("desc", flow.get("description", "")))
|
||||
|
||||
# Display parameters with human-readable descriptions
|
||||
parameters = flow.get("parameters", {})
|
||||
if parameters:
|
||||
# Try to get the flow class definition for parameter metadata
|
||||
class_name = flow.get("class-name", "")
|
||||
if class_name:
|
||||
# Try to get the flow blueprint definition for parameter metadata
|
||||
blueprint_name = flow.get("blueprint-name", "")
|
||||
if blueprint_name:
|
||||
try:
|
||||
flow_class = flow_api.get_class(class_name)
|
||||
class_params_metadata = flow_class.get("parameters", {})
|
||||
param_str = format_parameters(parameters, class_params_metadata, config_api)
|
||||
flow_blueprint = flow_api.get_blueprint(blueprint_name)
|
||||
blueprint_params_metadata = flow_blueprint.get("parameters", {})
|
||||
param_str = format_parameters(parameters, blueprint_params_metadata, config_api)
|
||||
except Exception as e:
|
||||
# Fallback to JSON if we can't get the class definition
|
||||
# Fallback to JSON if we can't get the blueprint definition
|
||||
param_str = json.dumps(parameters, indent=2)
|
||||
else:
|
||||
# No class name, fallback to JSON
|
||||
# No blueprint name, fallback to JSON
|
||||
param_str = json.dumps(parameters, indent=2)
|
||||
|
||||
table.append(("parameters", param_str))
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ def show_parameter_types(url, token=None):
|
|||
|
||||
# Get list of all parameter types
|
||||
try:
|
||||
param_type_names = config_api.list("parameter-types")
|
||||
param_type_names = config_api.list("parameter-type")
|
||||
except Exception as e:
|
||||
print(f"Error retrieving parameter types: {e}")
|
||||
return
|
||||
|
|
@ -97,7 +97,7 @@ def show_parameter_types(url, token=None):
|
|||
for param_type_name in param_type_names:
|
||||
try:
|
||||
# Get the parameter type definition
|
||||
key = ConfigKey("parameter-types", param_type_name)
|
||||
key = ConfigKey("parameter-type", param_type_name)
|
||||
type_def_value = config_api.get([key])[0].value
|
||||
param_type_def = json.loads(type_def_value)
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ def show_specific_parameter_type(url, param_type_name, token=None):
|
|||
|
||||
try:
|
||||
# Get the parameter type definition
|
||||
key = ConfigKey("parameter-types", param_type_name)
|
||||
key = ConfigKey("parameter-type", param_type_name)
|
||||
type_def_value = config_api.get([key])[0].value
|
||||
param_type_def = json.loads(type_def_value)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ def show_config(url, token=None):
|
|||
|
||||
api = Api(url, token=token).config()
|
||||
|
||||
models = api.list("token-costs")
|
||||
models = api.list("token-cost")
|
||||
|
||||
costs = []
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ def show_config(url, token=None):
|
|||
|
||||
try:
|
||||
values = json.loads(api.get([
|
||||
ConfigKey(type="token-costs", key=model),
|
||||
ConfigKey(type="token-cost", key=model),
|
||||
])[0].value)
|
||||
costs.append((
|
||||
model,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Starts a processing flow using a defined flow class.
|
||||
Starts a processing flow using a defined flow blueprint.
|
||||
|
||||
Parameters can be provided in three ways:
|
||||
1. As key=value pairs: --param model=gpt-4 --param temp=0.7
|
||||
|
|
@ -19,12 +19,12 @@ import json
|
|||
default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
||||
|
||||
def start_flow(url, class_name, flow_id, description, parameters=None, token=None):
|
||||
def start_flow(url, blueprint_name, flow_id, description, parameters=None, token=None):
|
||||
|
||||
api = Api(url, token=token).flow()
|
||||
|
||||
api.start(
|
||||
class_name = class_name,
|
||||
blueprint_name = blueprint_name,
|
||||
id = flow_id,
|
||||
description = description,
|
||||
parameters = parameters,
|
||||
|
|
@ -50,9 +50,9 @@ def main():
|
|||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-n', '--class-name',
|
||||
'-n', '--blueprint-name',
|
||||
required=True,
|
||||
help=f'Flow class name',
|
||||
help=f'Flow blueprint name',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
|
|
@ -115,7 +115,7 @@ def main():
|
|||
|
||||
start_flow(
|
||||
url = args.api_url,
|
||||
class_name = args.class_name,
|
||||
blueprint_name = args.blueprint_name,
|
||||
flow_id = args.flow_id,
|
||||
description = args.description,
|
||||
parameters = parameters,
|
||||
|
|
|
|||
|
|
@ -194,21 +194,21 @@ def check_processors(url: str, min_processors: int, timeout: int, token: Optiona
|
|||
return False, f"Processor check error: {e}"
|
||||
|
||||
|
||||
def check_flow_classes(url: str, timeout: int, token: Optional[str] = None) -> Tuple[bool, str]:
|
||||
"""Check if flow classes are loaded."""
|
||||
def check_flow_blueprints(url: str, timeout: int, token: Optional[str] = None) -> Tuple[bool, str]:
|
||||
"""Check if flow blueprints are loaded."""
|
||||
try:
|
||||
api = Api(url, token=token, timeout=timeout)
|
||||
flow_api = api.flow()
|
||||
|
||||
classes = flow_api.list_classes()
|
||||
blueprints = flow_api.list_blueprints()
|
||||
|
||||
if classes and len(classes) > 0:
|
||||
return True, f"Found {len(classes)} flow class(es)"
|
||||
if blueprints and len(blueprints) > 0:
|
||||
return True, f"Found {len(blueprints)} flow blueprint(s)"
|
||||
else:
|
||||
return False, "No flow classes found"
|
||||
return False, "No flow blueprints found"
|
||||
|
||||
except Exception as e:
|
||||
return False, f"Flow classes check error: {e}"
|
||||
return False, f"Flow blueprints check error: {e}"
|
||||
|
||||
|
||||
def check_flows(url: str, timeout: int, token: Optional[str] = None) -> Tuple[bool, str]:
|
||||
|
|
@ -416,8 +416,8 @@ def main():
|
|||
)
|
||||
|
||||
checker.run_check(
|
||||
"Flow Classes",
|
||||
check_flow_classes,
|
||||
"Flow Blueprints",
|
||||
check_flow_blueprints,
|
||||
args.api_url,
|
||||
args.check_timeout,
|
||||
args.token
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue