Skip to content

Commit

Permalink
refactor: improve artifact type handling and result processing (#6002)
Browse files Browse the repository at this point in the history
🐛 (component.py): fix the logic to determine the artifact type based on raw data and status
🐛 (artifact.py): fix the default message assignment in post_process_raw function to ensure consistent behavior
  • Loading branch information
Cristhianzl authored Jan 29, 2025
1 parent 441bfed commit 7e756b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -957,19 +957,19 @@ def _build_artifact(self, result):
custom_repr = str(custom_repr)

raw = self._process_raw_result(result)
artifact_type = get_artifact_type(self.status or raw, result)
artifact_type = get_artifact_type(raw or self.status, result)
raw, artifact_type = post_process_raw(raw, artifact_type)
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"):
if 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
elif self.status:
raw = self.status
else:
raw = result
return raw
Expand Down
6 changes: 4 additions & 2 deletions src/backend/base/langflow/schema/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def _to_list_of_dicts(raw):


def post_process_raw(raw, artifact_type: str):
default_message = "Built Successfully ✨"

if artifact_type == ArtifactType.STREAM.value:
raw = ""
elif artifact_type == ArtifactType.ARRAY.value:
Expand All @@ -74,7 +76,7 @@ def post_process_raw(raw, artifact_type: str):
artifact_type = ArtifactType.OBJECT.value
except Exception: # noqa: BLE001
logger.opt(exception=True).debug(f"Error converting to json: {raw} ({type(raw)})")
raw = "Built Successfully ✨"
raw = default_message
else:
raw = "Built Successfully ✨"
raw = default_message
return raw, artifact_type

0 comments on commit 7e756b9

Please sign in to comment.