refactor: improve artifact type handling and result processing (#6002)
🐛 (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
This commit is contained in:
parent
441bfed03b
commit
7e756b9db5
2 changed files with 8 additions and 6 deletions
|
|
@ -957,19 +957,19 @@ class Component(CustomComponent):
|
||||||
custom_repr = str(custom_repr)
|
custom_repr = str(custom_repr)
|
||||||
|
|
||||||
raw = self._process_raw_result(result)
|
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)
|
raw, artifact_type = post_process_raw(raw, artifact_type)
|
||||||
return {"repr": custom_repr, "raw": raw, "type": artifact_type}
|
return {"repr": custom_repr, "raw": raw, "type": artifact_type}
|
||||||
|
|
||||||
def _process_raw_result(self, result):
|
def _process_raw_result(self, result):
|
||||||
if self.status:
|
if hasattr(result, "data"):
|
||||||
raw = self.status
|
|
||||||
elif hasattr(result, "data"):
|
|
||||||
raw = result.data
|
raw = result.data
|
||||||
elif hasattr(result, "model_dump"):
|
elif hasattr(result, "model_dump"):
|
||||||
raw = result.model_dump()
|
raw = result.model_dump()
|
||||||
elif isinstance(result, dict | Data | str):
|
elif isinstance(result, dict | Data | str):
|
||||||
raw = result.data if isinstance(result, Data) else result
|
raw = result.data if isinstance(result, Data) else result
|
||||||
|
elif self.status:
|
||||||
|
raw = self.status
|
||||||
else:
|
else:
|
||||||
raw = result
|
raw = result
|
||||||
return raw
|
return raw
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,8 @@ def _to_list_of_dicts(raw):
|
||||||
|
|
||||||
|
|
||||||
def post_process_raw(raw, artifact_type: str):
|
def post_process_raw(raw, artifact_type: str):
|
||||||
|
default_message = "Built Successfully ✨"
|
||||||
|
|
||||||
if artifact_type == ArtifactType.STREAM.value:
|
if artifact_type == ArtifactType.STREAM.value:
|
||||||
raw = ""
|
raw = ""
|
||||||
elif artifact_type == ArtifactType.ARRAY.value:
|
elif artifact_type == ArtifactType.ARRAY.value:
|
||||||
|
|
@ -74,7 +76,7 @@ def post_process_raw(raw, artifact_type: str):
|
||||||
artifact_type = ArtifactType.OBJECT.value
|
artifact_type = ArtifactType.OBJECT.value
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
logger.opt(exception=True).debug(f"Error converting to json: {raw} ({type(raw)})")
|
logger.opt(exception=True).debug(f"Error converting to json: {raw} ({type(raw)})")
|
||||||
raw = "Built Successfully ✨"
|
raw = default_message
|
||||||
else:
|
else:
|
||||||
raw = "Built Successfully ✨"
|
raw = default_message
|
||||||
return raw, artifact_type
|
return raw, artifact_type
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue