return artifact values into log to frontend

This commit is contained in:
italojohnny 2024-05-31 19:23:35 -03:00
commit d68e5a1143
3 changed files with 12 additions and 5 deletions

View file

@ -171,7 +171,7 @@ async def build_vertex(
result_dict,
params,
valid,
_,
artifacts,
vertex,
) = await graph.build_vertex(
lock=lock,
@ -181,20 +181,22 @@ async def build_vertex(
inputs_dict=inputs.model_dump() if inputs else {},
files=files,
)
log_obj = Log(message=vertex.artifacts_raw, type=vertex.artifacts_type)
result_data_response = ResultDataResponse(**result_dict.model_dump())
except Exception as exc:
logger.exception(f"Error building vertex: {exc}")
params = format_exception_message(exc)
valid = False
log_obj = Log(message=params, type="error")
result_data_response = ResultDataResponse(results={})
artifacts = {}
# If there's an error building the vertex
# we need to clear the cache
await chat_service.clear_cache(flow_id_str)
log_object = Log(message=log_message)
result_data_response.logs.append(log_object)
result_data_response.message = artifacts
result_data_response.logs.append(log_obj)
# Log the vertex build
if not vertex.will_stream:

View file

@ -245,7 +245,8 @@ class VerticesOrderResponse(BaseModel):
class Log(TypedDict):
message: str
message: Union[dict, str]
type: str
class ResultDataResponse(BaseModel):

View file

@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, Any, AsyncIterator, Callable, Dict, Iterator,
from loguru import logger
from langflow.graph.schema import INPUT_COMPONENTS, OUTPUT_COMPONENTS, InterfaceComponentTypes, ResultData
from langflow.graph.utils import UnbuiltObject, UnbuiltResult
from langflow.graph.utils import UnbuiltObject, UnbuiltResult, ArtifactType
from langflow.graph.vertex.utils import generate_result, log_transaction
from langflow.interface.initialize import loading
from langflow.interface.listing import lazy_load_dict
@ -63,6 +63,8 @@ class Vertex:
self._built_result = None
self._built = False
self.artifacts: Dict[str, Any] = {}
self.artifacts_raw: Any = None
self.artifacts_type: Optional[str] = None
self.steps: List[Callable] = [self._build]
self.steps_ran: List[Callable] = []
self.task_id: Optional[str] = None
@ -648,6 +650,8 @@ class Vertex:
self._built_object, self.artifacts = result
elif len(result) == 3:
self._custom_component, self._built_object, self.artifacts = result
self.artifacts_raw = self.artifacts.pop("raw", None)
self.artifacts_type = self.artifacts.pop("type", None) or ArtifactType.UNKNOWN.value
else:
self._built_object = result