mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-20 18:51:03 +02:00
Flow class -> flow blueprint
This commit is contained in:
parent
7672815349
commit
ba45b59f7b
4 changed files with 38 additions and 38 deletions
|
|
@ -28,42 +28,42 @@ class Flow:
|
||||||
def id(self, id="default"):
|
def id(self, id="default"):
|
||||||
return FlowInstance(api=self, id=id)
|
return FlowInstance(api=self, id=id)
|
||||||
|
|
||||||
def list_classes(self):
|
def list_blueprints(self):
|
||||||
|
|
||||||
# The input consists of system and prompt strings
|
# The input consists of system and prompt strings
|
||||||
input = {
|
input = {
|
||||||
"operation": "list-classes",
|
"operation": "list-blueprints",
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.request(request = input)["class-names"]
|
return self.request(request = input)["blueprint-names"]
|
||||||
|
|
||||||
def get_class(self, class_name):
|
def get_blueprint(self, blueprint_name):
|
||||||
|
|
||||||
# The input consists of system and prompt strings
|
# The input consists of system and prompt strings
|
||||||
input = {
|
input = {
|
||||||
"operation": "get-class",
|
"operation": "get-blueprint",
|
||||||
"class-name": class_name,
|
"blueprint-name": blueprint_name,
|
||||||
}
|
}
|
||||||
|
|
||||||
return json.loads(self.request(request = input)["class-definition"])
|
return json.loads(self.request(request = input)["blueprint-definition"])
|
||||||
|
|
||||||
def put_class(self, class_name, definition):
|
def put_blueprint(self, blueprint_name, definition):
|
||||||
|
|
||||||
# The input consists of system and prompt strings
|
# The input consists of system and prompt strings
|
||||||
input = {
|
input = {
|
||||||
"operation": "put-class",
|
"operation": "put-blueprint",
|
||||||
"class-name": class_name,
|
"blueprint-name": blueprint_name,
|
||||||
"class-definition": json.dumps(definition),
|
"blueprint-definition": json.dumps(definition),
|
||||||
}
|
}
|
||||||
|
|
||||||
self.request(request = input)
|
self.request(request = input)
|
||||||
|
|
||||||
def delete_class(self, class_name):
|
def delete_blueprint(self, blueprint_name):
|
||||||
|
|
||||||
# The input consists of system and prompt strings
|
# The input consists of system and prompt strings
|
||||||
input = {
|
input = {
|
||||||
"operation": "delete-class",
|
"operation": "delete-blueprint",
|
||||||
"class-name": class_name,
|
"blueprint-name": blueprint_name,
|
||||||
}
|
}
|
||||||
|
|
||||||
self.request(request = input)
|
self.request(request = input)
|
||||||
|
|
@ -87,13 +87,13 @@ class Flow:
|
||||||
|
|
||||||
return json.loads(self.request(request = input)["flow"])
|
return json.loads(self.request(request = input)["flow"])
|
||||||
|
|
||||||
def start(self, class_name, id, description, parameters=None):
|
def start(self, blueprint_name, id, description, parameters=None):
|
||||||
|
|
||||||
# The input consists of system and prompt strings
|
# The input consists of system and prompt strings
|
||||||
input = {
|
input = {
|
||||||
"operation": "start-flow",
|
"operation": "start-flow",
|
||||||
"flow-id": id,
|
"flow-id": id,
|
||||||
"class-name": class_name,
|
"blueprint-name": blueprint_name,
|
||||||
"description": description,
|
"description": description,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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:
|
Parameters can be provided in three ways:
|
||||||
1. As key=value pairs: --param model=gpt-4 --param temp=0.7
|
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_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/')
|
||||||
default_token = os.getenv("TRUSTGRAPH_TOKEN", None)
|
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 = Api(url, token=token).flow()
|
||||||
|
|
||||||
api.start(
|
api.start(
|
||||||
class_name = class_name,
|
blueprint_name = blueprint_name,
|
||||||
id = flow_id,
|
id = flow_id,
|
||||||
description = description,
|
description = description,
|
||||||
parameters = parameters,
|
parameters = parameters,
|
||||||
|
|
@ -50,9 +50,9 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-n', '--class-name',
|
'-n', '--blueprint-name',
|
||||||
required=True,
|
required=True,
|
||||||
help=f'Flow class name',
|
help=f'Flow blueprint name',
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|
@ -115,7 +115,7 @@ def main():
|
||||||
|
|
||||||
start_flow(
|
start_flow(
|
||||||
url = args.api_url,
|
url = args.api_url,
|
||||||
class_name = args.class_name,
|
blueprint_name = args.blueprint_name,
|
||||||
flow_id = args.flow_id,
|
flow_id = args.flow_id,
|
||||||
description = args.description,
|
description = args.description,
|
||||||
parameters = parameters,
|
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}"
|
return False, f"Processor check error: {e}"
|
||||||
|
|
||||||
|
|
||||||
def check_flow_classes(url: str, timeout: int, token: Optional[str] = None) -> Tuple[bool, str]:
|
def check_flow_blueprints(url: str, timeout: int, token: Optional[str] = None) -> Tuple[bool, str]:
|
||||||
"""Check if flow classes are loaded."""
|
"""Check if flow blueprints are loaded."""
|
||||||
try:
|
try:
|
||||||
api = Api(url, token=token, timeout=timeout)
|
api = Api(url, token=token, timeout=timeout)
|
||||||
flow_api = api.flow()
|
flow_api = api.flow()
|
||||||
|
|
||||||
classes = flow_api.list_classes()
|
blueprints = flow_api.list_blueprints()
|
||||||
|
|
||||||
if classes and len(classes) > 0:
|
if blueprints and len(blueprints) > 0:
|
||||||
return True, f"Found {len(classes)} flow class(es)"
|
return True, f"Found {len(blueprints)} flow blueprint(s)"
|
||||||
else:
|
else:
|
||||||
return False, "No flow classes found"
|
return False, "No flow blueprints found"
|
||||||
|
|
||||||
except Exception as e:
|
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]:
|
def check_flows(url: str, timeout: int, token: Optional[str] = None) -> Tuple[bool, str]:
|
||||||
|
|
@ -416,8 +416,8 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
checker.run_check(
|
checker.run_check(
|
||||||
"Flow Classes",
|
"Flow Blueprints",
|
||||||
check_flow_classes,
|
check_flow_blueprints,
|
||||||
args.api_url,
|
args.api_url,
|
||||||
args.check_timeout,
|
args.check_timeout,
|
||||||
args.token
|
args.token
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ class FlowConfig:
|
||||||
|
|
||||||
async def handle_list_blueprints(self, msg):
|
async def handle_list_blueprints(self, msg):
|
||||||
|
|
||||||
names = list(await self.config.get("flow-blueprints").keys())
|
names = list(await self.config.get("flow-blueprint").keys())
|
||||||
|
|
||||||
return FlowResponse(
|
return FlowResponse(
|
||||||
error = None,
|
error = None,
|
||||||
|
|
@ -114,13 +114,13 @@ class FlowConfig:
|
||||||
return FlowResponse(
|
return FlowResponse(
|
||||||
error = None,
|
error = None,
|
||||||
blueprint_definition = await self.config.get(
|
blueprint_definition = await self.config.get(
|
||||||
"flow-blueprints"
|
"flow-blueprint"
|
||||||
).get(msg.blueprint_name),
|
).get(msg.blueprint_name),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def handle_put_blueprint(self, msg):
|
async def handle_put_blueprint(self, msg):
|
||||||
|
|
||||||
await self.config.get("flow-blueprints").put(
|
await self.config.get("flow-blueprint").put(
|
||||||
msg.blueprint_name, msg.blueprint_definition
|
msg.blueprint_name, msg.blueprint_definition
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -136,7 +136,7 @@ class FlowConfig:
|
||||||
|
|
||||||
logger.debug(f"Flow config message: {msg}")
|
logger.debug(f"Flow config message: {msg}")
|
||||||
|
|
||||||
await self.config.get("flow-blueprints").delete(msg.blueprint_name)
|
await self.config.get("flow-blueprint").delete(msg.blueprint_name)
|
||||||
|
|
||||||
await self.config.inc_version()
|
await self.config.inc_version()
|
||||||
|
|
||||||
|
|
@ -181,11 +181,11 @@ class FlowConfig:
|
||||||
if msg.description is None:
|
if msg.description is None:
|
||||||
raise RuntimeError("No description")
|
raise RuntimeError("No description")
|
||||||
|
|
||||||
if msg.blueprint_name not in await self.config.get("flow-blueprints").keys():
|
if msg.blueprint_name not in await self.config.get("flow-blueprint").keys():
|
||||||
raise RuntimeError("Blueprint does not exist")
|
raise RuntimeError("Blueprint does not exist")
|
||||||
|
|
||||||
cls = json.loads(
|
cls = json.loads(
|
||||||
await self.config.get("flow-blueprints").get(msg.blueprint_name)
|
await self.config.get("flow-blueprint").get(msg.blueprint_name)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Resolve parameters by merging user-provided values with defaults
|
# Resolve parameters by merging user-provided values with defaults
|
||||||
|
|
@ -292,7 +292,7 @@ class FlowConfig:
|
||||||
blueprint_name = flow["blueprint-name"]
|
blueprint_name = flow["blueprint-name"]
|
||||||
parameters = flow.get("parameters", {})
|
parameters = flow.get("parameters", {})
|
||||||
|
|
||||||
cls = json.loads(await self.config.get("flow-blueprints").get(blueprint_name))
|
cls = json.loads(await self.config.get("flow-blueprint").get(blueprint_name))
|
||||||
|
|
||||||
def repl_template(tmp):
|
def repl_template(tmp):
|
||||||
result = tmp.replace(
|
result = tmp.replace(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue