📝 (loading.py): Update the logic in build_custom_component function to handle cases where raw is None and improve artifact_type assignment for better accuracy
📝 (chat.py): Remove commented out code related to logs in build_vertex function for better code readability 📝 (schemas.py): Change the type of logs field in ResultDataResponse class to be a dictionary with string keys and Log values for consistency 📝 (schema.py): Refactor build_logs_from_artifacts function to use a dictionary instead of defaultdict for logs variable for simplicity and consistency
This commit is contained in:
parent
ccb9ba3307
commit
1774fdebe6
4 changed files with 6 additions and 12 deletions
|
|
@ -181,13 +181,6 @@ async def build_vertex(
|
|||
inputs_dict=inputs.model_dump() if inputs else {},
|
||||
files=files,
|
||||
)
|
||||
# logs = {}
|
||||
# if isinstance(vertex.artifacts_raw, dict):
|
||||
# for key in vertex.artifacts_raw:
|
||||
# log_obj = Log(message=vertex.artifacts_raw[key], type=vertex.artifacts_type[key])
|
||||
# logs[key] = log_obj
|
||||
# else:
|
||||
# logs = [Log(message=vertex.artifacts_raw, type=vertex.artifacts_type)]
|
||||
|
||||
result_data_response = ResultDataResponse.model_validate(result_dict, from_attributes=True)
|
||||
except Exception as exc:
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ class VerticesOrderResponse(BaseModel):
|
|||
|
||||
class ResultDataResponse(BaseModel):
|
||||
results: Optional[Any] = Field(default_factory=dict)
|
||||
logs: dict[str, List[Log] | Log] = Field(default_factory=dict)
|
||||
logs: dict[str, Log] = Field(default_factory=dict)
|
||||
message: Optional[Any] = Field(default_factory=dict)
|
||||
artifacts: Optional[Any] = Field(default_factory=dict)
|
||||
timedelta: Optional[float] = None
|
||||
|
|
|
|||
|
|
@ -157,8 +157,10 @@ async def build_custom_component(params: dict, custom_component: "CustomComponen
|
|||
|
||||
elif hasattr(raw, "model_dump") and raw is not None:
|
||||
raw = raw.model_dump()
|
||||
if raw is None and isinstance(build_result, (dict, Data, str)):
|
||||
raw = build_result.data if isinstance(build_result, Data) else build_result
|
||||
|
||||
artifact_type = get_artifact_type(custom_component.repr_value, build_result)
|
||||
artifact_type = get_artifact_type(custom_component.repr_value or raw, build_result)
|
||||
raw = post_process_raw(raw, artifact_type)
|
||||
artifact = {"repr": custom_repr, "raw": raw, "type": artifact_type}
|
||||
return custom_component, build_result, artifact
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
from collections import defaultdict
|
||||
from typing import Any, Literal
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
|
@ -19,7 +18,7 @@ class Log(TypedDict):
|
|||
|
||||
|
||||
def build_logs_from_artifacts(artifacts: dict) -> dict:
|
||||
logs = defaultdict(list)
|
||||
logs = {}
|
||||
for key in artifacts:
|
||||
message = artifacts[key]["raw"]
|
||||
_type = artifacts[key]["type"]
|
||||
|
|
@ -33,7 +32,7 @@ def build_logs_from_artifacts(artifacts: dict) -> dict:
|
|||
elif _type:
|
||||
log = Log(message=message, type=_type)
|
||||
|
||||
logs[key].append(log)
|
||||
logs[key] = log
|
||||
return logs
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue