refactor: Simplify _process_raw_result method in custom component processing (#6040)
* 🐛 (component.py): fix logic in _process_raw_result method to correctly extract data from result object based on conditions and return it * [autofix.ci] apply automated fixes * ♻️ (component.py): refactor extract_data method to improve readability and maintainability by using more descriptive variable names and simplifying the logic. * [autofix.ci] apply automated fixes * 🐛 (component.py): update isinstance check to use union type for better type handling --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
parent
0514d11d9c
commit
c2411d4c22
1 changed files with 13 additions and 10 deletions
|
|
@ -978,17 +978,20 @@ class Component(CustomComponent):
|
|||
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
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue