refactor: Update logs to outputs in ComponentVertex and ResultDataResponse classes
This commit is contained in:
parent
1c6047b269
commit
36681d2d34
7 changed files with 23 additions and 23 deletions
|
|
@ -25,7 +25,7 @@ from langflow.api.v1.schemas import (
|
|||
VerticesOrderResponse,
|
||||
)
|
||||
from langflow.exceptions.component import ComponentBuildException
|
||||
from langflow.schema.schema import Log
|
||||
from langflow.schema.schema import OutputLog
|
||||
from langflow.services.auth.utils import get_current_active_user
|
||||
from langflow.services.chat.service import ChatService
|
||||
from langflow.services.deps import get_chat_service, get_session, get_session_service
|
||||
|
|
@ -199,8 +199,8 @@ async def build_vertex(
|
|||
message = {"errorMessage": params, "stackTrace": tb}
|
||||
valid = False
|
||||
output_label = vertex.outputs[0]["name"] if vertex.outputs else "output"
|
||||
logs = {output_label: Log(message=message, type="error")}
|
||||
result_data_response = ResultDataResponse(results={}, logs=logs)
|
||||
outputs = {output_label: OutputLog(message=message, type="error")}
|
||||
result_data_response = ResultDataResponse(results={}, outputs=outputs)
|
||||
artifacts = {}
|
||||
background_tasks.add_task(graph.end_all_traces, error=message["errorMessage"])
|
||||
# If there's an error building the vertex
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from pydantic import BaseModel, ConfigDict, Field, field_validator, model_serial
|
|||
from langflow.graph.schema import RunOutputs
|
||||
from langflow.schema import dotdict
|
||||
from langflow.schema.graph import Tweaks
|
||||
from langflow.schema.schema import InputType, Log, OutputType
|
||||
from langflow.schema.schema import InputType, OutputLog, OutputType
|
||||
from langflow.services.database.models.api_key.model import ApiKeyRead
|
||||
from langflow.services.database.models.base import orjson_dumps
|
||||
from langflow.services.database.models.flow import FlowCreate, FlowRead
|
||||
|
|
@ -245,7 +245,7 @@ class VerticesOrderResponse(BaseModel):
|
|||
|
||||
class ResultDataResponse(BaseModel):
|
||||
results: Optional[Any] = Field(default_factory=dict)
|
||||
logs: dict[str, Log] = Field(default_factory=dict)
|
||||
outputs: dict[str, OutputLog] = Field(default_factory=dict)
|
||||
message: Optional[Any] = Field(default_factory=dict)
|
||||
artifacts: Optional[Any] = Field(default_factory=dict)
|
||||
timedelta: Optional[float] = None
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from langflow.schema import Data
|
|||
from langflow.schema.artifact import get_artifact_type
|
||||
from langflow.schema.dotdict import dotdict
|
||||
from langflow.schema.message import Message
|
||||
from langflow.schema.schema import Log
|
||||
from langflow.schema.schema import OutputLog
|
||||
from langflow.services.deps import get_storage_service, get_variable_service, session_scope
|
||||
from langflow.services.storage.service import StorageService
|
||||
from langflow.type_extraction.type_extraction import (
|
||||
|
|
@ -82,7 +82,7 @@ class CustomComponent(BaseComponent):
|
|||
status: Optional[Any] = None
|
||||
"""The status of the component. This is displayed on the frontend. Defaults to None."""
|
||||
_flows_data: Optional[List[Data]] = None
|
||||
_logs: List[Log] = []
|
||||
_logs: List[OutputLog] = []
|
||||
tracing_service: Optional["TracingService"] = None
|
||||
|
||||
def update_state(self, name: str, value: Any):
|
||||
|
|
@ -488,5 +488,5 @@ class CustomComponent(BaseComponent):
|
|||
Args:
|
||||
message (LoggableType | list[LoggableType]): The message to log.
|
||||
"""
|
||||
log = Log(message=message, type=get_artifact_type(message))
|
||||
log = OutputLog(message=message, type=get_artifact_type(message))
|
||||
self._logs.append(log)
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ from typing import Any, List, Optional
|
|||
from pydantic import BaseModel, Field, field_serializer, model_validator
|
||||
|
||||
from langflow.graph.utils import serialize_field
|
||||
from langflow.schema.schema import Log, StreamURL
|
||||
from langflow.schema.schema import OutputLog, StreamURL
|
||||
from langflow.utils.schemas import ChatOutputResponse, ContainsEnumMeta
|
||||
|
||||
|
||||
class ResultData(BaseModel):
|
||||
results: Optional[Any] = Field(default_factory=dict)
|
||||
artifacts: Optional[Any] = Field(default_factory=dict)
|
||||
logs: Optional[dict] = Field(default_factory=dict)
|
||||
outputs: Optional[dict] = Field(default_factory=dict)
|
||||
messages: Optional[list[ChatOutputResponse]] = Field(default_factory=list)
|
||||
timedelta: Optional[float] = None
|
||||
duration: Optional[str] = None
|
||||
|
|
@ -28,7 +28,7 @@ class ResultData(BaseModel):
|
|||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validate_model(cls, values):
|
||||
if not values.get("logs") and values.get("artifacts"):
|
||||
if not values.get("outputs") and values.get("artifacts"):
|
||||
# Build the log from the artifacts
|
||||
|
||||
for key in values["artifacts"]:
|
||||
|
|
@ -40,9 +40,9 @@ class ResultData(BaseModel):
|
|||
|
||||
if "stream_url" in message and "type" in message:
|
||||
stream_url = StreamURL(location=message["stream_url"])
|
||||
values["logs"].update({key: Log(message=stream_url, type=message["type"])})
|
||||
values["outputs"].update({key: OutputLog(message=stream_url, type=message["type"])})
|
||||
elif "type" in message:
|
||||
values["logs"].update({Log(message=message, type=message["type"])})
|
||||
values["outputs"].update({OutputLog(message=message, type=message["type"])})
|
||||
return values
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,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, Log, build_logs
|
||||
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.utils.constants import DIRECT_TYPES
|
||||
|
|
@ -80,7 +80,7 @@ class Vertex:
|
|||
self.layer = None
|
||||
self.result: Optional[ResultData] = None
|
||||
self.results: Dict[str, Any] = {}
|
||||
self.logs: Dict[str, Log] = {}
|
||||
self.outputs_logs: Dict[str, OutputLog] = {}
|
||||
try:
|
||||
self.is_interface_component = self.vertex_type in InterfaceComponentTypes
|
||||
except ValueError:
|
||||
|
|
@ -457,7 +457,7 @@ class Vertex:
|
|||
result_dict = ResultData(
|
||||
results=result_dict,
|
||||
artifacts=artifacts,
|
||||
logs=self.logs,
|
||||
outputs=self.outputs_logs,
|
||||
messages=messages,
|
||||
component_display_name=self.display_name,
|
||||
component_id=self.id,
|
||||
|
|
@ -620,7 +620,7 @@ class Vertex:
|
|||
fallback_to_env_vars=fallback_to_env_vars,
|
||||
vertex=self,
|
||||
)
|
||||
self.logs = build_logs(self, result)
|
||||
self.outputs_logs = build_output_logs(self, result)
|
||||
self._update_built_object_and_artifacts(result)
|
||||
except Exception as exc:
|
||||
tb = traceback.format_exc()
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ class ComponentVertex(Vertex):
|
|||
result_dict = ResultData(
|
||||
results=result_dict,
|
||||
artifacts=self.artifacts,
|
||||
logs=self.logs,
|
||||
outputs=self.outputs_logs,
|
||||
messages=messages,
|
||||
component_display_name=self.display_name,
|
||||
component_id=self.id,
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class ErrorLog(TypedDict):
|
|||
stackTrace: str
|
||||
|
||||
|
||||
class Log(BaseModel):
|
||||
class OutputLog(BaseModel):
|
||||
message: Union[ErrorLog, StreamURL, dict, list, str]
|
||||
type: str
|
||||
|
||||
|
|
@ -79,8 +79,8 @@ def get_message(payload):
|
|||
return message or payload
|
||||
|
||||
|
||||
def build_logs(vertex, result) -> dict:
|
||||
logs: dict[str, Log] = dict()
|
||||
def build_output_logs(vertex, result) -> dict:
|
||||
outputs: dict[str, OutputLog] = dict()
|
||||
component_instance = result[0]
|
||||
for index, output in enumerate(vertex.outputs):
|
||||
if component_instance.status is None:
|
||||
|
|
@ -105,6 +105,6 @@ def build_logs(vertex, result) -> dict:
|
|||
case LogType.UNKNOWN:
|
||||
message = ""
|
||||
name = output.get("name", f"output_{index}")
|
||||
logs |= {name: Log(message=message, type=_type).model_dump()}
|
||||
outputs |= {name: OutputLog(message=message, type=_type).model_dump()}
|
||||
|
||||
return logs
|
||||
return outputs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue