From 263f4d2abf4d27bd2a7f762894269f335ad2caae Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Fri, 31 Jan 2025 11:34:43 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20(component.py):=20fix=20logic=20?= =?UTF-8?q?in=20=5Fprocess=5Fraw=5Fresult=20method=20to=20correctly=20extr?= =?UTF-8?q?act=20data=20from=20result=20object=20based=20on=20conditions?= =?UTF-8?q?=20and=20return=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom/custom_component/component.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/backend/base/langflow/custom/custom_component/component.py b/src/backend/base/langflow/custom/custom_component/component.py index 82673419a2e4..b44e9f806fc4 100644 --- a/src/backend/base/langflow/custom/custom_component/component.py +++ b/src/backend/base/langflow/custom/custom_component/component.py @@ -978,17 +978,20 @@ def _build_artifact(self, result): return {"repr": custom_repr, "raw": raw, "type": artifact_type} def _process_raw_result(self, result): - if self.status: - raw = self.status - elif hasattr(result, "data"): - raw = result.data - elif hasattr(result, "model_dump"): - raw = result.model_dump() - elif isinstance(result, dict | Data | str): - raw = result.data if isinstance(result, Data) else result - else: - raw = result - return raw + if len(self.outputs) == 1: + return self.status or self.extract_data(result) + return self.extract_data(result) + + def extract_data(self, r): + if hasattr(r, "data"): + return r.data + elif hasattr(r, "model_dump"): + return r.model_dump() + elif isinstance(r, (Data, dict, str)): + return r.data if isinstance(r, Data) else r + elif self.status: + return self.status + return r def _log_output(self, output): self._output_logs[output.name] = self._logs