From a562ae5b0b1373449e57ff231c8db7e6fa89314a Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Wed, 12 Jun 2024 17:36:25 -0300 Subject: [PATCH] refactor: Update logs field type in ResultDataResponse schema --- src/backend/base/langflow/graph/graph/base.py | 1 + src/backend/base/langflow/graph/vertex/base.py | 8 +++++++- src/backend/base/langflow/graph/vertex/types.py | 3 +-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/backend/base/langflow/graph/graph/base.py b/src/backend/base/langflow/graph/graph/base.py index 8420adb19..86dd2a08c 100644 --- a/src/backend/base/langflow/graph/graph/base.py +++ b/src/backend/base/langflow/graph/graph/base.py @@ -4,6 +4,7 @@ from collections import defaultdict, deque from functools import partial from itertools import chain from typing import TYPE_CHECKING, Callable, Coroutine, Dict, Generator, List, Optional, Tuple, Type, Union + from loguru import logger from langflow.graph.edge.base import ContractEdge diff --git a/src/backend/base/langflow/graph/vertex/base.py b/src/backend/base/langflow/graph/vertex/base.py index 1b15fcccd..cf825202b 100644 --- a/src/backend/base/langflow/graph/vertex/base.py +++ b/src/backend/base/langflow/graph/vertex/base.py @@ -13,7 +13,7 @@ from langflow.graph.utils import UnbuiltObject, UnbuiltResult from langflow.interface.initialize import loading from langflow.interface.listing import lazy_load_dict from langflow.schema.artifact import ArtifactType -from langflow.schema.schema import INPUT_FIELD_NAME +from langflow.schema.schema import INPUT_FIELD_NAME, Log, build_log_from_raw_and_type from langflow.services.deps import get_storage_service from langflow.services.monitor.utils import log_transaction from langflow.utils.constants import DIRECT_TYPES @@ -77,6 +77,7 @@ class Vertex: self.layer = None self.result: Optional[ResultData] = None self.results: Dict[str, Any] = {} + self.logs: Dict[str, List[Log]] = {} try: self.is_interface_component = self.vertex_type in InterfaceComponentTypes except ValueError: @@ -481,6 +482,7 @@ class Vertex: result_dict = ResultData( results=result_dict, artifacts=artifacts, + logs=self.logs, messages=messages, component_display_name=self.display_name, component_id=self.id, @@ -660,6 +662,10 @@ class Vertex: self._custom_component, self._built_object, self.artifacts = result self.artifacts_raw = self.artifacts.get("raw", None) self.artifacts_type = self.artifacts.get("type", None) or ArtifactType.UNKNOWN.value + self.logs[self.outputs[0]["name"]] = build_log_from_raw_and_type( + self.artifacts_raw, self.artifacts_type + ) + else: self._built_object = result diff --git a/src/backend/base/langflow/graph/vertex/types.py b/src/backend/base/langflow/graph/vertex/types.py index e745d3aea..674247af5 100644 --- a/src/backend/base/langflow/graph/vertex/types.py +++ b/src/backend/base/langflow/graph/vertex/types.py @@ -10,7 +10,7 @@ from langflow.graph.utils import UnbuiltObject, serialize_field from langflow.graph.vertex.base import Vertex from langflow.schema import Record from langflow.schema.artifact import ArtifactType -from langflow.schema.schema import INPUT_FIELD_NAME, Log, build_logs_from_artifacts +from langflow.schema.schema import INPUT_FIELD_NAME, build_logs_from_artifacts from langflow.services.monitor.utils import log_transaction, log_vertex_build from langflow.utils.schemas import ChatOutputResponse, RecordOutputResponse from langflow.utils.util import unescape_string @@ -22,7 +22,6 @@ if TYPE_CHECKING: class CustomComponentVertex(Vertex): def __init__(self, data: Dict, graph): super().__init__(data, graph=graph, base_type="custom_components") - self.logs: Dict[str, Log] = {} def _built_object_repr(self): if self.artifacts and "repr" in self.artifacts: