refactor: Add log method to CustomComponent for logging messages
This commit is contained in:
parent
bde49ba286
commit
af38ec4580
1 changed files with 17 additions and 0 deletions
|
|
@ -14,7 +14,10 @@ from langflow.custom.code_parser.utils import (
|
||||||
from langflow.custom.custom_component.base_component import BaseComponent
|
from langflow.custom.custom_component.base_component import BaseComponent
|
||||||
from langflow.helpers.flow import list_flows, load_flow, run_flow
|
from langflow.helpers.flow import list_flows, load_flow, run_flow
|
||||||
from langflow.schema import Record
|
from langflow.schema import Record
|
||||||
|
from langflow.schema.artifact import get_artifact_type
|
||||||
from langflow.schema.dotdict import dotdict
|
from langflow.schema.dotdict import dotdict
|
||||||
|
from langflow.schema.message import Message
|
||||||
|
from langflow.schema.schema import Log
|
||||||
from langflow.services.deps import get_storage_service, get_variable_service, session_scope
|
from langflow.services.deps import get_storage_service, get_variable_service, session_scope
|
||||||
from langflow.services.storage.service import StorageService
|
from langflow.services.storage.service import StorageService
|
||||||
from langflow.utils import validate
|
from langflow.utils import validate
|
||||||
|
|
@ -25,6 +28,9 @@ if TYPE_CHECKING:
|
||||||
from langflow.services.storage.service import StorageService
|
from langflow.services.storage.service import StorageService
|
||||||
|
|
||||||
|
|
||||||
|
LoggableType = Union[str, dict, list, int, float, bool, None, Record, Message]
|
||||||
|
|
||||||
|
|
||||||
class CustomComponent(BaseComponent):
|
class CustomComponent(BaseComponent):
|
||||||
"""
|
"""
|
||||||
Represents a custom component in Langflow.
|
Represents a custom component in Langflow.
|
||||||
|
|
@ -75,6 +81,7 @@ class CustomComponent(BaseComponent):
|
||||||
status: Optional[Any] = None
|
status: Optional[Any] = None
|
||||||
"""The status of the component. This is displayed on the frontend. Defaults to None."""
|
"""The status of the component. This is displayed on the frontend. Defaults to None."""
|
||||||
_flows_records: Optional[List[Record]] = None
|
_flows_records: Optional[List[Record]] = None
|
||||||
|
_logs: Optional[List[Log]] = []
|
||||||
|
|
||||||
def update_state(self, name: str, value: Any):
|
def update_state(self, name: str, value: Any):
|
||||||
if not self.vertex:
|
if not self.vertex:
|
||||||
|
|
@ -468,3 +475,13 @@ class CustomComponent(BaseComponent):
|
||||||
Any: The result of the build process.
|
Any: The result of the build process.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def log(self, message: LoggableType | list[LoggableType]):
|
||||||
|
"""
|
||||||
|
Logs a message.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
message (LoggableType | list[LoggableType]): The message to log.
|
||||||
|
"""
|
||||||
|
log = Log(message=message, type=get_artifact_type(message))
|
||||||
|
self._logs.append(log)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue