Skip to content

feat: add logs field to ResultData and Vertex class #2732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 16, 2024
2 changes: 2 additions & 0 deletions src/backend/base/langflow/api/v1/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from langflow.services.database.models.base import orjson_dumps
from langflow.services.database.models.flow import FlowCreate, FlowRead
from langflow.services.database.models.user import UserRead
from langflow.services.tracing.schema import Log


class BuildStatus(Enum):
Expand Down Expand Up @@ -251,6 +252,7 @@ class VerticesOrderResponse(BaseModel):
class ResultDataResponse(BaseModel):
results: Optional[Any] = Field(default_factory=dict)
outputs: dict[str, OutputLog] = 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
Expand Down
1 change: 1 addition & 0 deletions src/backend/base/langflow/graph/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ResultData(BaseModel):
results: Optional[Any] = Field(default_factory=dict)
artifacts: Optional[Any] = Field(default_factory=dict)
outputs: Optional[dict] = Field(default_factory=dict)
logs: Optional[dict] = Field(default_factory=dict)
messages: Optional[list[ChatOutputResponse]] = Field(default_factory=list)
timedelta: Optional[float] = None
duration: Optional[str] = None
Expand Down
5 changes: 5 additions & 0 deletions src/backend/base/langflow/graph/vertex/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from langflow.schema.schema import INPUT_FIELD_NAME, OutputLog, build_output_logs
from langflow.services.deps import get_storage_service
from langflow.services.monitor.utils import log_transaction
from langflow.services.tracing.schema import Log
from langflow.utils.constants import DIRECT_TYPES
from langflow.utils.schemas import ChatOutputResponse
from langflow.utils.util import sync_to_async, unescape_string
Expand Down Expand Up @@ -83,6 +84,7 @@ def __init__(
self.result: Optional[ResultData] = None
self.results: Dict[str, Any] = {}
self.outputs_logs: Dict[str, OutputLog] = {}
self.logs: Dict[str, Log] = {}
try:
self.is_interface_component = self.vertex_type in InterfaceComponentTypes
except ValueError:
Expand Down Expand Up @@ -480,6 +482,7 @@ def _finalize_build(self):
results=result_dict,
artifacts=artifacts,
outputs=self.outputs_logs,
logs=self.logs,
messages=messages,
component_display_name=self.display_name,
component_id=self.id,
Expand Down Expand Up @@ -643,6 +646,7 @@ async def _get_and_instantiate_class(self, user_id=None, fallback_to_env_vars=Fa
vertex=self,
)
self.outputs_logs = build_output_logs(self, result)

self._update_built_object_and_artifacts(result)
except Exception as exc:
tb = traceback.format_exc()
Expand All @@ -658,6 +662,7 @@ def _update_built_object_and_artifacts(self, result):
self._built_object, self.artifacts = result
elif len(result) == 3:
self._custom_component, self._built_object, self.artifacts = result
self.logs = self._custom_component._logs
self.artifacts_raw = self.artifacts.get("raw", None)
self.artifacts_type = self.artifacts.get("type", None) or ArtifactType.UNKNOWN.value
self.artifacts = {self.outputs[0]["name"]: self.artifacts}
Expand Down
Loading