diff --git a/autogpt_platform/backend/backend/blocks/llm.py b/autogpt_platform/backend/backend/blocks/llm.py index d9a5d4691872..e2bdfd8c2485 100644 --- a/autogpt_platform/backend/backend/blocks/llm.py +++ b/autogpt_platform/backend/backend/blocks/llm.py @@ -320,7 +320,7 @@ def llm_call(input_data: AIStructuredResponseGeneratorBlock.Input) -> str: if output_name == "response": return output_data["response"] else: - raise output_data + raise RuntimeError(output_data) raise ValueError("Failed to get a response from the LLM.") def run(self, input_data: Input) -> BlockOutput: diff --git a/autogpt_platform/backend/backend/blocks/time_blocks.py b/autogpt_platform/backend/backend/blocks/time_blocks.py index 32d92964ab78..ad59a54f2a4e 100644 --- a/autogpt_platform/backend/backend/blocks/time_blocks.py +++ b/autogpt_platform/backend/backend/blocks/time_blocks.py @@ -23,7 +23,7 @@ def __init__(self): {"trigger": "Hello", "format": "{time}"}, ], test_output=[ - ("time", time.strftime("%H:%M:%S")), + ("time", lambda _: time.strftime("%H:%M:%S")), ], ) diff --git a/autogpt_platform/backend/backend/data/execution.py b/autogpt_platform/backend/backend/data/execution.py index 4ab9be025f14..8e3449dd5c68 100644 --- a/autogpt_platform/backend/backend/data/execution.py +++ b/autogpt_platform/backend/backend/data/execution.py @@ -396,19 +396,19 @@ def merge_execution_input(data: BlockInput) -> BlockInput: # Merge all input with _$_ into a single list. items = list(data.items()) - list_input: list[Any] = [] + for key, value in items: if LIST_SPLIT not in key: continue name, index = key.split(LIST_SPLIT) if not index.isdigit(): - list_input.append((name, value, 0)) - else: - list_input.append((name, value, int(index))) + raise ValueError(f"Invalid key: {key}, #{index} index must be an integer.") - for name, value, _ in sorted(list_input, key=lambda x: x[2]): data[name] = data.get(name, []) - data[name].append(value) + if int(index) >= len(data[name]): + # Pad list with empty string on missing indices. + data[name].extend([""] * (int(index) - len(data[name]) + 1)) + data[name][int(index)] = value # Merge all input with _#_ into a single dict. for key, value in items: diff --git a/autogpt_platform/backend/backend/executor/manager.py b/autogpt_platform/backend/backend/executor/manager.py index 257d4cc8260f..c52086de6b9a 100644 --- a/autogpt_platform/backend/backend/executor/manager.py +++ b/autogpt_platform/backend/backend/executor/manager.py @@ -69,20 +69,28 @@ def __init__( self.prefix = f"[ExecutionManager|uid:{user_id}|gid:{graph_id}|nid:{node_id}]|geid:{graph_eid}|nid:{node_eid}|{block_name}]" def info(self, msg: str, **extra): + msg = self._wrap(msg, **extra) logger.info(msg, extra={"json_fields": {**self.metadata, **extra}}) def warning(self, msg: str, **extra): + msg = self._wrap(msg, **extra) logger.warning(msg, extra={"json_fields": {**self.metadata, **extra}}) def error(self, msg: str, **extra): + msg = self._wrap(msg, **extra) logger.error(msg, extra={"json_fields": {**self.metadata, **extra}}) def debug(self, msg: str, **extra): + msg = self._wrap(msg, **extra) logger.debug(msg, extra={"json_fields": {**self.metadata, **extra}}) def exception(self, msg: str, **extra): + msg = self._wrap(msg, **extra) logger.exception(msg, extra={"json_fields": {**self.metadata, **extra}}) + def _wrap(self, msg: str, **extra): + return f"{self.prefix} {msg} {extra}" + T = TypeVar("T") ExecutionStream = Generator[NodeExecution, None, None] diff --git a/autogpt_platform/frontend/src/lib/utils.ts b/autogpt_platform/frontend/src/lib/utils.ts index 053724599d3d..8852dc4f42a1 100644 --- a/autogpt_platform/frontend/src/lib/utils.ts +++ b/autogpt_platform/frontend/src/lib/utils.ts @@ -152,13 +152,13 @@ export function setNestedProperty(obj: any, path: string, value: any) { export function removeEmptyStringsAndNulls(obj: any): any { if (Array.isArray(obj)) { - // If obj is an array, recursively remove empty strings and nulls from its elements - return obj - .map((item) => removeEmptyStringsAndNulls(item)) - .filter( - (item) => - item !== null && (typeof item !== "string" || item.trim() !== ""), - ); + // If obj is an array, recursively check each element, + // but element removal is avoided to prevent index changes. + return obj.map((item) => + item === undefined || item === null + ? "" + : removeEmptyStringsAndNulls(item), + ); } else if (typeof obj === "object" && obj !== null) { // If obj is an object, recursively remove empty strings and nulls from its properties for (const key in obj) { @@ -166,7 +166,8 @@ export function removeEmptyStringsAndNulls(obj: any): any { const value = obj[key]; if ( value === null || - (typeof value === "string" && value.trim() === "") + value === undefined || + (typeof value === "string" && value === "") ) { delete obj[key]; } else {