From 04a23b59654912539d096fec57e720b932463e3d Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Wed, 8 Mar 2023 18:32:36 -0300 Subject: [PATCH 1/5] clear button created --- .../src/components/chatComponent/index.tsx | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/langflow/frontend/src/components/chatComponent/index.tsx b/langflow/frontend/src/components/chatComponent/index.tsx index 00a278037..4cf6dcd82 100644 --- a/langflow/frontend/src/components/chatComponent/index.tsx +++ b/langflow/frontend/src/components/chatComponent/index.tsx @@ -5,7 +5,7 @@ import { PaperAirplaneIcon, XMarkIcon, } from "@heroicons/react/24/outline"; -import { useContext, useEffect, useRef, useState } from "react"; +import { MouseEventHandler, useContext, useEffect, useRef, useState } from "react"; import { sendAll } from "../../controllers/NodesServices"; import { alertContext } from "../../contexts/alertContext"; import { classNames, nodeColors } from "../../utils"; @@ -89,7 +89,7 @@ export default function Chat({ flow, reactFlowInstance }: ChatType) { sendAll({ ...reactFlowInstance.toObject(), message, chatHistory }) .then((r) => { console.log(r.data); - addChatHistory(r.data.result, false,r.data.thought); + addChatHistory(r.data.result, false, r.data.thought); setLockChat(false); }) .catch((error) => { @@ -109,6 +109,10 @@ export default function Chat({ flow, reactFlowInstance }: ChatType) { }); } } + function clearChat() { + setChatHistory([]) + updateFlow({ ..._.cloneDeep(flow), chat: []}); + } return ( <> @@ -137,10 +141,18 @@ export default function Chat({ flow, reactFlowInstance }: ChatType) { /> Chat +
{chatHistory.map((c, i) => ( - + ))}
@@ -154,7 +166,7 @@ export default function Chat({ flow, reactFlowInstance }: ChatType) { }} type="text" disabled={lockChat} - value={lockChat?"Thinking...": chatValue} + value={lockChat ? "Thinking..." : chatValue} onChange={(e) => { setChatValue(e.target.value); }} From 8adc3f203fc4b11e0672aaa4d0c8d38254eea5d6 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Wed, 8 Mar 2023 18:40:32 -0300 Subject: [PATCH 2/5] change download, tabs name and document title --- langflow/frontend/public/index.html | 2 +- langflow/frontend/src/contexts/tabsContext.tsx | 5 +++-- langflow/frontend/src/utils.ts | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/langflow/frontend/public/index.html b/langflow/frontend/public/index.html index e9ecbe8ec..aa19f07de 100644 --- a/langflow/frontend/public/index.html +++ b/langflow/frontend/public/index.html @@ -4,7 +4,7 @@ - Document + LangFLow diff --git a/langflow/frontend/src/contexts/tabsContext.tsx b/langflow/frontend/src/contexts/tabsContext.tsx index bb85474c2..7b3f60e06 100644 --- a/langflow/frontend/src/contexts/tabsContext.tsx +++ b/langflow/frontend/src/contexts/tabsContext.tsx @@ -1,6 +1,7 @@ import { createContext, useEffect, useState, useRef, ReactNode } from "react"; import { FlowType } from "../types/flow"; import { TabsContextType } from "../types/tabs"; +import { normalCaseToSnakeCase } from "../utils"; const TabsContextInitialValue: TabsContextType = { tabIndex: 0, @@ -61,7 +62,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { // create a link element and set its properties const link = document.createElement("a"); link.href = jsonString; - link.download = `${flows[tabIndex].name}.json`; + link.download = `${normalCaseToSnakeCase(flows[tabIndex].name)}.json`; // simulate a click on the link element to trigger the download link.click(); @@ -124,7 +125,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { // Create a new flow with a default name if no flow is provided. let newFlow: FlowType = { - name: flow ? flow.name : "flow" + id, + name: flow ? flow.name : "New Flow " + id, id: id.toString(), data, chat: flow ? flow.chat : [], diff --git a/langflow/frontend/src/utils.ts b/langflow/frontend/src/utils.ts index 82e09e979..3f53b446d 100644 --- a/langflow/frontend/src/utils.ts +++ b/langflow/frontend/src/utils.ts @@ -286,6 +286,18 @@ export function snakeToNormalCase(str: string) { .join(" "); } +export function normalCaseToSnakeCase(str:string){ + return str + .split(" ") + .map((word, index) => { + if (index === 0) { + return word[0].toUpperCase() + word.slice(1).toLowerCase(); + } + return word.toLowerCase(); + }) + .join("_"); +} + export function roundNumber(x:number, decimals:number) { return Math.round(x * Math.pow(10, decimals)) / Math.pow(10, decimals); } From 0e4bb1bc1d6059b98ccc634be6f9d49abbc60696 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Wed, 8 Mar 2023 19:40:40 -0300 Subject: [PATCH 3/5] Nodes connection after deleting a node with edge connected bug fixed --- langflow/frontend/src/contexts/typesContext.tsx | 1 + langflow/frontend/src/pages/FlowPage/index.tsx | 5 +++++ langflow/frontend/src/utils.ts | 1 - 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/langflow/frontend/src/contexts/typesContext.tsx b/langflow/frontend/src/contexts/typesContext.tsx index 664a3dcf6..d20012a84 100644 --- a/langflow/frontend/src/contexts/typesContext.tsx +++ b/langflow/frontend/src/contexts/typesContext.tsx @@ -21,6 +21,7 @@ export function TypesProvider({ children }:{children:ReactNode}) { reactFlowInstance.setNodes( reactFlowInstance.getNodes().filter((n:Node) => n.id !== idx) ); + reactFlowInstance.setEdges(reactFlowInstance.getEdges().filter((ns) => ns.source !== idx && ns.target !== idx)); } return ( { + setEdges(edges.filter((ns) => !nodes.some((n) => ns.source === n.id || ns.target === n.id))); + } return (
@@ -174,6 +178,7 @@ export default function FlowPage({ flow }:{flow:FlowType}) { connectionLineComponent={ConnectionLineComponent} onDragOver={onDragOver} onDrop={onDrop} + onNodesDelete={onDelete} > diff --git a/langflow/frontend/src/utils.ts b/langflow/frontend/src/utils.ts index 3f53b446d..c95f17834 100644 --- a/langflow/frontend/src/utils.ts +++ b/langflow/frontend/src/utils.ts @@ -315,7 +315,6 @@ export function isValidConnection( { source, target, sourceHandle, targetHandle }:Connection, reactFlowInstance:ReactFlowInstance ) { - console.log(target) if ( sourceHandle.split('|')[0] === targetHandle.split("|")[0] || sourceHandle.split('|').slice(2).some((t) => t === targetHandle.split("|")[0]) || From 9200d7e12a454c51ad7f85a4db034aa84caa4019 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Wed, 8 Mar 2023 19:42:32 -0300 Subject: [PATCH 4/5] fixed bug on parameter for hiding handle on str and bool --- .../components/parameterComponent/index.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/langflow/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/langflow/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 3d43557d9..daaf81972 100644 --- a/langflow/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/langflow/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -52,6 +52,9 @@ export default function ParameterComponent({ {title} {required ? " *" : ""}
+ {left && (type === "str" || type === "bool" || type === "float") ? + <> + : + } + {left === true && type === "str" ? (
{data.node.template[name].list ? ( From 1910be7c3310e7400e75ead2be8a534d756ceaab Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Wed, 8 Mar 2023 19:57:59 -0300 Subject: [PATCH 5/5] added password field --- .../GenericNode/components/parameterComponent/index.tsx | 1 + langflow/frontend/src/components/inputComponent/index.tsx | 4 ++-- langflow/frontend/src/types/components/index.ts | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/langflow/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/langflow/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index daaf81972..facf6237a 100644 --- a/langflow/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/langflow/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -101,6 +101,7 @@ export default function ParameterComponent({ ) : ( { data.node.template[name].value = t; diff --git a/langflow/frontend/src/components/inputComponent/index.tsx b/langflow/frontend/src/components/inputComponent/index.tsx index d81795907..bb1a5ed43 100644 --- a/langflow/frontend/src/components/inputComponent/index.tsx +++ b/langflow/frontend/src/components/inputComponent/index.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from "react"; import { InputComponentType } from "../../types/components"; -export default function InputComponent({value, onChange, disabled}: InputComponentType){ +export default function InputComponent({value, onChange, disabled, password}: InputComponentType){ const [myValue, setMyValue] = useState(value ?? ""); useEffect(()=> { if(disabled){ @@ -12,7 +12,7 @@ export default function InputComponent({value, onChange, disabled}: InputCompone return (
void; + password: boolean; }; export type ToggleComponentType = { enabled: boolean;