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: Simplify _process_raw_result method in custom component processing #6040

Merged
merged 6 commits into from
Jan 31, 2025
23 changes: 13 additions & 10 deletions src/backend/base/langflow/custom/custom_component/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 len(self.outputs) == 1:
return self.status or self.extract_data(result)
return self.extract_data(result)

def extract_data(self, result):
if hasattr(result, "data"):
return result.data
Cristhianzl marked this conversation as resolved.
Show resolved Hide resolved
if hasattr(result, "model_dump"):
return result.model_dump()
if isinstance(result, Data | dict | str):
return result.data if isinstance(result, Data) else 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
return self.status
return result

def _log_output(self, output):
self._output_logs[output.name] = self._logs
Expand Down
Loading