Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(backend): Introduced Graph Input & Output Schema, Merge GraphMeta & Graph, Remove subgraph functionality #8526

Merged
merged 11 commits into from
Nov 7, 2024
29 changes: 15 additions & 14 deletions autogpt_platform/backend/backend/blocks/branching.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,18 @@ def __init__(self):
)

def run(self, input_data: Input, **kwargs) -> BlockOutput:
majdyz marked this conversation as resolved.
Show resolved Hide resolved
value1 = input_data.value1
operator = input_data.operator

value1 = input_data.value1
if isinstance(value1, str):
value1 = float(value1.strip())

value2 = input_data.value2
if isinstance(value2, str):
value2 = float(value2.strip())

yes_value = input_data.yes_value if input_data.yes_value is not None else value1
no_value = input_data.no_value if input_data.no_value is not None else value1
no_value = input_data.no_value if input_data.no_value is not None else value2

comparison_funcs = {
ComparisonOperator.EQUAL: lambda a, b: a == b,
Expand All @@ -86,17 +93,11 @@ def run(self, input_data: Input, **kwargs) -> BlockOutput:
ComparisonOperator.LESS_THAN_OR_EQUAL: lambda a, b: a <= b,
}

try:
result = comparison_funcs[operator](value1, value2)

yield "result", result
result = comparison_funcs[operator](value1, value2)

if result:
yield "yes_output", yes_value
else:
yield "no_output", no_value
yield "result", result

except Exception:
yield "result", None
yield "yes_output", None
yield "no_output", None
if result:
yield "yes_output", yes_value
else:
yield "no_output", no_value
41 changes: 4 additions & 37 deletions autogpt_platform/backend/backend/data/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
AgentNodeExecution,
AgentNodeExecutionInputOutput,
)
from prisma.types import (
AgentGraphExecutionInclude,
AgentGraphExecutionWhereInput,
AgentNodeExecutionInclude,
)
from prisma.types import AgentGraphExecutionWhereInput
from pydantic import BaseModel

from backend.data.block import BlockData, BlockInput, CompletedBlockOutput
from backend.data.includes import EXECUTION_RESULT_INCLUDE, GRAPH_EXECUTION_INCLUDE
from backend.util import json, mock


Expand Down Expand Up @@ -110,24 +107,6 @@ def from_db(execution: AgentNodeExecution):

# --------------------- Model functions --------------------- #

EXECUTION_RESULT_INCLUDE: AgentNodeExecutionInclude = {
"Input": True,
"Output": True,
"AgentNode": True,
"AgentGraphExecution": True,
}

GRAPH_EXECUTION_INCLUDE: AgentGraphExecutionInclude = {
"AgentNodeExecutions": {
"include": {
"Input": True,
"Output": True,
"AgentNode": True,
"AgentGraphExecution": True,
}
}
}


async def create_graph_execution(
graph_id: str,
Expand Down Expand Up @@ -268,21 +247,9 @@ async def update_graph_execution_start_time(graph_exec_id: str):

async def update_graph_execution_stats(
graph_exec_id: str,
error: Exception | None,
wall_time: float,
cpu_time: float,
node_count: int,
stats: dict[str, Any],
):
status = ExecutionStatus.FAILED if error else ExecutionStatus.COMPLETED
stats = (
{
"walltime": wall_time,
"cputime": cpu_time,
"nodecount": node_count,
"error": str(error) if error else None,
},
)

status = ExecutionStatus.FAILED if stats.get("error") else ExecutionStatus.COMPLETED
await AgentGraphExecution.prisma().update(
where={"id": graph_exec_id},
data={
Expand Down
Loading
Loading