feat: logs on component output (#2740)

* Added tabs and passed the type of the table to the SwitchOutputView component

* Added type to SwitchOutputViewProps and changed results based on type

* Removed unused import

* Changed type of VertexDataTypeAPI to include logs

* Added condition where type is Logs to display only table

* Added handling when resultMessage is empty to SwitchOutputView

* Removed return that made Logs not appear when its empty

* Fixed logs not appearing

* feat: Add _output_logs attribute to CustomComponent

The code changes include adding a new attribute `_output_logs` to the `CustomComponent` class. This attribute is a dictionary that stores logs related to output values. This change is necessary to enhance the logging functionality of the component.

Note: Please remove any meta information such as issue references, tags, or author names from the commit message.

* feat: Serialize messages with to_json() in BaseCrewComponent

This commit modifies the `BaseCrewComponent` class in the `crew.py` file. It adds serialization of messages using the `to_json()` method to avoid circular reference issues. The `_messages_dict` dictionary is serialized by converting each message object to JSON format. This change enhances the functionality of the component and improves the logging process.

Note: Please remove any meta information such as issue references, tags, or author names from the commit message.

---------

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
Lucas Oliveira 2024-07-16 19:36:10 -03:00 • committed by GitHub
commit 0897ee542a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 58 additions and 13 deletions

View file

@ -67,7 +67,9 @@ class BaseCrewComponent(Component):
self.log(cast(dict, messages[0].to_json()), name=f"Finish (Agent: {_id})")
elif isinstance(agent_output, list):
_messages_dict = {f"Action {i}": action.messages for i, (action, _) in enumerate(agent_output)}
messages_dict = {k: v[0] if len(v) == 1 else v for k, v in _messages_dict.items()}
# Serialize the messages with to_json() to avoid issues with circular references
serializable_dict = {k: [m.to_json() for m in v] for k, v in _messages_dict.items()}
messages_dict = {k: v[0] if len(v) == 1 else v for k, v in serializable_dict.items()}
self.log(messages_dict, name=f"Step (Agent: {_id})")
return step_callback
@ -76,5 +78,5 @@ class BaseCrewComponent(Component):
crew = self.build_crew()
result = await crew.kickoff_async()
message = Message(text=result, sender="Machine")
self.status = "\n\n".join([result] + [str(message) for message in self._logs])
self.status = message
return message

View file

@ -9,7 +9,6 @@ from langflow.inputs.inputs import InputTypes
from langflow.schema.artifact import get_artifact_type, post_process_raw
from langflow.schema.data import Data
from langflow.schema.message import Message
from langflow.services.tracing.schema import Log
from langflow.template.field.base import UNDEFINED, Output
from .custom_component import CustomComponent
@ -39,7 +38,6 @@ class Component(CustomComponent):
inputs: List[InputTypes] = []
outputs: List[Output] = []
code_class_base_inheritance: ClassVar[str] = "Component"
_output_logs: dict[str, Log] = {}
def __init__(self, **data):
self._inputs: dict[str, InputTypes] = {}

View file

@ -86,6 +86,7 @@ class CustomComponent(BaseComponent):
_flows_data: Optional[List[Data]] = None
_outputs: List[OutputValue] = []
_logs: List[Log] = []
_output_logs: dict[str, Log] = {}
tracing_service: Optional["TracingService"] = None
def set_attributes(self, parameters: dict):