From 06f0e0e0f89bc5b5c33bbd23320843bda0b41af7 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Mon, 18 Mar 2024 13:12:31 +0100 Subject: [PATCH] Added dropdown and global page --- langflow1.db | Bin 0 -> 90112 bytes src/backend/langflow/services/chat/utils.py | 15 -- src/backend/langflow/utils/chat.py | 34 --- src/backend/langflow/utils/prompt.py | 58 ------ .../components/parameterComponent/index.tsx | 8 +- .../src/components/inputComponent/index.tsx | 197 ++++++++++-------- .../components/addNewVariableButton.tsx | 19 +- src/frontend/src/utils/styleUtils.ts | 2 + 8 files changed, 118 insertions(+), 215 deletions(-) create mode 100644 langflow1.db delete mode 100644 src/backend/langflow/utils/chat.py delete mode 100644 src/backend/langflow/utils/prompt.py diff --git a/langflow1.db b/langflow1.db new file mode 100644 index 0000000000000000000000000000000000000000..2b39da5dd15e9197718ae2575b99af51f65a1115 GIT binary patch literal 90112 zcmeI5-EZ4icEF{0#*XvlnYI}tXcuL?GuU`DmPwJKBp2yccI3o~Ej#{-JxRd5BCjOI z6e*LGZ6zHn63n9S`@H`}Q55JO(E@$#00sKCZ$+^M`q*>%VUe;Fe}rCmoFhoKNM2r^ z^SkHXd+vvQ)}AfuF6C;L-6Sq2roKp})2YAXxKt{AH}318{( z%i!OTN5=e@n`8f%`f_9>b&HPu+pQZn{^90--k7}p@7I60#$R8)`d`;ZuKxb&(#Zde zjEwx_;GFOZ5H? z%iMZtcCpO$T;%Ru8x3w#%yyI8EUnHxF0I}Zvy)t9d7Z0lEG~Y_T^pTSuB@%EmKG}O zy*VhY9hF;IU05ouZgWq|+uXfKev{WGAAC7H{_K7_rJEW(aCQyozZKGUE$>+A5l0bv zPW;*S*zmY`JKgb;>jz5Bu=W*=I;yR=Tu_!Be-UW7PMnDv>wa4?ND3MHI{m;Z?-{#ZkEA`$%i+G$G^Fqeih5kBu&cly45!?cD0)kJDPky zaeZX`_U-f!zwnBd-OD~VVui@gu#)rc4~i^SToEW+1vY$_~e~54egw?^c~t!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KrzoX<;g9xe;;H_y`X dict: - return self.func(inputs, callbacks) diff --git a/src/backend/langflow/utils/prompt.py b/src/backend/langflow/utils/prompt.py deleted file mode 100644 index 871193f45..000000000 --- a/src/backend/langflow/utils/prompt.py +++ /dev/null @@ -1,58 +0,0 @@ -from typing import Any, Union - -from langchain_core.prompts import PromptTemplate as LCPromptTemplate -from llama_index.prompts import PromptTemplate as LIPromptTemplate - -PromptTemplateTypes = Union[LCPromptTemplate, LIPromptTemplate] - - -class GenericPromptTemplate: - def __init__(self, prompt_template: PromptTemplateTypes): - object.__setattr__(self, "prompt_template", prompt_template) - - @property - def input_keys(self): - prompt_template = object.__getattribute__(self, "prompt_template") - if isinstance(prompt_template, LCPromptTemplate): - return prompt_template.input_variables - elif isinstance(prompt_template, LIPromptTemplate): - return prompt_template.template_vars - else: - raise TypeError(f"Unknown prompt template type {type(prompt_template)}") - - def to_lc_prompt(self): - prompt_template = object.__getattribute__(self, "prompt_template") - if isinstance(prompt_template, LCPromptTemplate): - return prompt_template - elif isinstance(prompt_template, LIPromptTemplate): - return LCPromptTemplate.from_template(prompt_template.get_template()) - else: - raise TypeError(f"Unknown prompt template type {type(prompt_template)}") - - def to_li_prompt(self): - prompt_template = object.__getattribute__(self, "prompt_template") - if isinstance(prompt_template, LIPromptTemplate): - return prompt_template - elif isinstance(prompt_template, LCPromptTemplate): - return LIPromptTemplate(template=prompt_template.template) - else: - raise TypeError(f"Unknown prompt template type {type(prompt_template)}") - - def __or__(self, other): - prompt_template = object.__getattribute__(self, "prompt_template") - if isinstance(prompt_template, LIPromptTemplate): - return self.to_lc_prompt() | other - else: - raise TypeError(f"Unknown prompt template type {type(other)}") - - def __getattribute__(self, name: str) -> Any: - if name in { - "input_keys", - "to_lc_prompt", - "to_li_prompt", - "__or__", - "prompt_template", - }: - return object.__getattribute__(self, name) - prompt_template = object.__getattribute__(self, "prompt_template") - return getattr(prompt_template, name) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 7b04f6be4..9278f2b23 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -314,9 +314,8 @@ export default function ParameterComponent({ <>
{proxy ? ( @@ -429,8 +428,7 @@ export default function ParameterComponent({ newNode.data.node.template[name].load_from_db = true; return newNode; }); - } - else{ + } else { setNode(data.id, (oldNode) => { let newNode = cloneDeep(oldNode); newNode.data = { diff --git a/src/frontend/src/components/inputComponent/index.tsx b/src/frontend/src/components/inputComponent/index.tsx index 9dfc96a9a..cd2846cdb 100644 --- a/src/frontend/src/components/inputComponent/index.tsx +++ b/src/frontend/src/components/inputComponent/index.tsx @@ -1,11 +1,13 @@ import { Listbox, Transition } from "@headlessui/react"; import * as Form from "@radix-ui/react-form"; import { Fragment, useEffect, useRef, useState } from "react"; +import AddNewVariableButton from "../../pages/globalVariablesPage/components/addNewVariableButton"; import { InputComponentType } from "../../types/components"; import { handleKeyDown } from "../../utils/reactflowUtils"; -import { classNames } from "../../utils/utils"; +import { classNames, cn } from "../../utils/utils"; import IconComponent from "../genericIconComponent"; import { Input } from "../ui/input"; +import { Separator } from "../ui/separator"; export default function InputComponent({ autoFocus = false, @@ -26,7 +28,6 @@ export default function InputComponent({ const [pwdVisible, setPwdVisible] = useState(false); const refInput = useRef(null); const [showOptions, setShowOptions] = useState(false); - const [filteredOpts, setFilteredValue] = useState(options); // Clear component state useEffect(() => { @@ -35,13 +36,12 @@ export default function InputComponent({ } }, [disabled]); - const filteredOptions = filteredOpts.filter((option) => + const filteredOptions = options.filter((option) => option.toLowerCase().includes(value.toLowerCase()) ); function onInputLostFocus(event): void { if (onBlur) onBlur(event); - setShowOptions(false); } return ( @@ -107,103 +107,115 @@ export default function InputComponent({ handleKeyDown(e, value, ""); if (blurOnEnter && e.key === "Enter") refInput.current?.blur(); }} - onFocus={() => setShowOptions(true)} /> - { - /* options.length > 0 && filteredOptions.length > 0 */ true ? ( - { - onChange(val); - }} - > - <> -
- - { + onChange(val); + }} + > + <> +
+ + +
+
+ + Global Variables +
+
+ + + +
+
+ + {filteredOptions.map((option, id) => ( + + classNames( + active ? " bg-accent" : "", + editNode + ? "dropdown-component-false-option" + : "dropdown-component-true-option", + " hover:bg-accent" + ) + } + value={option} > - {filteredOptions.map((option, id) => ( - - classNames( - active ? " bg-accent" : "", - editNode - ? "dropdown-component-false-option" - : "dropdown-component-true-option", - " hover:bg-accent" - ) - } - value={option} - > - {({ selected, active }) => ( - <> - - {option} - + {({ selected, active }) => ( + <> + + {option} + - {selected ? ( - - - ) : null} - - )} - - ))} -
-
-
- - - ) : null - } + {selected ? ( + + + ) : null} + + )} + + ))} +
+
+
+ +
)} {options.length > 0 && ( - )} @@ -212,6 +224,7 @@ export default function InputComponent({ type="button" tabIndex={-1} className={classNames( + "mb-px", editNode ? "input-component-true-button" : "input-component-false-button" diff --git a/src/frontend/src/pages/globalVariablesPage/components/addNewVariableButton.tsx b/src/frontend/src/pages/globalVariablesPage/components/addNewVariableButton.tsx index c0a7deba2..51f88ddf0 100644 --- a/src/frontend/src/pages/globalVariablesPage/components/addNewVariableButton.tsx +++ b/src/frontend/src/pages/globalVariablesPage/components/addNewVariableButton.tsx @@ -10,7 +10,7 @@ import { useGlobalVariablesStore } from "../../../stores/globalVariables"; //TODO IMPLEMENT FORM LOGIC -export default function AddNewVariableButton(): JSX.Element { +export default function AddNewVariableButton({children}): JSX.Element { const [key, setKey] = useState(""); const [value, setValue] = useState(""); const [provider, setProvider] = useState(""); @@ -33,25 +33,24 @@ export default function AddNewVariableButton(): JSX.Element { }); } return ( - + Create a new Variable - + {children} -
-
+
{ setKey(e.target.value); }} - placeholder="example name" + placeholder="Insert a name for the variable..." > -
-