From b2ccccd26cd326928f7fdc6ebc43fec18d63f9fc Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 16 Jul 2024 14:09:28 -0300 Subject: [PATCH 01/12] Added tabs and passed the type of the table to the SwitchOutputView component --- .../components/outputModal/index.tsx | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/index.tsx index e34ee6ec114..c8fdfa1a93c 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/index.tsx @@ -1,3 +1,5 @@ +import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import { useState } from "react"; import { Button } from "../../../../components/ui/button"; import BaseModal from "../../../../modals/baseModal"; import SwitchOutputView from "./components/switchOutputView"; @@ -8,15 +10,32 @@ export default function OutputModal({ nodeId, outputName, }): JSX.Element { + const [activeTab, setActiveTab] = useState<"Outputs" | "Logs">("Outputs"); return ( - +
Component Output
- + setActiveTab(value as "Outputs" | "Logs")} + className={ + "absolute top-6 flex flex-col self-center overflow-hidden rounded-md border bg-muted text-center" + } + > + + Outputs + Logs + + +
From 6ba0e6e5f4adafc1f71d98a0d2967937ba013742 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 16 Jul 2024 14:10:02 -0300 Subject: [PATCH 02/12] Added type to SwitchOutputViewProps and changed results based on type --- .../outputModal/components/switchOutputView/index.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx index 783a0036b85..823293ff040 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx @@ -13,16 +13,21 @@ import ErrorOutput from "./components"; interface SwitchOutputViewProps { nodeId: string; outputName: string; + type: "Outputs" | "Logs"; } const SwitchOutputView: React.FC = ({ nodeId, outputName, + type, }) => { const flowPool = useFlowStore((state) => state.flowPool); const flowPoolNode = (flowPool[nodeId] ?? [])[ (flowPool[nodeId]?.length ?? 1) - 1 ]; - let results = flowPoolNode?.data?.outputs[outputName] ?? ""; + let results = + type === "Outputs" + ? flowPoolNode?.data?.outputs[outputName] + : flowPoolNode?.data?.logs[outputName] ?? ""; if (Array.isArray(results)) { return; } From 3c4486f30078f6df44ceb398c90ebb84883254ea Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 16 Jul 2024 14:10:11 -0300 Subject: [PATCH 03/12] Removed unused import --- .../src/modals/IOModal/components/SessionView/index.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/frontend/src/modals/IOModal/components/SessionView/index.tsx b/src/frontend/src/modals/IOModal/components/SessionView/index.tsx index fc471043189..f23bbba0e9e 100644 --- a/src/frontend/src/modals/IOModal/components/SessionView/index.tsx +++ b/src/frontend/src/modals/IOModal/components/SessionView/index.tsx @@ -1,8 +1,5 @@ import Loading from "@/components/ui/loading"; -import { - useGetMessagesQuery, - useUpdateMessage, -} from "@/controllers/API/queries/messages"; +import { useUpdateMessage } from "@/controllers/API/queries/messages"; import { useIsFetching } from "@tanstack/react-query"; import { CellEditRequestEvent, From f5f81b1c47e122439942283fb6f0f13e140fb7ef Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 16 Jul 2024 14:10:26 -0300 Subject: [PATCH 04/12] Changed type of VertexDataTypeAPI to include logs --- src/frontend/src/types/api/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/frontend/src/types/api/index.ts b/src/frontend/src/types/api/index.ts index 6a74f9b446e..12e0700dc57 100644 --- a/src/frontend/src/types/api/index.ts +++ b/src/frontend/src/types/api/index.ts @@ -207,6 +207,7 @@ export type OutputLogType = { export type VertexDataTypeAPI = { results: { [key: string]: string }; outputs: { [key: string]: OutputLogType }; + logs: { [key: string]: OutputLogType }; messages: ChatOutputType[] | ChatInputType[]; inactive?: boolean; timedelta?: number; From f7972b092ae8c30d2de29236a15aeafb89d51f79 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 16 Jul 2024 14:24:02 -0300 Subject: [PATCH 05/12] Added condition where type is Logs to display only table --- .../components/switchOutputView/index.tsx | 17 +++++++++++++++-- src/frontend/src/types/api/index.ts | 7 ++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx index 823293ff040..69f751e8fc4 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx @@ -1,3 +1,4 @@ +import { LogsLogType, OutputLogType } from "@/types/api"; import DataOutputComponent from "../../../../../../components/dataOutputComponent"; import ForwardedIconComponent from "../../../../../../components/genericIconComponent"; import { @@ -24,7 +25,7 @@ const SwitchOutputView: React.FC = ({ const flowPoolNode = (flowPool[nodeId] ?? [])[ (flowPool[nodeId]?.length ?? 1) - 1 ]; - let results = + let results: OutputLogType | LogsLogType = type === "Outputs" ? flowPoolNode?.data?.outputs[outputName] : flowPoolNode?.data?.logs[outputName] ?? ""; @@ -37,7 +38,7 @@ const SwitchOutputView: React.FC = ({ if (resultMessage?.raw) { resultMessage = resultMessage.raw; } - return ( + return type === "Outputs" ? ( <>
NO OUTPUT
@@ -83,6 +84,18 @@ const SwitchOutputView: React.FC = ({
+ ) : ( + ).every((item) => item.data) + ? (resultMessage as Array).map((item) => item.data) + : resultMessage + : [resultMessage] + } + pagination={true} + columnMode="union" + /> ); }; diff --git a/src/frontend/src/types/api/index.ts b/src/frontend/src/types/api/index.ts index 12e0700dc57..9b93b3da1b1 100644 --- a/src/frontend/src/types/api/index.ts +++ b/src/frontend/src/types/api/index.ts @@ -201,13 +201,18 @@ export type OutputLogType = { message: any | ErrorLogType; type: string; }; +export type LogsLogType = { + name: string; + message: any | ErrorLogType; + type: string; +}; // data is the object received by the API // it has results, artifacts, timedelta, duration export type VertexDataTypeAPI = { results: { [key: string]: string }; outputs: { [key: string]: OutputLogType }; - logs: { [key: string]: OutputLogType }; + logs: { [key: string]: LogsLogType }; messages: ChatOutputType[] | ChatInputType[]; inactive?: boolean; timedelta?: number; From a58206e5be73cc73dd76d7dc3c909daf14f73d6c Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 16 Jul 2024 15:51:15 -0300 Subject: [PATCH 06/12] Added handling when resultMessage is empty to SwitchOutputView --- .../components/switchOutputView/index.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx index 69f751e8fc4..6f9faf2c1ca 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx @@ -26,14 +26,14 @@ const SwitchOutputView: React.FC = ({ (flowPool[nodeId]?.length ?? 1) - 1 ]; let results: OutputLogType | LogsLogType = - type === "Outputs" + (type === "Outputs" ? flowPoolNode?.data?.outputs[outputName] - : flowPoolNode?.data?.logs[outputName] ?? ""; + : flowPoolNode?.data?.logs[outputName]) ?? {}; if (Array.isArray(results)) { return; } const resultType = results?.type; - let resultMessage = results?.message; + let resultMessage = results?.message ?? {}; const RECORD_TYPES = ["data", "object", "array", "message"]; if (resultMessage?.raw) { resultMessage = resultMessage.raw; @@ -60,7 +60,9 @@ const SwitchOutputView: React.FC = ({ ? (resultMessage as Array).every((item) => item.data) ? (resultMessage as Array).map((item) => item.data) : resultMessage - : [resultMessage] + : Object.keys(resultMessage).length > 0 + ? [resultMessage] + : [] } pagination={true} columnMode="union" @@ -91,7 +93,9 @@ const SwitchOutputView: React.FC = ({ ? (resultMessage as Array).every((item) => item.data) ? (resultMessage as Array).map((item) => item.data) : resultMessage - : [resultMessage] + : Object.keys(resultMessage).length > 0 + ? [resultMessage] + : [] } pagination={true} columnMode="union" From 843a160d0b193bbd97fd172b742a1f75d876a852 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 16 Jul 2024 16:32:49 -0300 Subject: [PATCH 07/12] Removed return that made Logs not appear when its empty --- .../outputModal/components/switchOutputView/index.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx index 6f9faf2c1ca..09da6786ee5 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx @@ -29,9 +29,6 @@ const SwitchOutputView: React.FC = ({ (type === "Outputs" ? flowPoolNode?.data?.outputs[outputName] : flowPoolNode?.data?.logs[outputName]) ?? {}; - if (Array.isArray(results)) { - return; - } const resultType = results?.type; let resultMessage = results?.message ?? {}; const RECORD_TYPES = ["data", "object", "array", "message"]; From 5356cc3b818e1b48033a9288e2323b29e6d8aec4 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Tue, 16 Jul 2024 18:12:04 -0300 Subject: [PATCH 08/12] Fixed logs not appearing --- .../components/switchOutputView/index.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx index 09da6786ee5..e683fe5e02c 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/outputModal/components/switchOutputView/index.tsx @@ -86,12 +86,12 @@ const SwitchOutputView: React.FC = ({ ) : ( ).every((item) => item.data) - ? (resultMessage as Array).map((item) => item.data) - : resultMessage - : Object.keys(resultMessage).length > 0 - ? [resultMessage] + Array.isArray(results) + ? (results as Array).every((item) => item.data) + ? (results as Array).map((item) => item.data) + : results + : Object.keys(results).length > 0 + ? [results] : [] } pagination={true} From 528637e1e0b84ab094689a30a78912158dad8c6f Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 16 Jul 2024 18:59:36 -0300 Subject: [PATCH 09/12] 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. --- src/backend/base/langflow/custom/custom_component/component.py | 1 - .../base/langflow/custom/custom_component/custom_component.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/base/langflow/custom/custom_component/component.py b/src/backend/base/langflow/custom/custom_component/component.py index 8df5f6c2b8d..de6016c57b1 100644 --- a/src/backend/base/langflow/custom/custom_component/component.py +++ b/src/backend/base/langflow/custom/custom_component/component.py @@ -39,7 +39,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] = {} diff --git a/src/backend/base/langflow/custom/custom_component/custom_component.py b/src/backend/base/langflow/custom/custom_component/custom_component.py index 8ffeb5b0e72..4a75ec33db6 100644 --- a/src/backend/base/langflow/custom/custom_component/custom_component.py +++ b/src/backend/base/langflow/custom/custom_component/custom_component.py @@ -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): From bb9ca4566913b6f45ff1cbc2e5dfb396c382e78e Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 16 Jul 2024 19:20:05 -0300 Subject: [PATCH 10/12] 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. --- src/backend/base/langflow/base/agents/crewai/crew.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/base/agents/crewai/crew.py b/src/backend/base/langflow/base/agents/crewai/crew.py index a4c70a51c3a..79ce52ad438 100644 --- a/src/backend/base/langflow/base/agents/crewai/crew.py +++ b/src/backend/base/langflow/base/agents/crewai/crew.py @@ -67,6 +67,8 @@ def step_callback(agent_output: Union[AgentFinish, List[Tuple[AgentAction, str]] 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)} + # Serialize the messages with to_json() to avoid issues with circular references + _messages_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 _messages_dict.items()} self.log(messages_dict, name=f"Step (Agent: {_id})") @@ -76,5 +78,5 @@ async def build_output(self) -> Message: 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 From dacda131478c4be4710a88e70536ddba0f97a3a4 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 16 Jul 2024 19:23:13 -0300 Subject: [PATCH 11/12] refactor: Serialize messages with to_json() in BaseCrewComponent --- src/backend/base/langflow/base/agents/crewai/crew.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/base/agents/crewai/crew.py b/src/backend/base/langflow/base/agents/crewai/crew.py index 79ce52ad438..70137518c0c 100644 --- a/src/backend/base/langflow/base/agents/crewai/crew.py +++ b/src/backend/base/langflow/base/agents/crewai/crew.py @@ -68,8 +68,8 @@ def step_callback(agent_output: Union[AgentFinish, List[Tuple[AgentAction, str]] elif isinstance(agent_output, list): _messages_dict = {f"Action {i}": action.messages for i, (action, _) in enumerate(agent_output)} # Serialize the messages with to_json() to avoid issues with circular references - _messages_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 _messages_dict.items()} + 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 From 10065adaeae055709f136d96ef5fb410021a1a5d Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:24:04 +0000 Subject: [PATCH 12/12] [autofix.ci] apply automated fixes --- src/backend/base/langflow/custom/custom_component/component.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/base/langflow/custom/custom_component/component.py b/src/backend/base/langflow/custom/custom_component/component.py index de6016c57b1..af1dfe26184 100644 --- a/src/backend/base/langflow/custom/custom_component/component.py +++ b/src/backend/base/langflow/custom/custom_component/component.py @@ -9,7 +9,6 @@ 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