mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-24 04:31:02 +02:00
Update tg-show-flows CLI
This commit is contained in:
parent
d0b9a18b74
commit
9a7d1f29fb
1 changed files with 43 additions and 12 deletions
|
|
@ -45,13 +45,38 @@ def describe_interfaces(intdefs, flow):
|
|||
|
||||
return "\n".join(lst)
|
||||
|
||||
def format_parameters(flow_params, class_params_metadata):
|
||||
def get_enum_description(param_value, param_type_def):
|
||||
"""
|
||||
Get the human-readable description for an enum value
|
||||
|
||||
Args:
|
||||
param_value: The actual parameter value (e.g., "gpt-4")
|
||||
param_type_def: The parameter type definition containing enum objects
|
||||
|
||||
Returns:
|
||||
Human-readable description or the original value if not found
|
||||
"""
|
||||
enum_list = param_type_def.get("enum", [])
|
||||
|
||||
# Handle both old format (strings) and new format (objects with id/description)
|
||||
for enum_item in enum_list:
|
||||
if isinstance(enum_item, dict):
|
||||
if enum_item.get("id") == param_value:
|
||||
return enum_item.get("description", param_value)
|
||||
elif enum_item == param_value:
|
||||
return param_value
|
||||
|
||||
# If not found in enum, return original value
|
||||
return param_value
|
||||
|
||||
def format_parameters(flow_params, class_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
|
||||
config_api: API client to retrieve parameter type definitions
|
||||
|
||||
Returns:
|
||||
Formatted string of parameters with descriptions
|
||||
|
|
@ -72,21 +97,27 @@ def format_parameters(flow_params, class_params_metadata):
|
|||
value = flow_params[param_name]
|
||||
description = param_meta.get("description", param_name)
|
||||
param_type = param_meta.get("type", "")
|
||||
advanced = param_meta.get("advanced", False)
|
||||
controlled_by = param_meta.get("controlled-by", None)
|
||||
|
||||
# Try to get enum description if this parameter has a type definition
|
||||
display_value = value
|
||||
if param_type and config_api:
|
||||
try:
|
||||
from trustgraph.api import ConfigKey
|
||||
key = ConfigKey("parameter-types", 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)
|
||||
except:
|
||||
# If we can't get the type definition, just use the original value
|
||||
display_value = value
|
||||
|
||||
# Format the parameter line
|
||||
line = f"• {description}: {value}"
|
||||
line = f"• {description}: {display_value}"
|
||||
|
||||
# Add metadata indicators
|
||||
indicators = []
|
||||
if advanced:
|
||||
indicators.append("advanced")
|
||||
# Add controlled-by indicator if present
|
||||
if controlled_by:
|
||||
indicators.append(f"controlled by {controlled_by}")
|
||||
|
||||
if indicators:
|
||||
line += f" ({', '.join(indicators)})"
|
||||
line += f" (controlled by {controlled_by})"
|
||||
|
||||
param_list.append(line)
|
||||
|
||||
|
|
@ -136,7 +167,7 @@ def show_flows(url):
|
|||
try:
|
||||
flow_class = flow_api.get_class(class_name)
|
||||
class_params_metadata = flow_class.get("parameters", {})
|
||||
param_str = format_parameters(parameters, class_params_metadata)
|
||||
param_str = format_parameters(parameters, class_params_metadata, config_api)
|
||||
except Exception as e:
|
||||
# Fallback to JSON if we can't get the class definition
|
||||
param_str = json.dumps(parameters, indent=2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue