From 44011f3dd5ebb21643326f562e5972d561ccad4b Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 4 Jul 2023 23:25:18 -0300 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=90=9B=20fix(GenericNode/index.tsx):?= =?UTF-8?q?=20fix=20class=20order=20in=20div=20element=20to=20ensure=20cor?= =?UTF-8?q?rect=20styling=20=E2=9C=A8=20feat(GenericNode/index.tsx):=20imp?= =?UTF-8?q?rove=20readability=20and=20maintainability=20by=20extracting=20?= =?UTF-8?q?repeated=20class=20names=20into=20variables=20The=20class=20ord?= =?UTF-8?q?er=20in=20the=20div=20element=20has=20been=20fixed=20to=20ensur?= =?UTF-8?q?e=20the=20correct=20styling=20is=20applied.=20Repeated=20class?= =?UTF-8?q?=20names=20have=20been=20extracted=20into=20variables=20to=20im?= =?UTF-8?q?prove=20readability=20and=20maintainability=20of=20the=20code.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/CustomNodes/GenericNode/index.tsx | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/index.tsx b/src/frontend/src/CustomNodes/GenericNode/index.tsx index c994dc919..4e0f4ef18 100644 --- a/src/frontend/src/CustomNodes/GenericNode/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/index.tsx @@ -93,7 +93,7 @@ export default function GenericNode({ color: nodeColors[types[data.type]] ?? nodeColors.unknown, }} /> -
+
@@ -207,9 +207,19 @@ export default function GenericNode({ } info={data.node.template[t].info} name={t} - tooltipTitle={data.node.template[t].input_types?.join("\n") ?? data.node.template[t].type} + tooltipTitle={ + data.node.template[t].input_types?.join("\n") ?? + data.node.template[t].type + } required={data.node.template[t].required} - id={(data.node.template[t].input_types?.join(";") ?? data.node.template[t].type) + "|" + t + "|" + data.id} + id={ + (data.node.template[t].input_types?.join(";") ?? + data.node.template[t].type) + + "|" + + t + + "|" + + data.id + } left={true} type={data.node.template[t].type} optionalHandle={data.node.template[t].input_types} @@ -233,7 +243,11 @@ export default function GenericNode({ 0 ? data.node.output_types.join("|") : data.type} + title={ + data.node.output_types && data.node.output_types.length > 0 + ? data.node.output_types.join("|") + : data.type + } tooltipTitle={data.node.base_classes.join("\n")} id={[data.type, data.id, ...data.node.base_classes].join("|")} type={data.node.base_classes.join("|")} From 244aeae9165cd87c8e10d49e2929321e3f7f7739 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 4 Jul 2023 23:29:51 -0300 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=94=A7=20chore(validate.py):=20add=20?= =?UTF-8?q?multiline=20option=20to=20input=5Fvariables=20field=20in=20add?= =?UTF-8?q?=5Fnew=5Fvariables=5Fto=5Ftemplate=20function=20The=20multiline?= =?UTF-8?q?=20option=20is=20added=20to=20the=20input=5Fvariables=20field?= =?UTF-8?q?=20in=20the=20add=5Fnew=5Fvariables=5Fto=5Ftemplate=20function.?= =?UTF-8?q?=20This=20allows=20the=20field=20to=20accept=20multiline=20inpu?= =?UTF-8?q?t,=20which=20can=20be=20useful=20in=20certain=20scenarios=20whe?= =?UTF-8?q?re=20multiple=20lines=20of=20text=20need=20to=20be=20entered.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/validate.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/langflow/api/v1/validate.py b/src/backend/langflow/api/v1/validate.py index 9878376c7..362430cf8 100644 --- a/src/backend/langflow/api/v1/validate.py +++ b/src/backend/langflow/api/v1/validate.py @@ -71,6 +71,7 @@ def add_new_variables_to_template(input_variables, prompt_request): field_type="str", show=True, advanced=False, + multiline=True, input_types=["Document", "BaseOutputParser"], ) From 5445adbbce1b3693e0b5e21b24f70b1a4e5a57b8 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 4 Jul 2023 23:32:25 -0300 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=90=9B=20fix(validate.py):=20set=20ne?= =?UTF-8?q?w=20field=20value=20with=20the=20old=20value=20if=20variable=20?= =?UTF-8?q?already=20exists=20in=20the=20template=20The=20code=20now=20che?= =?UTF-8?q?cks=20if=20the=20variable=20already=20exists=20in=20the=20templ?= =?UTF-8?q?ate=20and=20if=20so,=20sets=20the=20new=20field=20value=20with?= =?UTF-8?q?=20the=20old=20value.=20This=20ensures=20that=20the=20existing?= =?UTF-8?q?=20value=20is=20preserved=20when=20adding=20new=20variables=20t?= =?UTF-8?q?o=20the=20template.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/validate.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/api/v1/validate.py b/src/backend/langflow/api/v1/validate.py index 362430cf8..aa3748785 100644 --- a/src/backend/langflow/api/v1/validate.py +++ b/src/backend/langflow/api/v1/validate.py @@ -74,7 +74,11 @@ def add_new_variables_to_template(input_variables, prompt_request): multiline=True, input_types=["Document", "BaseOutputParser"], ) - + if variable in prompt_request.frontend_node.template: + # Set the new field with the old value + template_field.value = prompt_request.frontend_node.template[variable][ + "value" + ] prompt_request.frontend_node.template[variable] = template_field.to_dict() # Check if variable is not already in the list before appending From 834429cd376d1d2cd9500f2ddb744a9d76b56a55 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 4 Jul 2023 23:58:54 -0300 Subject: [PATCH 4/6] fix: add verification for formKeysData --- src/frontend/src/modals/formModal/index.tsx | 65 ++++++++++++--------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index fd3ed98c6..bb45ee2a6 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -40,13 +40,26 @@ export default function FormModal({ flow: FlowType; }) { const { tabsState, setTabsState } = useContext(TabsContext); - const [chatValue, setChatValue] = useState( - tabsState[flow.id].formKeysData.input_keys[ - Object.keys(tabsState[flow.id].formKeysData.input_keys).find( - (k) => !tabsState[flow.id].formKeysData.handle_keys.some((j) => j === k) - ) - ] - ); + const [chatValue, setChatValue] = useState(() => { + try { + const { formKeysData } = tabsState[flow.id]; + if (!formKeysData) throw new Error("formKeysData is undefined"); + + const inputKeys = formKeysData.input_keys; + const handleKeys = formKeysData.handle_keys; + + const keyToUse = Object.keys(inputKeys).find( + (k) => !handleKeys.some((j) => j === k) + ); + + return inputKeys[keyToUse]; + } catch (error) { + console.error(error); + // return a sensible default or `undefined` if no default is possible + return undefined; + } + }); + const [chatHistory, setChatHistory] = useState([]); const { reactFlowInstance } = useContext(typesContext); const { setErrorData, setNoticeData } = useContext(alertContext); @@ -382,26 +395,26 @@ export default function FormModal({ Chat {CHAT_FORM_DIALOG_SUBTITLE} -
-
-
- +
+
+
+ Input Variables
-
-
+
+
Name
-
+
Chat Input @@ -413,7 +426,7 @@ export default function FormModal({
-
+
{i} @@ -438,7 +451,7 @@ export default function FormModal({
-
+
{tabsState[ id.current ].formKeysData.handle_keys.some((t) => t === i) && ( @@ -470,7 +483,7 @@ export default function FormModal({ )} {tabsState[id.current].formKeysData.memory_keys.map((i, k) => ( -
+
{i} @@ -483,14 +496,14 @@ export default function FormModal({
-
+