From 151d01f5063a9768466d7542158bfd41e7a2e7dc Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Thu, 24 Aug 2023 21:00:38 -0300 Subject: [PATCH 01/56] =?UTF-8?q?=F0=9F=94=A7=20chore(Makefile):=20remove?= =?UTF-8?q?=20unnecessary=20semicolons=20in=20Makefile=20commands=20?= =?UTF-8?q?=F0=9F=94=A7=20chore(Makefile):=20remove=20unnecessary=20packag?= =?UTF-8?q?e-lock.json=20deletion=20in=20install=5Ffrontendc=20command=20?= =?UTF-8?q?=E2=9C=A8=20feat(ParameterComponent):=20add=20KeypairListCompon?= =?UTF-8?q?ent=20to=20handle=20key-value=20pairs=20=F0=9F=94=A7=20chore(Ke?= =?UTF-8?q?ypairListComponent):=20create=20KeypairListComponent=20to=20han?= =?UTF-8?q?dle=20key-value=20pairs=20=F0=9F=94=A7=20chore(KeypairListCompo?= =?UTF-8?q?nent):=20add=20handleChangeKey=20and=20handleChangeValue=20func?= =?UTF-8?q?tions=20to=20handle=20changes=20in=20key-value=20pairs=20?= =?UTF-8?q?=F0=9F=94=A7=20chore(KeypairListComponent):=20add=20button=20to?= =?UTF-8?q?=20add=20new=20key-value=20pair=20and=20remove=20existing=20key?= =?UTF-8?q?-value=20pair=20=F0=9F=94=A7=20chore(KeypairListComponent):=20a?= =?UTF-8?q?dd=20disabled=20prop=20to=20disable=20editing=20of=20key-value?= =?UTF-8?q?=20pairs=20=F0=9F=94=A7=20chore(KeypairListComponent):=20add=20?= =?UTF-8?q?editNode=20prop=20to=20style=20input=20fields=20in=20edit=20mod?= =?UTF-8?q?e=20=F0=9F=94=A7=20chore(types):=20add=20KeyPairListComponent?= =?UTF-8?q?=20type=20definition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 4 +- .../components/parameterComponent/index.tsx | 31 ++++- .../components/keypairListComponent/index.tsx | 108 ++++++++++++++++++ src/frontend/src/types/components/index.ts | 7 ++ 4 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 src/frontend/src/components/keypairListComponent/index.tsx diff --git a/Makefile b/Makefile index c0c6a7abc..0b05ec7cf 100644 --- a/Makefile +++ b/Makefile @@ -32,10 +32,10 @@ lint: poetry run ruff . --fix install_frontend: - cd src/frontend && npm install; + cd src/frontend && npm install install_frontendc: - cd src/frontend && rm -rf node_modules package-lock.json && npm install; + cd src/frontend && rm -rf node_modules package-lock.json && npm install run_frontend: cd src/frontend && npm start diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 94cc939ff..0b577ed65 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -31,6 +31,7 @@ import { nodeNames, } from "../../../../utils/styleUtils"; import { classNames, groupByFamily } from "../../../../utils/utils"; +import KeypairListComponent from "../../../../components/keypairListComponent"; export default function ParameterComponent({ left, @@ -93,6 +94,22 @@ export default function ParameterComponent({ renderTooltips(); }; + const [arrayOfObjects, setArrayOfObjects] = useState([ + { key1: "value1", key2: "value2" }, + { key3: "value3", key4: "value4" }, + { key5: "value5", key6: "value6" }, + ]) + + + const handleOnNewValueTest = (newValue): void => { + let newData = cloneDeep(arrayOfObjects); + newData = newValue; + setArrayOfObjects(newData); + }; + + + + useEffect(() => { if (name === "openai_api_base") console.log(info); // @ts-ignore @@ -341,7 +358,19 @@ export default function ParameterComponent({ onChange={handleOnNewValue} /> - ) : ( + ) + : left === true && type === "keypair" ? ( +
+ +
+ ) + : ( <> )} diff --git a/src/frontend/src/components/keypairListComponent/index.tsx b/src/frontend/src/components/keypairListComponent/index.tsx new file mode 100644 index 000000000..efb122414 --- /dev/null +++ b/src/frontend/src/components/keypairListComponent/index.tsx @@ -0,0 +1,108 @@ +import { useEffect } from "react"; +import { KeyPairListComponent } from "../../types/components"; + +import _ from "lodash"; +import { classNames } from "../../utils/utils"; +import IconComponent from "../genericIconComponent"; +import { Input } from "../ui/input"; + +export default function KeypairListComponent({ + value, + onChange, + disabled, + editNode = false, +}: KeyPairListComponent): JSX.Element { + useEffect(() => { + if (disabled) { + onChange([""]); + } + }, [disabled]); + + const handleChangeKey = (event, idx) => { + const newInputList = _.cloneDeep(value); + const oldKey = Object.keys(newInputList[idx])[0]; + const updatedObj = { [event.target.value]: newInputList[idx][oldKey] }; + newInputList[idx] = updatedObj; + onChange(newInputList); + }; + + const handleChangeValue = (event, idx) => { + const newInputList = _.cloneDeep(value); + const key = Object.keys(newInputList[idx])[0]; + newInputList[idx][key] = event.target.value; + onChange(newInputList); + }; + + return ( +
1 && editNode ? "my-1" : "", + "flex flex-col gap-3" + )} + > + {value.map((obj, index) => { + return Object.keys(obj).map((key, idx) => { + return ( +
+ handleChangeKey(event, index)} + onKeyDown={(e) => { + if (e.ctrlKey && e.key === "Backspace") { + e.preventDefault(); + e.stopPropagation(); + } + }} + /> + handleChangeValue(event, index)} + onKeyDown={(e) => { + if (e.ctrlKey && e.key === "Backspace") { + e.preventDefault(); + e.stopPropagation(); + } + }} + /> + {index === value.length - 1 ? ( + + ) : ( + + )} +
+ ); + }); + })} +
+ ); +} diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index c3e515333..62702a9e9 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -54,6 +54,13 @@ export type InputListComponentType = { editNode?: boolean; }; +export type KeyPairListComponent = { + value: any[]; + onChange: (value: string[]) => void; + disabled: boolean; + editNode?: boolean; +}; + export type TextAreaComponentType = { field_name?: string; nodeClass?: APIClassType; From 9424d5738a3c9d3b32b7dc84220217767c0a4321 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Mon, 28 Aug 2023 17:12:28 -0300 Subject: [PATCH 02/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20add=20missing=20prop=20'editNode'=20to=20KeypairListComponen?= =?UTF-8?q?t=20to=20fix=20component=20rendering=20issue=20=F0=9F=90=9B=20f?= =?UTF-8?q?ix(EditNodeModal):=20import=20KeypairListComponent=20to=20fix?= =?UTF-8?q?=20missing=20import=20error=20=E2=9C=A8=20feat(EditNodeModal):?= =?UTF-8?q?=20add=20support=20for=20editing=20keypair=20type=20template=20?= =?UTF-8?q?parameters=20by=20adding=20KeypairListComponent=20and=20handlin?= =?UTF-8?q?g=20new=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/parameterComponent/index.tsx | 1 + .../src/modals/EditNodeModal/index.tsx | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 0b577ed65..afdaa397a 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -363,6 +363,7 @@ export default function ParameterComponent({
{ + let newData = cloneDeep(arrayOfObjects); + newData = newValue; + setArrayOfObjects(newData); + }; + return ( {children} @@ -336,6 +349,16 @@ const EditNodeModal = forwardRef( }} />
+ ) : myData.node?.template[templateParam].type === + "keypair" ? ( +
+ +
) : myData.node?.template[templateParam].type === "Any" ? ( "-" From 4c228303c9264f21045e4d296ed3a7bb0b667741 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Wed, 30 Aug 2023 11:50:47 -0300 Subject: [PATCH 03/56] =?UTF-8?q?=F0=9F=90=9B=20fix(EditNodeModal):=20add?= =?UTF-8?q?=20condition=20to=20check=20if=20nodeLength=20is=20greater=20th?= =?UTF-8?q?an=20arrayOfObjects.length=20to=20handle=20overflow=20scrolling?= =?UTF-8?q?=20correctly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/EditNodeModal/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx index 66973a343..30252afaa 100644 --- a/src/frontend/src/modals/EditNodeModal/index.tsx +++ b/src/frontend/src/modals/EditNodeModal/index.tsx @@ -111,7 +111,8 @@ const EditNodeModal = forwardRef(
limitScrollFieldsModal + nodeLength > limitScrollFieldsModal || + nodeLength > arrayOfObjects.length ? "overflow-scroll overflow-x-hidden custom-scroll" : "overflow-hidden" )} From 2deebad9508b91ab3292e4f2412d977efce20036 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 30 Aug 2023 11:57:19 -0300 Subject: [PATCH 04/56] =?UTF-8?q?=F0=9F=93=A6=20chore(pyproject.toml):=20a?= =?UTF-8?q?dd=20markupsafe=20dependency=20to=20improve=20compatibility=20a?= =?UTF-8?q?nd=20security=20=F0=9F=94=92=20chore(pyproject.toml):=20update?= =?UTF-8?q?=20black=20dependency=20to=20version=2023.1.0=20for=20developme?= =?UTF-8?q?nt=20purposes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- poetry.lock | 14 +++++--------- pyproject.toml | 2 ++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/poetry.lock b/poetry.lock index d775029c8..7580b7b71 100644 --- a/poetry.lock +++ b/poetry.lock @@ -3022,9 +3022,9 @@ files = [ ] [package.dependencies] -diskcache = ">=5.6.1" -numpy = ">=1.20.0" -typing-extensions = ">=4.5.0" +diskcache = ">=5.6.1,<6.0.0" +numpy = ">=1.24.4,<2.0.0" +typing-extensions = ">=4.7.1,<5.0.0" [package.extras] server = ["fastapi (>=0.100.0)", "pydantic-settings (>=2.0.1)", "sse-starlette (>=1.6.1)", "uvicorn (>=0.23.2,<0.24.0)"] @@ -3057,8 +3057,6 @@ files = [ {file = "lxml-4.9.3-cp27-cp27m-macosx_11_0_x86_64.whl", hash = "sha256:b0a545b46b526d418eb91754565ba5b63b1c0b12f9bd2f808c852d9b4b2f9b5c"}, {file = "lxml-4.9.3-cp27-cp27m-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:075b731ddd9e7f68ad24c635374211376aa05a281673ede86cbe1d1b3455279d"}, {file = "lxml-4.9.3-cp27-cp27m-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:1e224d5755dba2f4a9498e150c43792392ac9b5380aa1b845f98a1618c94eeef"}, - {file = "lxml-4.9.3-cp27-cp27m-win32.whl", hash = "sha256:2c74524e179f2ad6d2a4f7caf70e2d96639c0954c943ad601a9e146c76408ed7"}, - {file = "lxml-4.9.3-cp27-cp27m-win_amd64.whl", hash = "sha256:4f1026bc732b6a7f96369f7bfe1a4f2290fb34dce00d8644bc3036fb351a4ca1"}, {file = "lxml-4.9.3-cp27-cp27mu-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:c0781a98ff5e6586926293e59480b64ddd46282953203c76ae15dbbbf302e8bb"}, {file = "lxml-4.9.3-cp27-cp27mu-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:cef2502e7e8a96fe5ad686d60b49e1ab03e438bd9123987994528febd569868e"}, {file = "lxml-4.9.3-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:b86164d2cff4d3aaa1f04a14685cbc072efd0b4f99ca5708b2ad1b9b5988a991"}, @@ -3261,7 +3259,7 @@ testing = ["coverage", "pytest", "pytest-cov", "pytest-regressions"] name = "markupsafe" version = "2.1.3" description = "Safely add untrusted strings to HTML/XML markup." -optional = true +optional = false python-versions = ">=3.7" files = [ {file = "MarkupSafe-2.1.3-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:cd0f502fe016460680cd20aaa5a76d241d6f35a1c3350c474bac1273803893fa"}, @@ -4408,7 +4406,6 @@ files = [ {file = "Pillow-10.0.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:3b08d4cc24f471b2c8ca24ec060abf4bebc6b144cb89cba638c720546b1cf538"}, {file = "Pillow-10.0.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:d737a602fbd82afd892ca746392401b634e278cb65d55c4b7a8f48e9ef8d008d"}, {file = "Pillow-10.0.0-cp311-cp311-win_amd64.whl", hash = "sha256:3a82c40d706d9aa9734289740ce26460a11aeec2d9c79b7af87bb35f0073c12f"}, - {file = "Pillow-10.0.0-cp311-cp311-win_arm64.whl", hash = "sha256:bc2ec7c7b5d66b8ec9ce9f720dbb5fa4bace0f545acd34870eff4a369b44bf37"}, {file = "Pillow-10.0.0-cp312-cp312-macosx_10_10_x86_64.whl", hash = "sha256:d80cf684b541685fccdd84c485b31ce73fc5c9b5d7523bf1394ce134a60c6883"}, {file = "Pillow-10.0.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:76de421f9c326da8f43d690110f0e79fe3ad1e54be811545d7d91898b4c8493e"}, {file = "Pillow-10.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:81ff539a12457809666fef6624684c008e00ff6bf455b4b89fd00a140eecd640"}, @@ -4418,7 +4415,6 @@ files = [ {file = "Pillow-10.0.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:d50b6aec14bc737742ca96e85d6d0a5f9bfbded018264b3b70ff9d8c33485551"}, {file = "Pillow-10.0.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:00e65f5e822decd501e374b0650146063fbb30a7264b4d2744bdd7b913e0cab5"}, {file = "Pillow-10.0.0-cp312-cp312-win_amd64.whl", hash = "sha256:f31f9fdbfecb042d046f9d91270a0ba28368a723302786c0009ee9b9f1f60199"}, - {file = "Pillow-10.0.0-cp312-cp312-win_arm64.whl", hash = "sha256:1ce91b6ec08d866b14413d3f0bbdea7e24dfdc8e59f562bb77bc3fe60b6144ca"}, {file = "Pillow-10.0.0-cp38-cp38-macosx_10_10_x86_64.whl", hash = "sha256:349930d6e9c685c089284b013478d6f76e3a534e36ddfa912cde493f235372f3"}, {file = "Pillow-10.0.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:3a684105f7c32488f7153905a4e3015a3b6c7182e106fe3c37fbb5ef3e6994c3"}, {file = "Pillow-10.0.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b4f69b3700201b80bb82c3a97d5e9254084f6dd5fb5b16fc1a7b974260f89f43"}, @@ -7746,4 +7742,4 @@ local = ["ctransformers", "llama-cpp-python", "sentence-transformers"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.11" -content-hash = "8ad605e7ea30f2819dbc03eac6c2e67576a98d1efa4890912414a7568fc27441" +content-hash = "fc078c55010bf3749e684cf032a4fc64b3918b15b60b4521c17a27815518032e" diff --git a/pyproject.toml b/pyproject.toml index 01e04fd5d..e77accc10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,6 +82,8 @@ passlib = "^1.7.4" bcrypt = "^4.0.1" python-jose = "^3.3.0" metaphor-python = "^0.1.11" +markupsafe = "^2.1.3" + [tool.poetry.group.dev.dependencies] black = "^23.1.0" From 35322e7d559a4f44030908e559ab2912ee2ae670 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Wed, 30 Aug 2023 16:37:53 -0300 Subject: [PATCH 05/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20import=20KeypairListComponent=20from=20correct=20path=20to?= =?UTF-8?q?=20fix=20compilation=20error=20=E2=9C=A8=20feat(parameterCompon?= =?UTF-8?q?ent):=20add=20support=20for=20editing=20key-value=20pairs=20in?= =?UTF-8?q?=20the=20parameter=20component=20=F0=9F=90=9B=20fix(genericIcon?= =?UTF-8?q?Component):=20fix=20stroke=20width=20prop=20name=20to=20strokeW?= =?UTF-8?q?idth=20to=20fix=20SVG=20rendering=20issue=20=F0=9F=90=9B=20fix(?= =?UTF-8?q?keypairListComponent):=20import=20GenericModal=20from=20correct?= =?UTF-8?q?=20path=20to=20fix=20compilation=20error=20=E2=9C=A8=20feat(key?= =?UTF-8?q?pairListComponent):=20add=20support=20for=20editing=20key-value?= =?UTF-8?q?=20pairs=20in=20the=20keypair=20list=20component=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(editNodeModal):=20import=20KeypairListComponent=20from?= =?UTF-8?q?=20correct=20path=20to=20fix=20compilation=20error=20=E2=9C=A8?= =?UTF-8?q?=20feat(editNodeModal):=20add=20support=20for=20editing=20key-v?= =?UTF-8?q?alue=20pairs=20in=20the=20edit=20node=20modal=20=F0=9F=90=9B=20?= =?UTF-8?q?fix(types):=20change=20value=20type=20in=20KeyPairListComponent?= =?UTF-8?q?=20to=20any=20to=20allow=20for=20any=20key-value=20pair?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/parameterComponent/index.tsx | 71 ++++++++++++------- .../components/genericIconComponent/index.tsx | 2 +- .../components/keypairListComponent/index.tsx | 34 +++++---- .../src/modals/EditNodeModal/index.tsx | 67 +++++++++++------ src/frontend/src/types/components/index.ts | 2 +- 5 files changed, 114 insertions(+), 62 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index afdaa397a..dbd091e63 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -16,6 +16,7 @@ import InputComponent from "../../../../components/inputComponent"; import InputFileComponent from "../../../../components/inputFileComponent"; import InputListComponent from "../../../../components/inputListComponent"; import IntComponent from "../../../../components/intComponent"; +import KeypairListComponent from "../../../../components/keypairListComponent"; import PromptAreaComponent from "../../../../components/promptComponent"; import TextAreaComponent from "../../../../components/textAreaComponent"; import ToggleShadComponent from "../../../../components/toggleShadComponent"; @@ -31,7 +32,6 @@ import { nodeNames, } from "../../../../utils/styleUtils"; import { classNames, groupByFamily } from "../../../../utils/utils"; -import KeypairListComponent from "../../../../components/keypairListComponent"; export default function ParameterComponent({ left, @@ -94,21 +94,44 @@ export default function ParameterComponent({ renderTooltips(); }; - const [arrayOfObjects, setArrayOfObjects] = useState([ - { key1: "value1", key2: "value2" }, - { key3: "value3", key4: "value4" }, - { key5: "value5", key6: "value6" }, - ]) + const [dict, setDict] = useState({ + key1: "value1", + key2: "value2", + key3: "value3", + key4: "value4", + key5: "value5", + key6: "value6", + } as {}); + const [dictArr, setDictArr] = useState([]); + useEffect(() => { + convertToArray(dict); + }, [dict]); - const handleOnNewValueTest = (newValue): void => { - let newData = cloneDeep(arrayOfObjects); - newData = newValue; - setArrayOfObjects(newData); + const convertToArray = (singleObject) => { + let arrConverted: any = []; + for (const key in singleObject) { + if (singleObject.hasOwnProperty(key)) { + const newObj = {}; + newObj[key] = singleObject[key]; + arrConverted.push(newObj); + } + } + setDictArr(arrConverted); }; - - + const convertToDict = (newValue): void => { + const flattenedObject = {}; + for (const obj of newValue) { + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + flattenedObject[key] = obj[key]; + } + } + } + let newData = cloneDeep(flattenedObject); + setDict(newData); + }; useEffect(() => { if (name === "openai_api_base") console.log(info); @@ -225,6 +248,15 @@ export default function ParameterComponent({ type === "int") && !optionalHandle ? ( <> + ) : left === true && type === "str" ? ( +
+ +
) : (
- ) - : left === true && type === "keypair" ? ( -
- -
- ) - : ( + ) : ( <> )} diff --git a/src/frontend/src/components/genericIconComponent/index.tsx b/src/frontend/src/components/genericIconComponent/index.tsx index a06707d74..0473c2d90 100644 --- a/src/frontend/src/components/genericIconComponent/index.tsx +++ b/src/frontend/src/components/genericIconComponent/index.tsx @@ -11,7 +11,7 @@ export default function IconComponent({ ); } diff --git a/src/frontend/src/components/keypairListComponent/index.tsx b/src/frontend/src/components/keypairListComponent/index.tsx index efb122414..be6ea1f64 100644 --- a/src/frontend/src/components/keypairListComponent/index.tsx +++ b/src/frontend/src/components/keypairListComponent/index.tsx @@ -2,6 +2,8 @@ import { useEffect } from "react"; import { KeyPairListComponent } from "../../types/components"; import _ from "lodash"; +import { TypeModal } from "../../constants/enums"; +import GenericModal from "../../modals/genericModal"; import { classNames } from "../../utils/utils"; import IconComponent from "../genericIconComponent"; import { Input } from "../ui/input"; @@ -26,10 +28,10 @@ export default function KeypairListComponent({ onChange(newInputList); }; - const handleChangeValue = (event, idx) => { + const handleChangeValue = (newValue, idx) => { const newInputList = _.cloneDeep(value); const key = Object.keys(newInputList[idx])[0]; - newInputList[idx][key] = event.target.value; + newInputList[idx][key] = newValue; onChange(newInputList); }; @@ -58,20 +60,24 @@ export default function KeypairListComponent({ } }} /> - handleChangeValue(event, index)} - onKeyDown={(e) => { - if (e.ctrlKey && e.key === "Backspace") { - e.preventDefault(); - e.stopPropagation(); - } + buttonText="Save" + modalTitle="Edit Value" + setValue={(value: string) => { + handleChangeValue(value, index); }} - /> + > + + + {index === value.length - 1 ? ( + + + + + ); +} diff --git a/src/frontend/src/utils/styleUtils.ts b/src/frontend/src/utils/styleUtils.ts index 31a7adf7e..8add1e6cf 100644 --- a/src/frontend/src/utils/styleUtils.ts +++ b/src/frontend/src/utils/styleUtils.ts @@ -74,6 +74,7 @@ import { X, XCircle, Zap, + BookMarked } from "lucide-react"; import { FaApple, FaGithub } from "react-icons/fa"; import { AirbyteIcon } from "../icons/Airbyte"; @@ -300,4 +301,5 @@ export const nodeIconsLucide: iconsType = { UserCog2, Key, Unplug, + BookMarked }; From 54e3fd15dc6594a0995cb81850948d15c643a592 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Tue, 5 Sep 2023 08:34:15 -0300 Subject: [PATCH 11/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20fix=20incorrect=20type=20check=20for=20dict=20and=20keypair?= =?UTF-8?q?=20components=20in=20ParameterComponent=20=F0=9F=90=9B=20fix(di?= =?UTF-8?q?ctComponent):=20fix=20import=20statement=20for=20DictComponentT?= =?UTF-8?q?ype=20in=20dictComponent=20=F0=9F=90=9B=20fix(keypairListCompon?= =?UTF-8?q?ent):=20fix=20import=20statement=20for=20KeyPairListComponentTy?= =?UTF-8?q?pe=20in=20keypairListComponent=20=F0=9F=90=9B=20fix(EditNodeMod?= =?UTF-8?q?al):=20fix=20incorrect=20type=20check=20for=20dict=20and=20keyp?= =?UTF-8?q?air=20components=20in=20EditNodeModal=20=F0=9F=90=9B=20fix(type?= =?UTF-8?q?s):=20rename=20KeyPairListComponent=20to=20KeyPairListComponent?= =?UTF-8?q?Type=20and=20add=20DictComponentType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericNode/components/parameterComponent/index.tsx | 4 ++-- src/frontend/src/components/dictComponent/index.tsx | 4 ++-- .../src/components/keypairListComponent/index.tsx | 4 ++-- src/frontend/src/modals/EditNodeModal/index.tsx | 4 ++-- src/frontend/src/types/components/index.ts | 9 ++++++++- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 81a821266..c5623d3fa 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -241,7 +241,7 @@ export default function ParameterComponent({ !optionalHandle ? ( <> ) - : left === true && type === "str" ? ( + : left === true && type === "dict" ? (
) - : left === true && type === "dict" ? ( + : left === true && type === "keypair" ? (
{ if (disabled) { onChange([""]); diff --git a/src/frontend/src/components/keypairListComponent/index.tsx b/src/frontend/src/components/keypairListComponent/index.tsx index 87cad64d0..26e6d7f46 100644 --- a/src/frontend/src/components/keypairListComponent/index.tsx +++ b/src/frontend/src/components/keypairListComponent/index.tsx @@ -1,5 +1,5 @@ import { useEffect } from "react"; -import { KeyPairListComponent } from "../../types/components"; +import { KeyPairListComponentType } from "../../types/components"; import _ from "lodash"; import { TypeModal } from "../../constants/enums"; @@ -14,7 +14,7 @@ export default function KeypairListComponent({ disabled, editNode = false, duplicateKey -}: KeyPairListComponent): JSX.Element { +}: KeyPairListComponentType): JSX.Element { useEffect(() => { if (disabled) { onChange([""]); diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx index 85a149db8..437cdf232 100644 --- a/src/frontend/src/modals/EditNodeModal/index.tsx +++ b/src/frontend/src/modals/EditNodeModal/index.tsx @@ -206,7 +206,7 @@ const EditNodeModal = forwardRef( /> ) : myData.node?.template[templateParam] - .type === "str" ? ( + .type === "dict" ? (
) : myData.node?.template[templateParam] - .type === "dict" ? ( + .type === "keypair" ? (
void; disabled: boolean; @@ -62,6 +62,13 @@ export type KeyPairListComponent = { duplicateKey?: boolean; }; +export type DictComponentType = { + value: any; + onChange: (value: string[]) => void; + disabled: boolean; + editNode?: boolean; +}; + export type TextAreaComponentType = { field_name?: string; nodeClass?: APIClassType; From 28c8b3160e0005e5baabcabfe72783907504db04 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Tue, 5 Sep 2023 10:58:11 -0300 Subject: [PATCH 12/56] =?UTF-8?q?=F0=9F=94=A7=20fix(parameterComponent):?= =?UTF-8?q?=20remove=20unused=20errorDuplicateKey=20state=20variable=20?= =?UTF-8?q?=F0=9F=94=A7=20fix(parameterComponent):=20remove=20unused=20dic?= =?UTF-8?q?t=20and=20dictArr=20state=20variables=20=F0=9F=94=A7=20fix(para?= =?UTF-8?q?meterComponent):=20remove=20unused=20useEffect=20hook=20?= =?UTF-8?q?=F0=9F=94=A7=20fix(parameterComponent):=20update=20onChange=20h?= =?UTF-8?q?andler=20to=20setObj=20instead=20of=20setDict=20=F0=9F=94=A7=20?= =?UTF-8?q?fix(keypairListComponent):=20remove=20commented=20out=20code=20?= =?UTF-8?q?for=20future=20feature=20=F0=9F=94=A7=20fix(EditNodeModal):=20u?= =?UTF-8?q?pdate=20condition=20to=20check=20for=20"keypairlist"=20type=20i?= =?UTF-8?q?nstead=20of=20"keypair"=20type=20=F0=9F=94=A7=20fix(types):=20u?= =?UTF-8?q?pdate=20onChange=20type=20in=20DictComponentType=20to=20accept?= =?UTF-8?q?=20any=20value=20=F0=9F=94=A7=20fix(reactflowUtils):=20remove?= =?UTF-8?q?=20unnecessary=20comments=20and=20newline=20at=20end=20of=20fil?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/parameterComponent/index.tsx | 37 +------------------ .../components/keypairListComponent/index.tsx | 36 ++++++++++++++++++ .../src/modals/EditNodeModal/index.tsx | 2 +- src/frontend/src/types/components/index.ts | 2 +- src/frontend/src/utils/reactflowUtils.ts | 4 +- 5 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index c5623d3fa..a2313e4c0 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -54,7 +54,6 @@ export default function ParameterComponent({ const updateNodeInternals = useUpdateNodeInternals(); const [position, setPosition] = useState(0); const { setTabsState, tabId, save, flows } = useContext(TabsContext); - const [errorDuplicateKey, setErrorDuplicateKey] = useState(false); const flow = flows.find((flow) => flow.id === tabId)?.data?.nodes ?? null; @@ -96,20 +95,6 @@ export default function ParameterComponent({ renderTooltips(); }; - const [dict, setDict] = useState({ - key1: "value1", - key2: "value2", - key3: "value3", - key4: "value4", - key5: "value5", - key6: "value6", - } as {}); - const [dictArr, setDictArr] = useState([] as string[]); - - useEffect(() => { - setDictArr(convertObjToArray(dict)); - }, [dict]); - const [obj, setObj] = useState({ arr: ["test", 123456, false, null], @@ -248,30 +233,12 @@ export default function ParameterComponent({ editNode={false} value={obj} onChange={(newValue) => { - setDict(newValue); + setObj(newValue); }} />
) - : left === true && type === "keypair" ? ( -
- { - setErrorDuplicateKey(hasDuplicateKeys(newValue)); - if(hasDuplicateKeys(newValue)){ - setDictArr(newValue); - } - else{ - setDict(convertArrayToObj(newValue)); - } - }} - /> -
- ) : ( + : ( { + // setDictArr(convertObjToArray(dict)); + // }, [dict]); + + // left === true && type === "keypairlist" ? ( + //
+ // { + // setErrorDuplicateKey(hasDuplicateKeys(newValue)); + // if(hasDuplicateKeys(newValue)){ + // setDictArr(newValue); + // } + // else{ + // setDict(convertArrayToObj(newValue)); + // } + // }} + // /> + //
+ // ) const handleChangeKey = (event, idx) => { diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx index 437cdf232..c47b2503a 100644 --- a/src/frontend/src/modals/EditNodeModal/index.tsx +++ b/src/frontend/src/modals/EditNodeModal/index.tsx @@ -219,7 +219,7 @@ const EditNodeModal = forwardRef(
) : myData.node?.template[templateParam] - .type === "keypair" ? ( + .type === "keypairlist" ? (
void; + onChange: (value) => void; disabled: boolean; editNode?: boolean; }; diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 1394203f1..7c58864b2 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -321,10 +321,10 @@ export function hasDuplicateKeys(array) { for (const obj of array) { for (const key in obj) { if (keys[key]) { - return true; // Duplicate key found + return true; } keys[key] = true; } } - return false; // No duplicate keys found + return false; } \ No newline at end of file From 628e6bace57af900d256cd16d9b0d6cc31c5820c Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Tue, 5 Sep 2023 11:13:42 -0300 Subject: [PATCH 13/56] =?UTF-8?q?=F0=9F=90=9B=20fix(EditNodeModal):=20remo?= =?UTF-8?q?ve=20unused=20state=20variable=20'errorDuplicateKey'=20to=20imp?= =?UTF-8?q?rove=20code=20cleanliness=20and=20remove=20unnecessary=20comple?= =?UTF-8?q?xity=20=F0=9F=94=A5=20chore(EditNodeModal):=20remove=20unused?= =?UTF-8?q?=20state=20variables=20'dict'=20and=20'dictArr'=20to=20improve?= =?UTF-8?q?=20code=20cleanliness=20and=20remove=20unnecessary=20complexity?= =?UTF-8?q?=20=F0=9F=94=A5=20chore(EditNodeModal):=20remove=20unused=20use?= =?UTF-8?q?Effect=20hook=20for=20'dict'=20state=20variable=20to=20improve?= =?UTF-8?q?=20code=20cleanliness=20and=20remove=20unnecessary=20complexity?= =?UTF-8?q?=20=F0=9F=94=A5=20chore(EditNodeModal):=20remove=20unused=20sta?= =?UTF-8?q?te=20variable=20'obj'=20to=20improve=20code=20cleanliness=20and?= =?UTF-8?q?=20remove=20unnecessary=20complexity=20=F0=9F=94=A5=20chore(Edi?= =?UTF-8?q?tNodeModal):=20remove=20unused=20state=20variable=20'myData'=20?= =?UTF-8?q?to=20improve=20code=20cleanliness=20and=20remove=20unnecessary?= =?UTF-8?q?=20complexity=20=F0=9F=94=A5=20chore(EditNodeModal):=20remove?= =?UTF-8?q?=20unused=20state=20variable=20'setMyData'=20to=20improve=20cod?= =?UTF-8?q?e=20cleanliness=20and=20remove=20unnecessary=20complexity=20?= =?UTF-8?q?=F0=9F=94=A5=20chore(EditNodeModal):=20remove=20unused=20state?= =?UTF-8?q?=20variable=20'setDict'=20to=20improve=20code=20cleanliness=20a?= =?UTF-8?q?nd=20remove=20unnecessary=20complexity=20=F0=9F=94=A5=20chore(E?= =?UTF-8?q?ditNodeModal):=20remove=20unused=20state=20variable=20'setDictA?= =?UTF-8?q?rr'=20to=20improve=20code=20cleanliness=20and=20remove=20unnece?= =?UTF-8?q?ssary=20complexity=20=F0=9F=94=A5=20chore(EditNodeModal):=20rem?= =?UTF-8?q?ove=20unused=20state=20variable=20'setObj'=20to=20improve=20cod?= =?UTF-8?q?e=20cleanliness=20and=20remove=20unnecessary=20complexity=20?= =?UTF-8?q?=F0=9F=94=A5=20chore(EditNodeModal):=20remove=20unused=20state?= =?UTF-8?q?=20variable=20'setTabsState'=20to=20improve=20code=20cleanlines?= =?UTF-8?q?s=20and=20remove=20unnecessary=20complexity=20=F0=9F=94=A5=20ch?= =?UTF-8?q?ore(EditNodeModal):=20remove=20unused=20state=20variable=20'tab?= =?UTF-8?q?Id'=20to=20improve=20code=20cleanliness=20and=20remove=20unnece?= =?UTF-8?q?ssary=20complexity=20=F0=9F=94=A5=20chore(EditNodeModal):=20rem?= =?UTF-8?q?ove=20unused=20state=20variable=20'reactFlowInstance'=20to=20im?= =?UTF-8?q?prove=20code=20cleanliness=20and=20remove=20unnecessary=20compl?= =?UTF-8?q?exity=20=F0=9F=94=A5=20chore(EditNodeModal):=20remove=20unused?= =?UTF-8?q?=20import=20for=20'typesContext'=20to=20improve=20code=20cleanl?= =?UTF-8?q?iness=20and=20remove=20unnecessary=20complexity=20=F0=9F=94=A5?= =?UTF-8?q?=20chore(EditNodeModal):=20remove=20unused=20import=20for=20'us?= =?UTF-8?q?eState'=20to=20improve=20code=20cleanliness=20and=20remove=20un?= =?UTF-8?q?necessary=20complexity=20=F0=9F=94=A5=20chore(EditNodeModal):?= =?UTF-8?q?=20remove=20unused=20import=20for=20'useEffect'=20to=20improve?= =?UTF-8?q?=20code=20cleanliness=20and=20remove=20unnecessary=20complexity?= =?UTF-8?q?=20=F0=9F=94=A5=20chore(EditNodeModal):=20remove=20unused=20imp?= =?UTF-8?q?ort=20for=20'forwardRef'=20to=20improve=20code=20cleanliness=20?= =?UTF-8?q?and=20remove=20unnecessary=20complexity=20=F0=9F=94=A5=20chore(?= =?UTF-8?q?EditNodeModal):=20remove=20unused=20import=20for=20'useContext'?= =?UTF-8?q?=20to=20improve=20code=20cleanliness=20and=20remove=20unnecessa?= =?UTF-8?q?ry=20complexity=20=F0=9F=94=A5=20chore(EditNodeModal):=20remove?= =?UTF-8?q?=20unused=20import=20for=20'classNames'=20to=20improve=20code?= =?UTF-8?q?=20cleanliness=20and=20remove=20unnecessary=20complexity=20?= =?UTF-8?q?=F0=9F=94=A5=20chore(EditNodeModal):=20remove=20unused=20import?= =?UTF-8?q?=20for=20'convertObjToArray'=20to=20improve=20code=20cleanlines?= =?UTF-8?q?s=20and=20remove=20unnecessary=20complexity=20=F0=9F=94=A5=20ch?= =?UTF-8?q?ore(EditNodeModal):=20remove=20unused=20import=20for=20'convert?= =?UTF-8?q?ArrayToObj'=20to=20improve=20code=20cleanliness=20and=20remove?= =?UTF-8?q?=20unnecessary=20complexity=20=F0=9F=94=A5=20chore(EditNodeModa?= =?UTF-8?q?l):=20remove=20unused=20import=20for=20'hasDuplicateKeys'=20to?= =?UTF-8?q?=20improve=20code=20cleanliness=20and=20remove=20unnecessary=20?= =?UTF-8?q?complexity=20=F0=9F=94=A5=20chore(EditNodeModal):=20remove=20un?= =?UTF-8?q?used=20import=20for=20'KeypairListComponent'=20to=20improve=20c?= =?UTF-8?q?ode=20cleanliness=20and=20remove=20unnecessary=20complexity=20?= =?UTF-8?q?=F0=9F=94=A5=20chore(EditNodeModal):=20remove=20unused=20import?= =?UTF-8?q?=20for=20'TextAreaComponent'=20to=20improve=20code=20cleanlines?= =?UTF-8?q?s=20and=20remove=20unnecessary=20complexity=20=F0=9F=94=A5=20ch?= =?UTF-8?q?ore(EditNodeModal):=20remove=20unused=20import=20for=20'useStat?= =?UTF-8?q?e'=20to=20improve=20code=20cleanliness=20and=20remove=20unneces?= =?UTF-8?q?sary=20complexity=20=F0=9F=94=A5=20chore(EditNodeModal):=20remo?= =?UTF-8?q?ve=20unused=20import=20for=20'useEffect'=20to=20improve=20code?= =?UTF-8?q?=20cleanliness=20and=20remove=20unnecessary=20complexity=20?= =?UTF-8?q?=F0=9F=94=A5=20chore(EditNodeModal):=20remove=20unused=20import?= =?UTF-8?q?=20for=20'useContext'=20to=20improve=20code=20cleanliness=20and?= =?UTF-8?q?=20remove=20unnecessary=20complexity=20=F0=9F=94=A5=20chore(Edi?= =?UTF-8?q?tNodeModal):=20remove=20unused=20import=20for=20'forwardRef'=20?= =?UTF-8?q?to=20improve=20code=20cleanliness=20and=20remove=20unnecessary?= =?UTF-8?q?=20complexity=20=F0=9F=94=A5=20chore(EditNodeModal):=20remove?= =?UTF-8?q?=20unused=20import=20for=20'classNames'=20to=20improve=20code?= =?UTF-8?q?=20cleanliness=20and=20remove=20unnecessary=20complexity=20?= =?UTF-8?q?=F0=9F=94=A5=20chore(EditNodeModal):=20remove=20unused=20import?= =?UTF-8?q?=20for=20'convertObjToArray'=20to=20improve=20code=20cleanlines?= =?UTF-8?q?s=20and=20remove=20unnecessary=20complexity=20=F0=9F=94=A5=20ch?= =?UTF-8?q?ore(EditNodeModal):=20remove=20unused=20import=20for=20'convert?= =?UTF-8?q?ArrayToObj'=20to=20improve=20code=20cleanliness=20and=20remove?= =?UTF-8?q?=20unnecessary=20complexity=20=F0=9F=94=A5=20chore(EditNodeModa?= =?UTF-8?q?l):=20remove=20unused=20import=20for=20'hasDuplicateKeys'=20to?= =?UTF-8?q?=20improve=20code=20cleanliness=20and=20remove=20unnecessary=20?= =?UTF-8?q?complexity=20=F0=9F=94=A5=20chore(EditNodeModal):=20remove?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modals/EditNodeModal/index.tsx | 43 ++----------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx index c47b2503a..f27347897 100644 --- a/src/frontend/src/modals/EditNodeModal/index.tsx +++ b/src/frontend/src/modals/EditNodeModal/index.tsx @@ -55,7 +55,6 @@ const EditNodeModal = forwardRef( const [myData, setMyData] = useState(data); const { setTabsState, tabId } = useContext(TabsContext); const { reactFlowInstance } = useContext(typesContext); - const [errorDuplicateKey, setErrorDuplicateKey] = useState(false); let disabled = reactFlowInstance @@ -86,19 +85,6 @@ const EditNodeModal = forwardRef( setMyData(data); // reset data to what it is on node when opening modal }, [modalOpen]); - const [dict, setDict] = useState({ - key1: "value1", - key2: "value2", - key3: "value3", - key4: "value4", - key5: "value5", - key6: "value6", - } as {}); - const [dictArr, setDictArr] = useState([] as string[]); - - useEffect(() => { - setDictArr(convertObjToArray(dict)); - }, [dict]); const [obj, setObj] = useState({ arr: ["test", 123456, false, null], @@ -135,8 +121,7 @@ const EditNodeModal = forwardRef(
limitScrollFieldsModal || - nodeLength > dictArr.length + nodeLength > limitScrollFieldsModal ? "overflow-scroll overflow-x-hidden custom-scroll" : "overflow-hidden" )} @@ -213,34 +198,12 @@ const EditNodeModal = forwardRef( editNode={false} value={obj} onChange={(newValue) => { - setDict(newValue); + setObj(newValue); }} />
) - : myData.node?.template[templateParam] - .type === "keypairlist" ? ( -
- { - setErrorDuplicateKey( - hasDuplicateKeys(newValue) - ); - if (hasDuplicateKeys(newValue)) { - setDictArr(newValue); - } else { - setDict( - convertArrayToObj(newValue) - ); - } - }} - /> -
- ) : myData.node.template[templateParam] + : myData.node.template[templateParam] .multiline ? ( Date: Fri, 8 Sep 2023 10:00:59 -0300 Subject: [PATCH 14/56] =?UTF-8?q?=F0=9F=8E=A8=20style(dictAreaModal):=20up?= =?UTF-8?q?date=20BaseModal=20size=20prop=20value=20to=20"medium-h-full"?= =?UTF-8?q?=20for=20better=20UI=20layout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/package-lock.json | 45 +++++++++---------- .../src/modals/dictAreaModal/index.tsx | 2 +- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/frontend/package-lock.json b/src/frontend/package-lock.json index 1ab8be47f..56eff5ba0 100644 --- a/src/frontend/package-lock.json +++ b/src/frontend/package-lock.json @@ -3131,6 +3131,26 @@ "tailwindcss": ">=3.0.0 || insiders" } }, + "node_modules/@testing-library/dom": { + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-9.3.1.tgz", + "integrity": "sha512-0DGPd9AR3+iDTjGoMpxIkAsUihHZ3Ai6CneU6bRRrffXMgzCdlNk43jTrD2/5LT6CBb3MWTP8v510JzYtahD2w==", + "dev": true, + "peer": true, + "dependencies": { + "@babel/code-frame": "^7.10.4", + "@babel/runtime": "^7.12.5", + "@types/aria-query": "^5.0.1", + "aria-query": "5.1.3", + "chalk": "^4.1.0", + "dom-accessibility-api": "^0.5.9", + "lz-string": "^1.5.0", + "pretty-format": "^27.0.2" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/@testing-library/jest-dom": { "version": "5.17.0", "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-5.17.0.tgz", @@ -3613,7 +3633,7 @@ "version": "16.18.46", "resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.46.tgz", "integrity": "sha512-Mnq3O9Xz52exs3mlxMcQuA7/9VFe/dXcrgAyfjLkABIqxXKOgBRjyazTxUbjsxDa4BP7hhPliyjVTP9RDP14xg==", - "dev": true + "devOptional": true }, "node_modules/@types/parse-json": { "version": "4.0.0", @@ -5529,7 +5549,6 @@ "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, "hasInstallScript": true, "optional": true, "os": [ @@ -10550,7 +10569,6 @@ "cpu": [ "arm" ], - "dev": true, "optional": true, "os": [ "android" @@ -10566,7 +10584,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "android" @@ -10582,7 +10599,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "android" @@ -10598,7 +10614,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "darwin" @@ -10614,7 +10629,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "darwin" @@ -10630,7 +10644,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "freebsd" @@ -10646,7 +10659,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "freebsd" @@ -10662,7 +10674,6 @@ "cpu": [ "arm" ], - "dev": true, "optional": true, "os": [ "linux" @@ -10678,7 +10689,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -10694,7 +10704,6 @@ "cpu": [ "ia32" ], - "dev": true, "optional": true, "os": [ "linux" @@ -10710,7 +10719,6 @@ "cpu": [ "loong64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -10726,7 +10734,6 @@ "cpu": [ "mips64el" ], - "dev": true, "optional": true, "os": [ "linux" @@ -10742,7 +10749,6 @@ "cpu": [ "ppc64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -10758,7 +10764,6 @@ "cpu": [ "riscv64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -10774,7 +10779,6 @@ "cpu": [ "s390x" ], - "dev": true, "optional": true, "os": [ "linux" @@ -10790,7 +10794,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -10806,7 +10809,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "netbsd" @@ -10822,7 +10824,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "openbsd" @@ -10838,7 +10839,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "sunos" @@ -10854,7 +10854,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "win32" @@ -10870,7 +10869,6 @@ "cpu": [ "ia32" ], - "dev": true, "optional": true, "os": [ "win32" @@ -10886,7 +10884,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "win32" diff --git a/src/frontend/src/modals/dictAreaModal/index.tsx b/src/frontend/src/modals/dictAreaModal/index.tsx index a8a5356a9..85e7d293d 100644 --- a/src/frontend/src/modals/dictAreaModal/index.tsx +++ b/src/frontend/src/modals/dictAreaModal/index.tsx @@ -22,7 +22,7 @@ export default function DictAreaModal({ const [dictObj, setDictObj] = useState(value); return ( - + {children} Edit Dictionary From 0aa39d8a8e5c4ad5e3b507139440383c7900512c Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Fri, 8 Sep 2023 10:11:32 -0300 Subject: [PATCH 15/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20import=20DictComponent=20from=20correct=20path=20to=20fix=20?= =?UTF-8?q?module=20not=20found=20error=20=F0=9F=90=9B=20fix(parameterComp?= =?UTF-8?q?onent):=20remove=20unused=20import=20of=20CodeAreaComponent=20t?= =?UTF-8?q?o=20improve=20code=20readability=20=F0=9F=90=9B=20fix(parameter?= =?UTF-8?q?Component):=20remove=20unused=20import=20of=20TabsContext=20to?= =?UTF-8?q?=20improve=20code=20readability=20=F0=9F=90=9B=20fix(parameterC?= =?UTF-8?q?omponent):=20remove=20unused=20import=20of=20typesContext=20to?= =?UTF-8?q?=20improve=20code=20readability=20=F0=9F=90=9B=20fix(parameterC?= =?UTF-8?q?omponent):=20remove=20unused=20import=20of=20TabsState=20to=20i?= =?UTF-8?q?mprove=20code=20readability=20=F0=9F=90=9B=20fix(parameterCompo?= =?UTF-8?q?nent):=20remove=20unused=20import=20of=20nodeColors=20to=20impr?= =?UTF-8?q?ove=20code=20readability=20=F0=9F=90=9B=20fix(parameterComponen?= =?UTF-8?q?t):=20remove=20unused=20import=20of=20nodeIconsLucide=20to=20im?= =?UTF-8?q?prove=20code=20readability=20=F0=9F=90=9B=20fix(parameterCompon?= =?UTF-8?q?ent):=20remove=20unused=20import=20of=20nodeNames=20to=20improv?= =?UTF-8?q?e=20code=20readability=20=F0=9F=90=9B=20fix(parameterComponent)?= =?UTF-8?q?:=20remove=20unused=20import=20of=20classNames=20to=20improve?= =?UTF-8?q?=20code=20readability=20=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20remove=20unused=20import=20of=20groupByFamily=20to=20improve?= =?UTF-8?q?=20code=20readability=20=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20remove=20unused=20import=20of=20useUpdateNodeInternals=20to?= =?UTF-8?q?=20improve=20code=20readability=20=F0=9F=90=9B=20fix(parameterC?= =?UTF-8?q?omponent):=20remove=20unused=20import=20of=20Position=20from=20?= =?UTF-8?q?reactflow=20to=20improve=20code=20readability=20=F0=9F=90=9B=20?= =?UTF-8?q?fix(parameterComponent):=20remove=20unused=20import=20of=20Hand?= =?UTF-8?q?le=20from=20reactflow=20to=20improve=20code=20readability=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):=20remove=20unused=20imp?= =?UTF-8?q?ort=20of=20types=20from=20reactflow=20to=20improve=20code=20rea?= =?UTF-8?q?dability=20=F0=9F=90=9B=20fix(parameterComponent):=20remove=20u?= =?UTF-8?q?nused=20import=20of=20React=20from=20react=20to=20improve=20cod?= =?UTF-8?q?e=20readability=20=F0=9F=90=9B=20fix(parameterComponent):=20rem?= =?UTF-8?q?ove=20unused=20import=20of=20useEffect=20from=20react=20to=20im?= =?UTF-8?q?prove=20code=20readability=20=F0=9F=90=9B=20fix(parameterCompon?= =?UTF-8?q?ent):=20remove=20unused=20import=20of=20useState=20from=20react?= =?UTF-8?q?=20to=20improve=20code=20readability=20=F0=9F=90=9B=20fix(param?= =?UTF-8?q?eterComponent):=20remove=20unused=20import=20of=20useContext=20?= =?UTF-8?q?from=20react=20to=20improve=20code=20readability=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(parameterComponent):=20remove=20unused=20import=20of=20R?= =?UTF-8?q?eactNode=20from=20react=20to=20improve=20code=20readability=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):=20remove=20unused=20imp?= =?UTF-8?q?ort=20of=20forwardRef=20from=20react=20to=20improve=20code=20re?= =?UTF-8?q?adability=20=F0=9F=90=9B=20fix(parameterComponent):=20remove=20?= =?UTF-8?q?unused=20import=20of=20useEffect=20from=20react=20to=20improve?= =?UTF-8?q?=20code=20readability=20=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20remove=20unused=20import=20of=20useState=20from=20react=20to?= =?UTF-8?q?=20improve=20code=20readability=20=F0=9F=90=9B=20fix(parameterC?= =?UTF-8?q?omponent):=20remove=20unused=20import=20of=20useState=20from=20?= =?UTF-8?q?react=20to=20improve=20code=20readability=20=F0=9F=90=9B=20fix(?= =?UTF-8?q?parameterComponent):=20remove=20unused=20import=20of=20useState?= =?UTF-8?q?=20from=20react=20to=20improve=20code=20readability=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):=20remove=20unused=20imp?= =?UTF-8?q?ort=20of=20useState=20from=20react=20to=20improve=20code=20read?= =?UTF-8?q?ability=20=F0=9F=90=9B=20fix(parameterComponent):=20remove=20un?= =?UTF-8?q?used=20import=20of=20useState=20from=20react=20to=20improve=20c?= =?UTF-8?q?ode=20readability=20=F0=9F=90=9B=20fix(parameterComponent):=20r?= =?UTF-8?q?emove=20unused=20import=20of=20useState=20from=20react=20to=20i?= =?UTF-8?q?mprove=20code=20readability=20=F0=9F=90=9B=20fix(parameterCompo?= =?UTF-8?q?nent):=20remove=20unused=20import=20of=20useState=20from=20reac?= =?UTF-8?q?t=20to=20improve=20code=20readability=20=F0=9F=90=9B=20fix(para?= =?UTF-8?q?meterComponent):=20remove=20unused=20import=20of=20useState=20f?= =?UTF-8?q?rom=20react=20to=20improve=20code=20readability=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(parameterComponent):=20remove=20unused=20import=20of=20u?= =?UTF-8?q?seState=20from=20react=20to=20improve=20code=20readability=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):=20remove=20unused=20imp?= =?UTF-8?q?ort=20of=20useState=20from=20react=20to=20improve=20code=20read?= =?UTF-8?q?ability=20=F0=9F=90=9B=20fix(parameterComponent):=20remove=20un?= =?UTF-8?q?used=20import=20of=20useState=20from=20react=20to=20improve=20c?= =?UTF-8?q?ode=20readability=20=F0=9F=90=9B=20fix(parameterComponent):=20r?= =?UTF-8?q?emove=20unused=20import=20of=20useState=20from=20react=20to=20i?= =?UTF-8?q?mprove=20code=20readability=20=F0=9F=90=9B=20fix(parameterCompo?= =?UTF-8?q?nent):=20remove=20unused=20import=20of=20useState=20from=20reac?= =?UTF-8?q?t=20to=20improve=20code=20readability=20=F0=9F=90=9B=20fix(para?= =?UTF-8?q?meterComponent):=20remove=20unused=20import=20of=20useState=20f?= =?UTF-8?q?rom=20react=20to=20improve=20code=20readability=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(parameterComponent):=20remove=20unused=20import=20of=20u?= =?UTF-8?q?seState=20from=20react=20to=20improve=20code=20readability=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):=20remove=20unused=20imp?= =?UTF-8?q?ort=20of=20useState=20from=20react=20to=20improve=20code=20read?= =?UTF-8?q?ability=20=F0=9F=90=9B=20fix(parameterComponent):=20remove=20un?= =?UTF-8?q?used=20import=20of=20useState=20from=20react=20to=20improve=20c?= =?UTF-8?q?ode=20readability=20=F0=9F=90=9B=20fix(parameterComponent):=20r?= =?UTF-8?q?emove=20unused=20import=20of=20useState=20from=20react=20to=20i?= =?UTF-8?q?mprove=20code=20readability=20=F0=9F=90=9B=20fix(parameterCompo?= =?UTF-8?q?nent):=20remove=20unused=20import=20of=20useState=20from=20reac?= =?UTF-8?q?t=20to=20improve=20code=20readability=20=F0=9F=90=9B=20fix(para?= =?UTF-8?q?meterComponent):=20remove=20unused=20import=20of=20useState=20f?= =?UTF-8?q?rom=20react=20to=20improve=20code=20readability=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(parameterComponent):=20remove=20unused=20import=20of=20u?= =?UTF-8?q?seState=20from=20react=20to=20improve=20code=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/parameterComponent/index.tsx | 50 ++++++++++++--- .../src/modals/EditNodeModal/index.tsx | 63 ++++++++++++++----- 2 files changed, 90 insertions(+), 23 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index a2313e4c0..50f14f7b4 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -9,6 +9,7 @@ import React, { import { Handle, Position, useUpdateNodeInternals } from "reactflow"; import ShadTooltip from "../../../../components/ShadTooltipComponent"; import CodeAreaComponent from "../../../../components/codeAreaComponent"; +import DictComponent from "../../../../components/dictComponent"; import Dropdown from "../../../../components/dropdownComponent"; import FloatComponent from "../../../../components/floatComponent"; import IconComponent from "../../../../components/genericIconComponent"; @@ -25,14 +26,18 @@ import { TabsContext } from "../../../../contexts/tabsContext"; import { typesContext } from "../../../../contexts/typesContext"; import { ParameterComponentType } from "../../../../types/components"; import { TabsState } from "../../../../types/tabs"; -import { convertArrayToObj, convertObjToArray, hasDuplicateKeys, isValidConnection } from "../../../../utils/reactflowUtils"; +import { + convertArrayToObj, + convertObjToArray, + hasDuplicateKeys, + isValidConnection, +} from "../../../../utils/reactflowUtils"; import { nodeColors, nodeIconsLucide, nodeNames, } from "../../../../utils/styleUtils"; import { classNames, groupByFamily } from "../../../../utils/utils"; -import DictComponent from "../../../../components/dictComponent"; export default function ParameterComponent({ left, @@ -95,7 +100,6 @@ export default function ParameterComponent({ renderTooltips(); }; - const [obj, setObj] = useState({ arr: ["test", 123456, false, null], boolean: false, @@ -107,9 +111,24 @@ export default function ParameterComponent({ k2: "123", k3: false, }, - string: "string" + string: "string", }); + const [errorDuplicateKey, setErrorDuplicateKey] = useState(false); + const [dict, setDict] = useState({ + key1: "value1", + key2: "value2", + key3: "value3", + key4: "value4", + key5: "value5", + key6: "value6", + } as {}); + const [dictArr, setDictArr] = useState([] as string[]); + + useEffect(() => { + setDictArr(convertObjToArray(dict)); + }, [dict]); + useEffect(() => { if (name === "openai_api_base") console.log(info); // @ts-ignore @@ -225,8 +244,7 @@ export default function ParameterComponent({ type === "int") && !optionalHandle ? ( <> - ) - : left === true && type === "dict" ? ( + ) : left === true && type === "nested_dict" ? (
- ) - : ( + ) : left === true && type === "dict" ? ( +
+ { + setErrorDuplicateKey(hasDuplicateKeys(newValue)); + if (hasDuplicateKeys(newValue)) { + setDictArr(newValue); + } else { + setDict(convertArrayToObj(newValue)); + } + }} + /> +
+ ) : ( { + setDictArr(convertObjToArray(dict)); + }, [dict]); return ( @@ -189,21 +202,41 @@ const EditNodeModal = forwardRef( handleOnNewValue(value, templateParam); }} /> - ) - : myData.node?.template[templateParam] + ) : myData.node?.template[templateParam] + .type === "nested_dict" ? ( +
+ { + setObj(newValue); + }} + /> +
+ ) : myData.node?.template[templateParam] .type === "dict" ? (
- { - setObj(newValue); - }} - /> + { + setErrorDuplicateKey( + hasDuplicateKeys(newValue) + ); + if (hasDuplicateKeys(newValue)) { + setDictArr(newValue); + } else { + setDict( + convertArrayToObj(newValue) + ); + } + }} + />
- ) - : myData.node.template[templateParam] + ) : myData.node.template[templateParam] .multiline ? ( Date: Thu, 14 Sep 2023 14:09:06 -0300 Subject: [PATCH 16/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20fix=20type=20comparison=20for=20"NestedDict"=20to=20improve?= =?UTF-8?q?=20accuracy=20and=20consistency=20=F0=9F=90=9B=20fix(EditNodeMo?= =?UTF-8?q?dal):=20fix=20type=20comparison=20for=20"NestedDict"=20to=20imp?= =?UTF-8?q?rove=20accuracy=20and=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericNode/components/parameterComponent/index.tsx | 2 +- src/frontend/src/modals/EditNodeModal/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 50f14f7b4..998186f83 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -244,7 +244,7 @@ export default function ParameterComponent({ type === "int") && !optionalHandle ? ( <> - ) : left === true && type === "nested_dict" ? ( + ) : left === true && type === "NestedDict" ? (
) : myData.node?.template[templateParam] - .type === "nested_dict" ? ( + .type === "NestedDict" ? (
Date: Thu, 14 Sep 2023 14:09:18 -0300 Subject: [PATCH 17/56] =?UTF-8?q?=E2=9C=A8=20feat(field=5Ftyping):=20add?= =?UTF-8?q?=20NestedDict=20type=20alias=20to=20improve=20code=20readabilit?= =?UTF-8?q?y=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/field_typing/__init__.py | 3 +++ src/backend/langflow/field_typing/base.py | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 src/backend/langflow/field_typing/__init__.py create mode 100644 src/backend/langflow/field_typing/base.py diff --git a/src/backend/langflow/field_typing/__init__.py b/src/backend/langflow/field_typing/__init__.py new file mode 100644 index 000000000..927716b11 --- /dev/null +++ b/src/backend/langflow/field_typing/__init__.py @@ -0,0 +1,3 @@ +from .base import NestedDict + +__all__ = ["NestedDict"] diff --git a/src/backend/langflow/field_typing/base.py b/src/backend/langflow/field_typing/base.py new file mode 100644 index 000000000..ed3219888 --- /dev/null +++ b/src/backend/langflow/field_typing/base.py @@ -0,0 +1,4 @@ +from typing import Union, Dict + +# Type alias for more complex dicts +NestedDict = Dict[str, Union[str, Dict]] From 6b129b4d44a0ba7c978cf923ae7591f08c2e4948 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Thu, 14 Sep 2023 14:32:03 -0300 Subject: [PATCH 18/56] =?UTF-8?q?=F0=9F=90=9B=20fix(dictComponent):=20fix?= =?UTF-8?q?=20placeholder=20text=20in=20input=20field=20to=20improve=20cla?= =?UTF-8?q?rity=20and=20user=20experience=20=F0=9F=94=80=20refactor(dictCo?= =?UTF-8?q?mponent):=20reorganize=20imports=20for=20better=20readability?= =?UTF-8?q?=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/dictComponent/index.tsx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/frontend/src/components/dictComponent/index.tsx b/src/frontend/src/components/dictComponent/index.tsx index ef1a31ffc..d55f194f5 100644 --- a/src/frontend/src/components/dictComponent/index.tsx +++ b/src/frontend/src/components/dictComponent/index.tsx @@ -1,9 +1,9 @@ import { useEffect } from "react"; import { DictComponentType } from "../../types/components"; +import DictAreaModal from "../../modals/dictAreaModal"; import { classNames } from "../../utils/utils"; import { Input } from "../ui/input"; -import DictAreaModal from "../../modals/dictAreaModal"; export default function DictComponent({ value, @@ -27,19 +27,19 @@ export default function DictComponent({ {
{ - onChange(obj); - }} + value={value} + onChange={(obj) => { + onChange(obj); + }} > - +
} From 9e4f30f77447b825ccece696c3093af12da3d64e Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Thu, 14 Sep 2023 14:32:11 -0300 Subject: [PATCH 19/56] =?UTF-8?q?=F0=9F=94=80=20refactor(parameterComponen?= =?UTF-8?q?t):=20remove=20initial=20values=20from=20dict=20state=20and=20d?= =?UTF-8?q?ictArr=20state=20to=20improve=20code=20readability=20and=20main?= =?UTF-8?q?tainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericNode/components/parameterComponent/index.tsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 50f14f7b4..e25dda62b 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -115,14 +115,7 @@ export default function ParameterComponent({ }); const [errorDuplicateKey, setErrorDuplicateKey] = useState(false); - const [dict, setDict] = useState({ - key1: "value1", - key2: "value2", - key3: "value3", - key4: "value4", - key5: "value5", - key6: "value6", - } as {}); + const [dict, setDict] = useState({} as {}); const [dictArr, setDictArr] = useState([] as string[]); useEffect(() => { From 81bd3666540f582410f1989d7c6072c866955827 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Thu, 14 Sep 2023 14:39:07 -0300 Subject: [PATCH 20/56] =?UTF-8?q?=F0=9F=94=A8=20refactor(parameterComponen?= =?UTF-8?q?t):=20update=20initial=20state=20of=20dict=20to=20include=20a?= =?UTF-8?q?=20default=20key-value=20pair=20for=20better=20clarity=20and=20?= =?UTF-8?q?consistency=20=F0=9F=94=A8=20refactor(EditNodeModal):=20update?= =?UTF-8?q?=20initial=20state=20of=20dict=20to=20include=20a=20default=20k?= =?UTF-8?q?ey-value=20pair=20for=20better=20clarity=20and=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericNode/components/parameterComponent/index.tsx | 4 +++- src/frontend/src/modals/EditNodeModal/index.tsx | 7 +------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index bc03603be..7f5f5dc84 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -115,7 +115,9 @@ export default function ParameterComponent({ }); const [errorDuplicateKey, setErrorDuplicateKey] = useState(false); - const [dict, setDict] = useState({} as {}); + const [dict, setDict] = useState({ + yourKey: "yourValue", + } as {}); const [dictArr, setDictArr] = useState([] as string[]); useEffect(() => { diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx index 4e1e2bb83..abc9e0aff 100644 --- a/src/frontend/src/modals/EditNodeModal/index.tsx +++ b/src/frontend/src/modals/EditNodeModal/index.tsx @@ -101,12 +101,7 @@ const EditNodeModal = forwardRef( const [errorDuplicateKey, setErrorDuplicateKey] = useState(false); const [dict, setDict] = useState({ - key1: "value1", - key2: "value2", - key3: "value3", - key4: "value4", - key5: "value5", - key6: "value6", + yourKey: "yourValue", } as {}); const [dictArr, setDictArr] = useState([] as string[]); From 1c1d6d2c023444034f0b07fc86069dc2e1eebad0 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Thu, 14 Sep 2023 19:53:39 -0300 Subject: [PATCH 21/56] =?UTF-8?q?=F0=9F=94=A7=20fix(parameterComponent):?= =?UTF-8?q?=20remove=20unused=20longString=20variable=20to=20improve=20cod?= =?UTF-8?q?e=20readability=20and=20reduce=20unnecessary=20code=20?= =?UTF-8?q?=F0=9F=94=A7=20fix(parameterComponent):=20move=20DictComponent?= =?UTF-8?q?=20and=20KeypairListComponent=20rendering=20logic=20to=20the=20?= =?UTF-8?q?correct=20position=20to=20fix=20rendering=20issues=20?= =?UTF-8?q?=F0=9F=94=A7=20fix(keypairListComponent):=20remove=20unused=20i?= =?UTF-8?q?mports=20and=20fix=20formatting=20to=20improve=20code=20readabi?= =?UTF-8?q?lity=20=F0=9F=94=A7=20fix(keypairListComponent):=20fix=20handle?= =?UTF-8?q?ChangeKey=20function=20name=20to=20improve=20code=20clarity=20?= =?UTF-8?q?=F0=9F=94=A7=20fix(keypairListComponent):=20fix=20className=20p?= =?UTF-8?q?rop=20in=20Input=20component=20to=20improve=20code=20readabilit?= =?UTF-8?q?y=20=F0=9F=94=A7=20fix(keypairListComponent):=20remove=20unused?= =?UTF-8?q?=20GenericModal=20component=20and=20fix=20formatting=20to=20imp?= =?UTF-8?q?rove=20code=20readability=20=F0=9F=94=A7=20fix(reactflowUtils.t?= =?UTF-8?q?s):=20fix=20formatting=20and=20remove=20unnecessary=20whitespac?= =?UTF-8?q?e=20to=20improve=20code=20readability=20=F0=9F=94=A7=20fix(reac?= =?UTF-8?q?tflowUtils.ts):=20fix=20function=20names=20and=20formatting=20t?= =?UTF-8?q?o=20improve=20code=20readability=20=F0=9F=94=A7=20fix(reactflow?= =?UTF-8?q?Utils.ts):=20fix=20formatting=20and=20remove=20unnecessary=20wh?= =?UTF-8?q?itespace=20to=20improve=20code=20readability=20=F0=9F=94=A7=20f?= =?UTF-8?q?ix(reactflowUtils.ts):=20fix=20formatting=20and=20remove=20unne?= =?UTF-8?q?cessary=20whitespace=20to=20improve=20code=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/parameterComponent/index.tsx | 61 ++++++++++--------- .../components/keypairListComponent/index.tsx | 39 +++++------- src/frontend/src/utils/reactflowUtils.ts | 23 ++++--- 3 files changed, 56 insertions(+), 67 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 7f5f5dc84..f0264ee2d 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -103,8 +103,6 @@ export default function ParameterComponent({ const [obj, setObj] = useState({ arr: ["test", 123456, false, null], boolean: false, - longString: - "long string long string long string long string long string long string", number: 123456, try: { k1: 123, @@ -239,34 +237,6 @@ export default function ParameterComponent({ type === "int") && !optionalHandle ? ( <> - ) : left === true && type === "NestedDict" ? ( -
- { - setObj(newValue); - }} - /> -
- ) : left === true && type === "dict" ? ( -
- { - setErrorDuplicateKey(hasDuplicateKeys(newValue)); - if (hasDuplicateKeys(newValue)) { - setDictArr(newValue); - } else { - setDict(convertArrayToObj(newValue)); - } - }} - /> -
) : (
+ ) : left === true && type === "NestedDict" ? ( +
+ { + setObj(newValue); + data.node!.template[name].value = newValue; + console.log(data); + }} + /> +
+ ) : left === true && type === "dict" ? ( +
+ { + setErrorDuplicateKey(hasDuplicateKeys(newValue)); + if (hasDuplicateKeys(newValue)) { + setDictArr(newValue); + } else { + setDict(convertArrayToObj(newValue)); + data.node!.template[name].value = convertArrayToObj(newValue); + } + }} + /> +
) : ( <> )} diff --git a/src/frontend/src/components/keypairListComponent/index.tsx b/src/frontend/src/components/keypairListComponent/index.tsx index ef3f58e39..b88b17946 100644 --- a/src/frontend/src/components/keypairListComponent/index.tsx +++ b/src/frontend/src/components/keypairListComponent/index.tsx @@ -2,8 +2,6 @@ import { useEffect } from "react"; import { KeyPairListComponentType } from "../../types/components"; import _ from "lodash"; -import { TypeModal } from "../../constants/enums"; -import GenericModal from "../../modals/genericModal"; import { classNames } from "../../utils/utils"; import IconComponent from "../genericIconComponent"; import { Input } from "../ui/input"; @@ -13,7 +11,7 @@ export default function KeypairListComponent({ onChange, disabled, editNode = false, - duplicateKey + duplicateKey, }: KeyPairListComponentType): JSX.Element { useEffect(() => { if (disabled) { @@ -56,9 +54,8 @@ export default function KeypairListComponent({ // /> //
// ) - - const handleChangeKey = (event, idx) => { + const handleChangeKey = (event, idx) => { const newInputList = _.cloneDeep(value); const oldKey = Object.keys(newInputList[idx])[0]; const updatedObj = { [event.target.value]: newInputList[idx][oldKey] }; @@ -89,10 +86,8 @@ export default function KeypairListComponent({ type="text" value={key} className={classNames( - editNode - ? "input-edit-node" - : "", - duplicateKey ? "input-invalid" : "" + editNode ? "input-edit-node" : "", + duplicateKey ? "input-invalid" : "" )} placeholder="Type key..." onChange={(event) => handleChangeKey(event, index)} @@ -103,23 +98,17 @@ export default function KeypairListComponent({ } }} /> - { - handleChangeValue(value, index); - }} - > - - + className={editNode ? "input-edit-node" : ""} + placeholder="Click to input a value..." + onChange={(event) => + handleChangeValue(event.target.value, index) + } + /> {index === value.length - 1 ? (
@@ -388,7 +387,7 @@ export default function ParameterComponent({ { setErrorDuplicateKey(hasDuplicateKeys(newValue)); From dd556c518dc2e58654828f18d3d2a2d138d96967 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Fri, 15 Sep 2023 08:47:51 -0300 Subject: [PATCH 23/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20remove=20unnecessary=20useEffect=20hook=20that=20sets=20dict?= =?UTF-8?q?Arr=20state=20=F0=9F=90=9B=20fix(parameterComponent):=20update?= =?UTF-8?q?=20value=20prop=20of=20KeypairListComponent=20to=20use=20conver?= =?UTF-8?q?tObjToArray(dict)=20instead=20of=20dict?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericNode/components/parameterComponent/index.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 0aa2cbf71..56d5562bc 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -118,10 +118,6 @@ export default function ParameterComponent({ } as {}); const [dictArr, setDictArr] = useState([] as string[]); - useEffect(() => { - setDictArr(convertObjToArray(dict)); - }, [dict]); - useEffect(() => { if (name === "openai_api_base") console.log(info); // @ts-ignore @@ -387,7 +383,7 @@ export default function ParameterComponent({ { setErrorDuplicateKey(hasDuplicateKeys(newValue)); From a6751d4a17ee8d7b8cfbccf7f603e3a1ea5d4c1c Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Fri, 15 Sep 2023 08:48:23 -0300 Subject: [PATCH 24/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20fix=20nullish=20coalescing=20operator=20usage=20to=20prevent?= =?UTF-8?q?=20potential=20error=20when=20accessing=20nested=20object=20pro?= =?UTF-8?q?perties?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericNode/components/parameterComponent/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 56d5562bc..acf643965 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -383,7 +383,10 @@ export default function ParameterComponent({ { setErrorDuplicateKey(hasDuplicateKeys(newValue)); From 55513a34a341d3b648bc117cdee5920e36fdc592 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Fri, 15 Sep 2023 09:27:48 -0300 Subject: [PATCH 25/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20fix=20logic=20for=20setting=20default=20value=20in=20Paramet?= =?UTF-8?q?erComponent=20=F0=9F=90=9B=20fix(dictComponent):=20fix=20class?= =?UTF-8?q?=20name=20for=20disabled=20input=20in=20DictComponent=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(keypairListComponent):=20remove=20unnecessar?= =?UTF-8?q?y=20disabled=20prop=20from=20Input=20component=20in=20KeypairLi?= =?UTF-8?q?stComponent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericNode/components/parameterComponent/index.tsx | 5 +++-- src/frontend/src/components/dictComponent/index.tsx | 5 +++-- src/frontend/src/components/keypairListComponent/index.tsx | 2 -- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index acf643965..5be56e31c 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -384,8 +384,9 @@ export default function ParameterComponent({ disabled={disabled} editNode={false} value={ - convertObjToArray(data.node!.template[name].value) ?? - convertObjToArray(dict) + convertObjToArray(data.node!.template[name].value).length === 0 + ? convertObjToArray(dict) + : convertObjToArray(data.node!.template[name].value) } duplicateKey={errorDuplicateKey} onChange={(newValue: string[]) => { diff --git a/src/frontend/src/components/dictComponent/index.tsx b/src/frontend/src/components/dictComponent/index.tsx index d55f194f5..fd55430bb 100644 --- a/src/frontend/src/components/dictComponent/index.tsx +++ b/src/frontend/src/components/dictComponent/index.tsx @@ -33,10 +33,11 @@ export default function DictComponent({ }} > diff --git a/src/frontend/src/components/keypairListComponent/index.tsx b/src/frontend/src/components/keypairListComponent/index.tsx index b88b17946..d555b1ead 100644 --- a/src/frontend/src/components/keypairListComponent/index.tsx +++ b/src/frontend/src/components/keypairListComponent/index.tsx @@ -82,7 +82,6 @@ export default function KeypairListComponent({ return (
Date: Fri, 15 Sep 2023 14:02:21 -0300 Subject: [PATCH 26/56] =?UTF-8?q?=F0=9F=94=A5=20refactor(keypairListCompon?= =?UTF-8?q?ent):=20remove=20commented=20out=20code=20and=20unused=20import?= =?UTF-8?q?s=20for=20cleaner=20code=20=F0=9F=90=9B=20fix(reactflowUtils.ts?= =?UTF-8?q?):=20add=20space=20before=20key=20in=20flattenedObject=20to=20p?= =?UTF-8?q?revent=20ordering=20when=20adding=20new=20keys=20to=20the=20obj?= =?UTF-8?q?ect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/keypairListComponent/index.tsx | 38 +------------------ src/frontend/src/utils/reactflowUtils.ts | 2 +- 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/src/frontend/src/components/keypairListComponent/index.tsx b/src/frontend/src/components/keypairListComponent/index.tsx index d555b1ead..f33c3aa2b 100644 --- a/src/frontend/src/components/keypairListComponent/index.tsx +++ b/src/frontend/src/components/keypairListComponent/index.tsx @@ -19,42 +19,6 @@ export default function KeypairListComponent({ } }, [disabled]); - //when this feature is available, this code below must be in the parent component - // const [errorDuplicateKey, setErrorDuplicateKey] = useState(false); - // const [dict, setDict] = useState({ - // key1: "value1", - // key2: "value2", - // key3: "value3", - // key4: "value4", - // key5: "value5", - // key6: "value6", - // } as {}); - // const [dictArr, setDictArr] = useState([] as string[]); - - // useEffect(() => { - // setDictArr(convertObjToArray(dict)); - // }, [dict]); - - // left === true && type === "keypairlist" ? ( - //
- // { - // setErrorDuplicateKey(hasDuplicateKeys(newValue)); - // if(hasDuplicateKeys(newValue)){ - // setDictArr(newValue); - // } - // else{ - // setDict(convertArrayToObj(newValue)); - // } - // }} - // /> - //
- // ) - const handleChangeKey = (event, idx) => { const newInputList = _.cloneDeep(value); const oldKey = Object.keys(newInputList[idx])[0]; @@ -83,7 +47,7 @@ export default function KeypairListComponent({
Date: Fri, 15 Sep 2023 14:50:27 -0300 Subject: [PATCH 27/56] =?UTF-8?q?=F0=9F=90=9B=20fix(reactflowUtils.ts):=20?= =?UTF-8?q?remove=20unnecessary=20space=20in=20key=20assignment=20to=20mai?= =?UTF-8?q?ntain=20consistent=20object=20key=20order?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/utils/reactflowUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 340fff53f..250ce4054 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -307,7 +307,7 @@ export function convertArrayToObj(newValue) { for (const obj of newValue) { for (const key in obj) { if (obj.hasOwnProperty(key)) { - flattenedObject[' ' + key] = obj[key]; //added space to dont order when add new keys to object + flattenedObject[key] = obj[key]; //added space to dont order when add new keys to object } } } From ef5a3fb3552350e763550c39e59ad83c88ce2681 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Fri, 15 Sep 2023 15:49:37 -0300 Subject: [PATCH 28/56] =?UTF-8?q?=F0=9F=94=A7=20fix(parameterComponent):?= =?UTF-8?q?=20remove=20unused=20imports=20and=20variables=20to=20improve?= =?UTF-8?q?=20code=20cleanliness=20and=20readability=20=F0=9F=94=A7=20fix(?= =?UTF-8?q?parameterComponent):=20update=20useState=20initial=20value=20fo?= =?UTF-8?q?r=20dictArr=20to=20be=20an=20array=20of=20objects=20instead=20o?= =?UTF-8?q?f=20an=20empty=20array=20=F0=9F=94=A7=20fix(parameterComponent)?= =?UTF-8?q?:=20update=20value=20prop=20in=20ParameterInputListComponent=20?= =?UTF-8?q?to=20handle=20cases=20where=20data.node!.template[name].value?= =?UTF-8?q?=20is=20null=20or=20an=20empty=20array=20=F0=9F=94=A7=20fix(par?= =?UTF-8?q?ameterComponent):=20update=20onChange=20prop=20in=20ParameterIn?= =?UTF-8?q?putListComponent=20to=20handle=20any=20type=20of=20newValue=20i?= =?UTF-8?q?nstead=20of=20just=20string[]=20=F0=9F=94=A7=20fix(keypairListC?= =?UTF-8?q?omponent):=20update=20className=20condition=20to=20check=20if?= =?UTF-8?q?=20value=20is=20null=20or=20undefined=20before=20checking=20its?= =?UTF-8?q?=20length=20=F0=9F=94=A7=20fix(editNodeModal):=20remove=20unuse?= =?UTF-8?q?d=20imports=20and=20variables=20to=20improve=20code=20cleanline?= =?UTF-8?q?ss=20and=20readability=20=F0=9F=94=A7=20fix(editNodeModal):=20u?= =?UTF-8?q?pdate=20useState=20initial=20value=20for=20dictArr=20to=20be=20?= =?UTF-8?q?an=20array=20of=20objects=20instead=20of=20an=20empty=20array?= =?UTF-8?q?=20=F0=9F=94=A7=20fix(editNodeModal):=20update=20value=20prop?= =?UTF-8?q?=20in=20KeypairListComponent=20to=20handle=20cases=20where=20my?= =?UTF-8?q?Data.node.template[templateParam].value=20is=20null=20or=20an?= =?UTF-8?q?=20empty=20array=20=F0=9F=94=A7=20fix(editNodeModal):=20update?= =?UTF-8?q?=20onChange=20prop=20in=20KeypairListComponent=20to=20handle=20?= =?UTF-8?q?any=20type=20of=20newValue=20instead=20of=20just=20string[]=20?= =?UTF-8?q?=F0=9F=94=A7=20fix(types):=20update=20onChange=20type=20in=20Ke?= =?UTF-8?q?yPairListComponentType=20to=20accept=20an=20array=20of=20object?= =?UTF-8?q?s=20instead=20of=20an=20array=20of=20strings=20=F0=9F=94=A7=20f?= =?UTF-8?q?ix(reactflowUtils):=20remove=20unused=20convertArrayToObj=20fun?= =?UTF-8?q?ction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/parameterComponent/index.tsx | 24 ++++++------ .../components/keypairListComponent/index.tsx | 4 +- .../src/modals/EditNodeModal/index.tsx | 39 ++++++++++--------- src/frontend/src/types/components/index.ts | 26 ++++++------- src/frontend/src/utils/reactflowUtils.ts | 14 ------- 5 files changed, 47 insertions(+), 60 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 5be56e31c..3bb92d34e 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -27,8 +27,6 @@ import { typesContext } from "../../../../contexts/typesContext"; import { ParameterComponentType } from "../../../../types/components"; import { TabsState } from "../../../../types/tabs"; import { - convertArrayToObj, - convertObjToArray, hasDuplicateKeys, isValidConnection, } from "../../../../utils/reactflowUtils"; @@ -113,10 +111,9 @@ export default function ParameterComponent({ }); const [errorDuplicateKey, setErrorDuplicateKey] = useState(false); - const [dict, setDict] = useState({ - yourKey: "yourValue", - } as {}); - const [dictArr, setDictArr] = useState([] as string[]); + const [dictArr, setDictArr] = useState([ + { yourKey: "yourValue" }, + ] as Object[]); useEffect(() => { if (name === "openai_api_base") console.log(info); @@ -384,18 +381,21 @@ export default function ParameterComponent({ disabled={disabled} editNode={false} value={ - convertObjToArray(data.node!.template[name].value).length === 0 - ? convertObjToArray(dict) - : convertObjToArray(data.node!.template[name].value) + data.node!.template[name].value?.length === 0 || + !data.node!.template[name].value + ? dictArr + : data.node!.template[name].value } duplicateKey={errorDuplicateKey} - onChange={(newValue: string[]) => { + onChange={(newValue) => { setErrorDuplicateKey(hasDuplicateKeys(newValue)); if (hasDuplicateKeys(newValue)) { setDictArr(newValue); } else { - setDict(convertArrayToObj(newValue)); - data.node!.template[name].value = convertArrayToObj(newValue); + setDictArr(newValue); + console.log(newValue); + + data.node!.template[name].value = newValue; } }} /> diff --git a/src/frontend/src/components/keypairListComponent/index.tsx b/src/frontend/src/components/keypairListComponent/index.tsx index f33c3aa2b..580de2cfd 100644 --- a/src/frontend/src/components/keypairListComponent/index.tsx +++ b/src/frontend/src/components/keypairListComponent/index.tsx @@ -37,11 +37,11 @@ export default function KeypairListComponent({ return (
1 && editNode ? "my-1" : "", + value?.length > 1 && editNode ? "my-1" : "", "flex flex-col gap-3" )} > - {value.map((obj, index) => { + {value?.map((obj, index) => { return Object.keys(obj).map((key, idx) => { return (
diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx index abc9e0aff..390904ef4 100644 --- a/src/frontend/src/modals/EditNodeModal/index.tsx +++ b/src/frontend/src/modals/EditNodeModal/index.tsx @@ -28,11 +28,7 @@ import { TabsContext } from "../../contexts/tabsContext"; import { typesContext } from "../../contexts/typesContext"; import { NodeDataType } from "../../types/flow"; import { TabsState } from "../../types/tabs"; -import { - convertArrayToObj, - convertObjToArray, - hasDuplicateKeys, -} from "../../utils/reactflowUtils"; +import { hasDuplicateKeys } from "../../utils/reactflowUtils"; import { classNames } from "../../utils/utils"; import BaseModal from "../baseModal"; @@ -100,14 +96,9 @@ const EditNodeModal = forwardRef( }); const [errorDuplicateKey, setErrorDuplicateKey] = useState(false); - const [dict, setDict] = useState({ - yourKey: "yourValue", - } as {}); - const [dictArr, setDictArr] = useState([] as string[]); - - useEffect(() => { - setDictArr(convertObjToArray(dict)); - }, [dict]); + const [dictArr, setDictArr] = useState([ + { yourKey: "yourValue" }, + ] as Object[]); return ( @@ -214,19 +205,29 @@ const EditNodeModal = forwardRef(
{ + onChange={(newValue) => { setErrorDuplicateKey( hasDuplicateKeys(newValue) ); if (hasDuplicateKeys(newValue)) { setDictArr(newValue); } else { - setDict( - convertArrayToObj(newValue) - ); + setDictArr(newValue); + myData.node!.template[ + templateParam + ].value = newValue; } }} /> diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index e63a21482..3749a80c7 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -56,7 +56,7 @@ export type InputListComponentType = { export type KeyPairListComponentType = { value: any; - onChange: (value: string[]) => void; + onChange: (value: Object[]) => void; disabled: boolean; editNode?: boolean; duplicateKey?: boolean; @@ -123,18 +123,18 @@ export type TooltipComponentType = { children: ReactElement; title: string | ReactElement; placement?: - | "bottom-end" - | "bottom-start" - | "bottom" - | "left-end" - | "left-start" - | "left" - | "right-end" - | "right-start" - | "right" - | "top-end" - | "top-start" - | "top"; + | "bottom-end" + | "bottom-start" + | "bottom" + | "left-end" + | "left-start" + | "left" + | "right-end" + | "right-start" + | "right" + | "top-end" + | "top-start" + | "top"; }; export type ProgressBarType = { diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 250ce4054..07f289132 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -298,23 +298,9 @@ export function convertObjToArray(singleObject) { arrConverted.push(newObj); } } - return arrConverted; } -export function convertArrayToObj(newValue) { - const flattenedObject = {}; - for (const obj of newValue) { - for (const key in obj) { - if (obj.hasOwnProperty(key)) { - flattenedObject[key] = obj[key]; //added space to dont order when add new keys to object - } - } - } - let newData = _.cloneDeep(flattenedObject); - return newData; -} - export function hasDuplicateKeys(array) { const keys = {}; for (const obj of array) { From 55001b98c873940d702ee5a3f44e6634083fe5a2 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Fri, 15 Sep 2023 15:49:47 -0300 Subject: [PATCH 29/56] =?UTF-8?q?=F0=9F=94=A5=20refactor(parameterComponen?= =?UTF-8?q?t):=20remove=20console.log=20statement=20for=20newValue=20in=20?= =?UTF-8?q?ParameterComponent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericNode/components/parameterComponent/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 3bb92d34e..548c90180 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -393,8 +393,6 @@ export default function ParameterComponent({ setDictArr(newValue); } else { setDictArr(newValue); - console.log(newValue); - data.node!.template[name].value = newValue; } }} From 4a03e81314842d08b0d54fdb1b57ae1da5d0ad4e Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Fri, 15 Sep 2023 16:07:08 -0300 Subject: [PATCH 30/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20remove=20redundant=20conditional=20statement=20and=20set=20d?= =?UTF-8?q?ictionary=20array=20and=20node=20template=20value=20directly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The conditional statement checking for duplicate keys and setting the dictionary array was redundant. Instead, the dictionary array is now always set to the new value. Additionally, the node template value is now always updated with the new value. --- .../GenericNode/components/parameterComponent/index.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 548c90180..19916002a 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -389,12 +389,8 @@ export default function ParameterComponent({ duplicateKey={errorDuplicateKey} onChange={(newValue) => { setErrorDuplicateKey(hasDuplicateKeys(newValue)); - if (hasDuplicateKeys(newValue)) { - setDictArr(newValue); - } else { - setDictArr(newValue); - data.node!.template[name].value = newValue; - } + setDictArr(newValue); + data.node!.template[name].value = newValue; }} />
From ddda46f6d6bb0241658f630a154f025451e29b1d Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Sun, 17 Sep 2023 10:31:42 -0300 Subject: [PATCH 31/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20convert=20object=20to=20array=20in=20data.node!.template[nam?= =?UTF-8?q?e].value=20to=20fix=20rendering=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericNode/components/parameterComponent/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 19916002a..c8cb0194b 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -27,6 +27,7 @@ import { typesContext } from "../../../../contexts/typesContext"; import { ParameterComponentType } from "../../../../types/components"; import { TabsState } from "../../../../types/tabs"; import { + convertObjToArray, hasDuplicateKeys, isValidConnection, } from "../../../../utils/reactflowUtils"; @@ -384,7 +385,7 @@ export default function ParameterComponent({ data.node!.template[name].value?.length === 0 || !data.node!.template[name].value ? dictArr - : data.node!.template[name].value + : convertObjToArray(data.node!.template[name].value) } duplicateKey={errorDuplicateKey} onChange={(newValue) => { From 46601245e1d5947a7155566903a79bd57cc7e27b Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Sun, 17 Sep 2023 11:09:15 -0300 Subject: [PATCH 32/56] =?UTF-8?q?=F0=9F=90=9B=20fix(EditNodeModal/index.ts?= =?UTF-8?q?x):=20import=20convertObjToArray=20function=20from=20reactflowU?= =?UTF-8?q?tils=20to=20fix=20undefined=20reference=20error=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(EditNodeModal/index.tsx):=20fix=20incorrect=20usage=20of?= =?UTF-8?q?=20convertObjToArray=20function=20to=20correctly=20convert=20ob?= =?UTF-8?q?ject=20to=20array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/EditNodeModal/index.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx index 390904ef4..bee154905 100644 --- a/src/frontend/src/modals/EditNodeModal/index.tsx +++ b/src/frontend/src/modals/EditNodeModal/index.tsx @@ -28,7 +28,10 @@ import { TabsContext } from "../../contexts/tabsContext"; import { typesContext } from "../../contexts/typesContext"; import { NodeDataType } from "../../types/flow"; import { TabsState } from "../../types/tabs"; -import { hasDuplicateKeys } from "../../utils/reactflowUtils"; +import { + convertObjToArray, + hasDuplicateKeys, +} from "../../utils/reactflowUtils"; import { classNames } from "../../utils/utils"; import BaseModal from "../baseModal"; @@ -212,9 +215,11 @@ const EditNodeModal = forwardRef( !myData.node.template[templateParam] .value ? dictArr - : myData.node.template[ - templateParam - ].value + : convertObjToArray( + myData.node.template[ + templateParam + ].value + ) } duplicateKey={errorDuplicateKey} onChange={(newValue) => { From 4b61a582ba07b958a23d776f645496f877dcd98e Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Mon, 18 Sep 2023 11:25:18 -0300 Subject: [PATCH 33/56] =?UTF-8?q?=F0=9F=94=A7=20fix(constants.ts):=20fix?= =?UTF-8?q?=20indentation=20issue=20in=20CODE=5FDICT=5FDIALOG=5FSUBTITLE?= =?UTF-8?q?=20constant=20=F0=9F=94=A7=20fix(constants.ts):=20update=20CODE?= =?UTF-8?q?=5FDICT=5FDIALOG=5FSUBTITLE=20constant=20to=20include=20informa?= =?UTF-8?q?tion=20about=20using=20eval()=20function=20=F0=9F=94=A7=20fix(r?= =?UTF-8?q?eactflowUtils.ts):=20add=20check=20to=20convertObjToArray=20fun?= =?UTF-8?q?ction=20to=20return=20the=20input=20if=20it=20is=20already=20an?= =?UTF-8?q?=20array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/constants/constants.ts | 4 ++-- src/frontend/src/utils/reactflowUtils.ts | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/constants/constants.ts b/src/frontend/src/constants/constants.ts index ab87f1e01..2e48b5b32 100644 --- a/src/frontend/src/constants/constants.ts +++ b/src/frontend/src/constants/constants.ts @@ -115,9 +115,9 @@ export const EDIT_DIALOG_SUBTITLE = export const CODE_PROMPT_DIALOG_SUBTITLE = "Edit your Python code. This code snippet accepts module import and a single function definition. Make sure that your function returns a string."; - + export const CODE_DICT_DIALOG_SUBTITLE = -"Edit your dictionary. This dialog allows you to create your own customized dictionary. You can add as many key-value pairs as you want."; + "Edit your dictionary. This dialog allows you to create your own customized dictionary. You can add as many key-value pairs as you want. The editor uses eval(). While in edit mode, you can enter ({}) or ([]), which will cause the result of eval to become a new object or array."; /** * The base text for subtitle of Prompt Dialog diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index aebf36eab..da503befc 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -292,6 +292,9 @@ export function getConnectedNodes( } export function convertObjToArray(singleObject) { + + if (Array.isArray(singleObject)) return singleObject; + let arrConverted: any = []; for (const key in singleObject) { if (singleObject.hasOwnProperty(key)) { From bdd79fc6f61a76234068edac05631eba0b19431f Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Mon, 18 Sep 2023 11:36:14 -0300 Subject: [PATCH 34/56] =?UTF-8?q?=F0=9F=93=9D=20chore(constants.ts):=20upd?= =?UTF-8?q?ate=20CODE=5FDICT=5FDIALOG=5FSUBTITLE=20to=20improve=20clarity?= =?UTF-8?q?=20and=20remove=20unnecessary=20information?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/constants/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/src/constants/constants.ts b/src/frontend/src/constants/constants.ts index 2e48b5b32..cd0eaac06 100644 --- a/src/frontend/src/constants/constants.ts +++ b/src/frontend/src/constants/constants.ts @@ -117,7 +117,7 @@ export const CODE_PROMPT_DIALOG_SUBTITLE = export const CODE_DICT_DIALOG_SUBTITLE = - "Edit your dictionary. This dialog allows you to create your own customized dictionary. You can add as many key-value pairs as you want. The editor uses eval(). While in edit mode, you can enter ({}) or ([]), which will cause the result of eval to become a new object or array."; + "Edit your dictionary. This dialog allows you to create your own customized dictionary. You can add as many key-value pairs as you want. While in edit mode, you can enter ({}) or ([]), and this will result in adding a new object or array."; /** * The base text for subtitle of Prompt Dialog From d39685e9f5ebc696a05ebaf34a1d1f8cae4f23af Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Mon, 18 Sep 2023 13:51:42 -0300 Subject: [PATCH 35/56] =?UTF-8?q?=F0=9F=94=A7=20chore(codeAreaModal):=20ad?= =?UTF-8?q?d=20additional=20class=20names=20to=20CodeArea=20component=20fo?= =?UTF-8?q?r=20better=20control=20and=20customization=20=F0=9F=8E=A8=20sty?= =?UTF-8?q?le(codeAreaModal):=20add=20class=20names=20'nopan',=20'nodrag',?= =?UTF-8?q?=20'noundo',=20and=20'nocopy'=20to=20CodeArea=20component=20to?= =?UTF-8?q?=20disable=20specific=20behaviors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/codeAreaModal/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/src/modals/codeAreaModal/index.tsx b/src/frontend/src/modals/codeAreaModal/index.tsx index 835e493cb..6fb06fe39 100644 --- a/src/frontend/src/modals/codeAreaModal/index.tsx +++ b/src/frontend/src/modals/codeAreaModal/index.tsx @@ -159,7 +159,7 @@ export default function CodeAreaModal({ onChange={(value) => { setCode(value); }} - className="h-full w-full rounded-lg border-[1px] border-gray-300 custom-scroll dark:border-gray-600" + className="nopan nodrag noundo nocopy h-full w-full rounded-lg border-[1px] border-gray-300 custom-scroll dark:border-gray-600" />
Date: Mon, 18 Sep 2023 14:23:20 -0300 Subject: [PATCH 36/56] =?UTF-8?q?=F0=9F=90=9B=20fix(dialog.tsx):=20remove?= =?UTF-8?q?=20unnecessary=20CSS=20classes=20'noundo'=20and=20'nocopy'=20fr?= =?UTF-8?q?om=20DialogOverlay=20component=20to=20improve=20code=20readabil?= =?UTF-8?q?ity=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 fix(index.tsx): remove unnecessary CSS classes 'nopan', 'nodrag', 'noundo', and 'nocopy' from CodeMirror component to improve code readability and maintainability --- src/frontend/src/components/ui/dialog.tsx | 2 +- src/frontend/src/modals/codeAreaModal/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/components/ui/dialog.tsx b/src/frontend/src/components/ui/dialog.tsx index fae079856..a6d3d58e9 100644 --- a/src/frontend/src/components/ui/dialog.tsx +++ b/src/frontend/src/components/ui/dialog.tsx @@ -27,7 +27,7 @@ const DialogOverlay = React.forwardRef< { setCode(value); }} - className="nopan nodrag noundo nocopy h-full w-full rounded-lg border-[1px] border-gray-300 custom-scroll dark:border-gray-600" + className="h-full w-full rounded-lg border-[1px] border-gray-300 custom-scroll dark:border-gray-600" />
Date: Mon, 18 Sep 2023 18:43:07 -0300 Subject: [PATCH 37/56] =?UTF-8?q?=F0=9F=94=A7=20chore(UpdateRequest.py):?= =?UTF-8?q?=20change=20field=5Ftype=20from=20"code"=20to=20"NestedDict"=20?= =?UTF-8?q?to=20improve=20clarity=20and=20semantics=20=F0=9F=94=A7=20chore?= =?UTF-8?q?(base.py):=20handle=20"dict"=20and=20"NestedDict"=20types=20in?= =?UTF-8?q?=20params=20parsing=20to=20ensure=20correct=20conversion=20from?= =?UTF-8?q?=20frontend=20data=20=F0=9F=94=A7=20chore(llms.py):=20change=20?= =?UTF-8?q?field=5Ftype=20from=20"code"=20to=20"dict"=20for=20model=5Fkwar?= =?UTF-8?q?gs=20field=20to=20improve=20semantics=20=F0=9F=94=A7=20chore(ut?= =?UTF-8?q?ilities.py):=20remove=20field=5Ftype=20"code"=20for=20fields=20?= =?UTF-8?q?with=20dict=20values=20to=20improve=20consistency=20?= =?UTF-8?q?=F0=9F=94=A7=20chore(constants.py):=20add=20"dict"=20and=20"Nes?= =?UTF-8?q?tedDict"=20to=20DIRECT=5FTYPES=20list=20to=20reflect=20availabl?= =?UTF-8?q?e=20field=20types=20=F0=9F=94=A7=20chore(util.py):=20remove=20r?= =?UTF-8?q?eplace=5Fdict=5Ftype=5Fwith=5Fcode=20function=20as=20it=20is=20?= =?UTF-8?q?no=20longer=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/components/utilities/UpdateRequest.py | 2 +- src/backend/langflow/graph/vertex/base.py | 12 ++++++++++++ src/backend/langflow/template/frontend_node/llms.py | 2 +- .../langflow/template/frontend_node/utilities.py | 1 - src/backend/langflow/utils/constants.py | 12 +++++++++++- src/backend/langflow/utils/util.py | 2 -- 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/backend/langflow/components/utilities/UpdateRequest.py b/src/backend/langflow/components/utilities/UpdateRequest.py index 6e8991794..d18c94a56 100644 --- a/src/backend/langflow/components/utilities/UpdateRequest.py +++ b/src/backend/langflow/components/utilities/UpdateRequest.py @@ -15,7 +15,7 @@ class UpdateRequest(CustomComponent): "url": {"display_name": "URL", "info": "The URL to make the request to."}, "headers": { "display_name": "Headers", - "field_type": "code", + "field_type": "NestedDict", "info": "The headers to send with the request.", }, "code": {"show": False}, diff --git a/src/backend/langflow/graph/vertex/base.py b/src/backend/langflow/graph/vertex/base.py index 0f9a5e8a9..715babf25 100644 --- a/src/backend/langflow/graph/vertex/base.py +++ b/src/backend/langflow/graph/vertex/base.py @@ -122,6 +122,18 @@ class Vertex: except Exception as exc: logger.debug(f"Error parsing code: {exc}") params[key] = value.get("value") + elif value.get("type") in ["dict", "NestedDict"]: + # When dict comes from the frontend it comes as a + # list of dicts, so we need to convert it to a dict + # before passing it to the build method + _value = value.get("value") + if isinstance(_value, list): + params[key] = { + item["key"]: item["value"] + for item in value.get("value", []) + } + elif isinstance(_value, dict): + params[key] = _value else: params[key] = value.get("value") diff --git a/src/backend/langflow/template/frontend_node/llms.py b/src/backend/langflow/template/frontend_node/llms.py index 01098724e..b8e007a27 100644 --- a/src/backend/langflow/template/frontend_node/llms.py +++ b/src/backend/langflow/template/frontend_node/llms.py @@ -131,7 +131,7 @@ class LLMFrontendNode(FrontendNode): if display_name := display_names_dict.get(field.name): field.display_name = display_name if field.name == "model_kwargs": - field.field_type = "code" + field.field_type = "dict" field.advanced = True field.show = True elif field.name in [ diff --git a/src/backend/langflow/template/frontend_node/utilities.py b/src/backend/langflow/template/frontend_node/utilities.py index 9dedacd0f..a5adb219d 100644 --- a/src/backend/langflow/template/frontend_node/utilities.py +++ b/src/backend/langflow/template/frontend_node/utilities.py @@ -21,5 +21,4 @@ class UtilitiesFrontendNode(FrontendNode): field.field_type = "str" if isinstance(field.value, dict): - field.field_type = "code" field.value = orjson_dumps(field.value) diff --git a/src/backend/langflow/utils/constants.py b/src/backend/langflow/utils/constants.py index e473d855b..43f92f651 100644 --- a/src/backend/langflow/utils/constants.py +++ b/src/backend/langflow/utils/constants.py @@ -48,4 +48,14 @@ def python_function(text: str) -> str: return text """ -DIRECT_TYPES = ["str", "bool", "code", "int", "float", "Any", "prompt"] +DIRECT_TYPES = [ + "str", + "bool", + "dict", + "int", + "float", + "Any", + "prompt", + "code", + "NestedDict", +] diff --git a/src/backend/langflow/utils/util.py b/src/backend/langflow/utils/util.py index 921f913c6..519ee79ca 100644 --- a/src/backend/langflow/utils/util.py +++ b/src/backend/langflow/utils/util.py @@ -276,8 +276,6 @@ def format_dict( value["password"] = is_password_field(key) value["multiline"] = is_multiline_field(key) - replace_dict_type_with_code(value) - if key == "dict_": set_dict_file_attributes(value) From 71dd9821ea671b8e0e6bedb6b4a42f2133d70463 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Mon, 18 Sep 2023 20:47:04 -0300 Subject: [PATCH 38/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20handleOnNewValue=20now=20accepts=20Object[]=20as=20a=20valid?= =?UTF-8?q?=20parameter=20type=20to=20support=20dict=20and=20NestedDict=20?= =?UTF-8?q?types=20=F0=9F=90=9B=20fix(parameterComponent):=20remove=20unus?= =?UTF-8?q?ed=20state=20variables=20obj=20and=20dictArr=20=E2=9C=A8=20feat?= =?UTF-8?q?(parameterComponent):=20add=20support=20for=20dict=20and=20Nest?= =?UTF-8?q?edDict=20types=20in=20ParameterComponent=20=F0=9F=90=9B=20fix(d?= =?UTF-8?q?ictComponent):=20call=20onChange=20when=20value=20prop=20change?= =?UTF-8?q?s=20to=20ensure=20proper=20synchronization=20=F0=9F=90=9B=20fix?= =?UTF-8?q?(keypairListComponent):=20call=20onChange=20when=20value=20prop?= =?UTF-8?q?=20changes=20to=20ensure=20proper=20synchronization=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(dialog.tsx):=20add=20missing=20classes=20to?= =?UTF-8?q?=20prevent=20panning,=20dragging,=20undoing,=20and=20copying=20?= =?UTF-8?q?in=20DialogPortal=20and=20DialogOverlay=20components?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/parameterComponent/index.tsx | 43 ++++++++++--------- .../src/components/dictComponent/index.tsx | 4 ++ .../components/keypairListComponent/index.tsx | 4 ++ src/frontend/src/components/ui/dialog.tsx | 4 +- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 82a667c5a..c61cadc2b 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -80,7 +80,9 @@ export default function ParameterComponent({ const { data: myData } = useContext(typesContext); - const handleOnNewValue = (newValue: string | string[] | boolean): void => { + const handleOnNewValue = ( + newValue: string | string[] | boolean | Object[] + ): void => { let newData = cloneDeep(data); newData.node!.template[name].value = newValue; setData(newData); @@ -99,22 +101,7 @@ export default function ParameterComponent({ renderTooltips(); }; - const [obj, setObj] = useState({ - arr: ["test", 123456, false, null], - boolean: false, - number: 123456, - try: { - k1: 123, - k2: "123", - k3: false, - }, - string: "string", - }); - const [errorDuplicateKey, setErrorDuplicateKey] = useState(false); - const [dictArr, setDictArr] = useState([ - { yourKey: "yourValue" }, - ] as Object[]); useEffect(() => { if (name === "openai_api_base") console.log(info); @@ -237,6 +224,8 @@ export default function ParameterComponent({ type === "code" || type === "prompt" || type === "file" || + type === "dict" || + type === "NestedDict" || type === "int") && !optionalHandle ? ( <> @@ -378,10 +367,22 @@ export default function ParameterComponent({ { - setObj(newValue); data.node!.template[name].value = newValue; + handleOnNewValue(newValue); }} />
@@ -393,14 +394,14 @@ export default function ParameterComponent({ value={ data.node!.template[name].value?.length === 0 || !data.node!.template[name].value - ? dictArr + ? [{ yourKey: "yourValue" }] : convertObjToArray(data.node!.template[name].value) } duplicateKey={errorDuplicateKey} onChange={(newValue) => { - setErrorDuplicateKey(hasDuplicateKeys(newValue)); - setDictArr(newValue); data.node!.template[name].value = newValue; + setErrorDuplicateKey(hasDuplicateKeys(newValue)); + handleOnNewValue(newValue); }} />
diff --git a/src/frontend/src/components/dictComponent/index.tsx b/src/frontend/src/components/dictComponent/index.tsx index fd55430bb..981372506 100644 --- a/src/frontend/src/components/dictComponent/index.tsx +++ b/src/frontend/src/components/dictComponent/index.tsx @@ -17,6 +17,10 @@ export default function DictComponent({ } }, [disabled]); + useEffect(() => { + if (value) onChange(value); + }, [value]); + return (
{ + if (value) onChange(value); + }, [value]); + return (
( -
+
{children}
@@ -27,7 +27,7 @@ const DialogOverlay = React.forwardRef< Date: Mon, 18 Sep 2023 21:16:10 -0300 Subject: [PATCH 39/56] =?UTF-8?q?=F0=9F=94=A7=20fix(dictAreaModal/index.ts?= =?UTF-8?q?x):=20add=20useEffect=20hook=20to=20update=20dictObj=20state=20?= =?UTF-8?q?when=20value=20prop=20changes=20=F0=9F=94=A7=20fix(dictAreaModa?= =?UTF-8?q?l/index.tsx):=20initialize=20dictObj=20state=20with=20value=20p?= =?UTF-8?q?rop=20on=20component=20mount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/dictAreaModal/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/modals/dictAreaModal/index.tsx b/src/frontend/src/modals/dictAreaModal/index.tsx index 85e7d293d..fdf0f5bb1 100644 --- a/src/frontend/src/modals/dictAreaModal/index.tsx +++ b/src/frontend/src/modals/dictAreaModal/index.tsx @@ -4,7 +4,7 @@ import "ace-builds/src-noconflict/mode-python"; import "ace-builds/src-noconflict/theme-github"; import "ace-builds/src-noconflict/theme-twilight"; // import "ace-builds/webpack-resolver"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import JsonView from "react18-json-view"; import "react18-json-view/src/dark.css"; import "react18-json-view/src/style.css"; @@ -21,6 +21,10 @@ export default function DictAreaModal({ const [open, setOpen] = useState(false); const [dictObj, setDictObj] = useState(value); + useEffect(() => { + if (value) setDictObj(value); + }, [value]); + return ( {children} From b30f9ddf7f2017c008ee0f9ada13f5aa915ac506 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Mon, 18 Sep 2023 21:51:22 -0300 Subject: [PATCH 40/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20convert=20parameter=20values=20to=20numbers=20before=20assig?= =?UTF-8?q?ning=20them=20to=20improve=20data=20consistency=20=F0=9F=94=A7?= =?UTF-8?q?=20chore(reactflowUtils):=20add=20utility=20function=20to=20con?= =?UTF-8?q?vert=20values=20to=20numbers=20in=20an=20array=20of=20objects?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/parameterComponent/index.tsx | 8 +++++--- src/frontend/src/utils/reactflowUtils.ts | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index c61cadc2b..a9e279e21 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -28,6 +28,7 @@ import { ParameterComponentType } from "../../../../types/components"; import { TabsState } from "../../../../types/tabs"; import { convertObjToArray, + convertValuesToNumbers, hasDuplicateKeys, isValidConnection, } from "../../../../utils/reactflowUtils"; @@ -399,9 +400,10 @@ export default function ParameterComponent({ } duplicateKey={errorDuplicateKey} onChange={(newValue) => { - data.node!.template[name].value = newValue; - setErrorDuplicateKey(hasDuplicateKeys(newValue)); - handleOnNewValue(newValue); + const valueToNumbers = convertValuesToNumbers(newValue); + data.node!.template[name].value = valueToNumbers; + setErrorDuplicateKey(hasDuplicateKeys(valueToNumbers)); + handleOnNewValue(valueToNumbers); }} />
diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index da503befc..0e0e07155 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -317,4 +317,21 @@ export function hasDuplicateKeys(array) { } } return false; -} \ No newline at end of file +} + +export function convertValuesToNumbers(arr) { + return arr.map((obj) => { + const newObj = {}; + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + let value = obj[key]; + if (/\s/g.test(value)) { + value = value.trim(); + } + newObj[key] = value === "" || isNaN(value) ? value.toString() : Number(value); + } + } + return newObj; + }); +} + From 52a8e6eeb591cb8a703978e5868928aaf83fedc3 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Mon, 18 Sep 2023 22:27:08 -0300 Subject: [PATCH 41/56] =?UTF-8?q?=F0=9F=90=9B=20fix(reactflowUtils.ts):=20?= =?UTF-8?q?fix=20validation=20logic=20for=20nested=20dictionaries=20in=20v?= =?UTF-8?q?alidateNode=20function=20=E2=9C=A8=20feat(reactflowUtils.ts):?= =?UTF-8?q?=20add=20hasEmptyKey=20function=20to=20check=20for=20empty=20ke?= =?UTF-8?q?ys=20in=20dictionaries=20in=20validateNode=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/utils/reactflowUtils.ts | 64 +++++++++++++++--------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 0e0e07155..5e4ac5f49 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -204,29 +204,36 @@ export function validateNode( node: { template }, } = node.data; - return Object.keys(template).reduce( - (errors: Array, t) => - errors.concat( - template[t].required && - template[t].show && - (template[t].value === undefined || - template[t].value === null || - template[t].value === "") && - !reactFlowInstance - .getEdges() - .some( - (edge) => - edge.targetHandle?.split("|")[1] === t && - edge.targetHandle.split("|")[2] === node.id - ) - ? [ - `${type} is missing ${template.display_name || toNormalCase(template[t].name) - }.`, - ] - : [] - ), - [] as string[] - ); + return Object.keys(template).reduce((errors: Array, t) => { + if ( + template[t].required && + template[t].show && + (template[t].value === undefined || + template[t].value === null || + template[t].value === "") && + !reactFlowInstance + .getEdges() + .some( + (edge) => + edge.targetHandle?.split("|")[1] === t && + edge.targetHandle.split("|")[2] === node.id + ) + ) { + errors.push(`${type} is missing ${template.display_name || toNormalCase(template[t].name)}.`); + } else if ( + (template[t].type === "dict" || template[t].type === "NestedDict") && + template[t].required && + template[t].show && + (template[t].value !== undefined || + template[t].value !== null || + template[t].value !== "") + ) { + if (hasDuplicateKeys(template[t].value)) errors.push(`${type} (${template.display_name || template[t].name}) contains duplicate keys with the same values.`); + if (hasEmptyKey(template[t].value)) errors.push(`${type} (${template.display_name || template[t].name}) contains keys with empty values.`); + } + return errors; + }, [] as string[]); + } export function validateNodes(reactFlowInstance: ReactFlowInstance) { @@ -319,6 +326,17 @@ export function hasDuplicateKeys(array) { return false; } +export function hasEmptyKey(objArray) { + for (const obj of objArray) { + for (const key in obj) { + if (obj.hasOwnProperty(key) && key === '') { + return true; // Found an empty key + } + } + } + return false; // No empty keys found +} + export function convertValuesToNumbers(arr) { return arr.map((obj) => { const newObj = {}; From a6c80a8780f4e10ec19fc279d64fe5353161ea02 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Mon, 18 Sep 2023 22:32:11 -0300 Subject: [PATCH 42/56] =?UTF-8?q?=F0=9F=90=9B=20fix(reactflowUtils.ts):=20?= =?UTF-8?q?improve=20error=20message=20for=20empty=20key=20in=20validateNo?= =?UTF-8?q?de=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/utils/reactflowUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 5e4ac5f49..9ed4736c0 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -229,7 +229,7 @@ export function validateNode( template[t].value !== "") ) { if (hasDuplicateKeys(template[t].value)) errors.push(`${type} (${template.display_name || template[t].name}) contains duplicate keys with the same values.`); - if (hasEmptyKey(template[t].value)) errors.push(`${type} (${template.display_name || template[t].name}) contains keys with empty values.`); + if (hasEmptyKey(template[t].value)) errors.push(`${type} (${template.display_name || template[t].name}) field must not be empty.`); } return errors; }, [] as string[]); From 83271fa0e8b4019f0d591ecb89ecffbc4d4c0eb6 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Mon, 18 Sep 2023 22:59:40 -0300 Subject: [PATCH 43/56] =?UTF-8?q?=F0=9F=90=9B=20fix(reactflowUtils.ts):=20?= =?UTF-8?q?remove=20unnecessary=20condition=20for=20template[t].type=20to?= =?UTF-8?q?=20improve=20code=20readability=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/utils/reactflowUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 9ed4736c0..108871bb1 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -221,7 +221,7 @@ export function validateNode( ) { errors.push(`${type} is missing ${template.display_name || toNormalCase(template[t].name)}.`); } else if ( - (template[t].type === "dict" || template[t].type === "NestedDict") && + (template[t].type === "dict") && template[t].required && template[t].show && (template[t].value !== undefined || From 5a70aa04dd0b766186c75acb569c05858c04e315 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 19 Sep 2023 11:28:01 -0300 Subject: [PATCH 44/56] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20fix=20the?= =?UTF-8?q?=20assignment=20of=20params[key]=20in=20Vertex=20class=20to=20c?= =?UTF-8?q?orrectly=20handle=20nested=20dictionaries=20and=20lists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous implementation was not correctly handling nested dictionaries and lists. This fix updates the assignment of params[key] to correctly handle nested dictionaries and lists by using a dictionary comprehension. --- src/backend/langflow/graph/vertex/base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/graph/vertex/base.py b/src/backend/langflow/graph/vertex/base.py index 715babf25..ac05ac221 100644 --- a/src/backend/langflow/graph/vertex/base.py +++ b/src/backend/langflow/graph/vertex/base.py @@ -129,8 +129,9 @@ class Vertex: _value = value.get("value") if isinstance(_value, list): params[key] = { - item["key"]: item["value"] + k: v for item in value.get("value", []) + for k, v in item.items() } elif isinstance(_value, dict): params[key] = _value From 738bfa481263dba2549b1ef54c23a6c50c12419a Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 19 Sep 2023 14:07:13 -0300 Subject: [PATCH 45/56] =?UTF-8?q?=F0=9F=94=A8=20refactor(PromptRunner.py):?= =?UTF-8?q?=20remove=20unused=20inputs=20field=20from=20the=20component=20?= =?UTF-8?q?configuration=20=F0=9F=94=A8=20refactor(MetalRetriever.py):=20r?= =?UTF-8?q?emove=20field=5Ftype=20code=20from=20params=20field=20in=20the?= =?UTF-8?q?=20component=20configuration=20=F0=9F=94=A8=20refactor(GetReque?= =?UTF-8?q?st.py):=20remove=20field=5Ftype=20code=20from=20headers=20field?= =?UTF-8?q?=20in=20the=20component=20configuration=20=F0=9F=94=A8=20refact?= =?UTF-8?q?or(PostRequest.py):=20remove=20field=5Ftype=20code=20from=20hea?= =?UTF-8?q?ders=20field=20in=20the=20component=20configuration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/components/chains/PromptRunner.py | 7 ++----- .../langflow/components/retrievers/MetalRetriever.py | 2 +- src/backend/langflow/components/utilities/GetRequest.py | 1 - src/backend/langflow/components/utilities/PostRequest.py | 1 - 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/backend/langflow/components/chains/PromptRunner.py b/src/backend/langflow/components/chains/PromptRunner.py index 141941c38..db9283b07 100644 --- a/src/backend/langflow/components/chains/PromptRunner.py +++ b/src/backend/langflow/components/chains/PromptRunner.py @@ -16,17 +16,14 @@ class PromptRunner(CustomComponent): "info": "Make sure the prompt has all variables filled.", }, "code": {"show": False}, - "inputs": {"field_type": "code"}, } def build( - self, - llm: BaseLLM, - prompt: PromptTemplate, + self, llm: BaseLLM, prompt: PromptTemplate, inputs: dict = {} ) -> Document: chain = prompt | llm # The input is an empty dict because the prompt is already filled - result = chain.invoke({}) + result = chain.invoke(input=inputs) if hasattr(result, "content"): result = result.content self.repr_value = result diff --git a/src/backend/langflow/components/retrievers/MetalRetriever.py b/src/backend/langflow/components/retrievers/MetalRetriever.py index 9b2d1e5dd..b105cd24f 100644 --- a/src/backend/langflow/components/retrievers/MetalRetriever.py +++ b/src/backend/langflow/components/retrievers/MetalRetriever.py @@ -14,7 +14,7 @@ class MetalRetrieverComponent(CustomComponent): "api_key": {"display_name": "API Key", "password": True}, "client_id": {"display_name": "Client ID", "password": True}, "index_id": {"display_name": "Index ID"}, - "params": {"display_name": "Parameters", "field_type": "code"}, + "params": {"display_name": "Parameters"}, "code": {"show": False}, } diff --git a/src/backend/langflow/components/utilities/GetRequest.py b/src/backend/langflow/components/utilities/GetRequest.py index 13ff0dc23..d5df32cca 100644 --- a/src/backend/langflow/components/utilities/GetRequest.py +++ b/src/backend/langflow/components/utilities/GetRequest.py @@ -19,7 +19,6 @@ class GetRequest(CustomComponent): }, "headers": { "display_name": "Headers", - "field_type": "code", "info": "The headers to send with the request.", }, "code": {"show": False}, diff --git a/src/backend/langflow/components/utilities/PostRequest.py b/src/backend/langflow/components/utilities/PostRequest.py index 4f7100d43..6857f4866 100644 --- a/src/backend/langflow/components/utilities/PostRequest.py +++ b/src/backend/langflow/components/utilities/PostRequest.py @@ -15,7 +15,6 @@ class PostRequest(CustomComponent): "url": {"display_name": "URL", "info": "The URL to make the request to."}, "headers": { "display_name": "Headers", - "field_type": "code", "info": "The headers to send with the request.", }, "code": {"show": False}, From 01104e666c3b3aa102bb28ed929b527f2116cce3 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 19 Sep 2023 14:07:58 -0300 Subject: [PATCH 46/56] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20refactor?= =?UTF-8?q?=20handle=5Fdict=5Ftype=20method=20to=20improve=20readability?= =?UTF-8?q?=20and=20semantics=20=E2=9C=A8=20feat(base.py):=20add=20support?= =?UTF-8?q?=20for=20'dict'=20type=20fields=20to=20be=20handled=20as=20'dic?= =?UTF-8?q?t'=20instead=20of=20'code'=20or=20'file'=20=F0=9F=90=9B=20fix(d?= =?UTF-8?q?ocumentloaders.py):=20change=20field=5Ftype=20of=20metadata=20f?= =?UTF-8?q?ield=20to=20'dict'=20instead=20of=20'code'=20=F0=9F=90=9B=20fix?= =?UTF-8?q?(embeddings.py):=20change=20field=5Ftype=20of=20model=5Fkwargs?= =?UTF-8?q?=20field=20to=20'dict'=20instead=20of=20'code'=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(field=5Fformatters.py):=20refactor=20DictCodeFileFormatt?= =?UTF-8?q?er=20to=20handle=20'dict'=20type=20fields=20as=20'dict'=20inste?= =?UTF-8?q?ad=20of=20'code'=20or=20'file'=20=F0=9F=90=9B=20fix(prompts.py)?= =?UTF-8?q?:=20call=20parent=20format=5Ffield=20method=20in=20PromptFronte?= =?UTF-8?q?ndNode=20to=20ensure=20proper=20formatting=20=F0=9F=90=9B=20fix?= =?UTF-8?q?(vectorstores.py):=20change=20field=5Ftype=20of=20search=5Fkwar?= =?UTF-8?q?gs=20field=20to=20'NestedDict'=20instead=20of=20'code'=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(util.py):=20remove=20unused=20replace=5Fdict?= =?UTF-8?q?=5Ftype=5Fwith=5Fcode=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/template/frontend_node/base.py | 31 ++++++------------- .../template/frontend_node/documentloaders.py | 2 +- .../template/frontend_node/embeddings.py | 2 +- .../formatter/field_formatters.py | 17 +++++----- .../template/frontend_node/prompts.py | 1 + .../template/frontend_node/vectorstores.py | 2 +- src/backend/langflow/utils/util.py | 8 ----- 7 files changed, 24 insertions(+), 39 deletions(-) diff --git a/src/backend/langflow/template/frontend_node/base.py b/src/backend/langflow/template/frontend_node/base.py index fe19b5652..979054c9b 100644 --- a/src/backend/langflow/template/frontend_node/base.py +++ b/src/backend/langflow/template/frontend_node/base.py @@ -140,13 +140,16 @@ class FrontendNode(BaseModel): @staticmethod def handle_dict_type(field: TemplateField, _type: str) -> str: """Handles 'dict' type by replacing it with 'code' or 'file' based on the field name.""" - if "dict" in _type.lower(): - if field.name == "dict_": - field.field_type = "file" - field.suffixes = [".json", ".yaml", ".yml"] - field.file_types = ["json", "yaml", "yml"] - else: - field.field_type = "code" + if "dict" in _type.lower() and key == "dict_": + field.field_type = "file" + field.suffixes = [".json", ".yaml", ".yml"] + field.file_types = ["json", "yaml", "yml"] + elif ( + _type.startswith("Dict") + or _type.startswith("Mapping") + or _type.startswith("dict") + ): + field.field_type = "dict" return _type @staticmethod @@ -240,20 +243,6 @@ class FrontendNode(BaseModel): "description", } - @staticmethod - def replace_dict_with_code_or_file( - field: TemplateField, _type: str, key: str - ) -> str: - """Replaces 'dict' type with 'code' or 'file'.""" - if "dict" in _type.lower(): - if key == "dict_": - field.field_type = "file" - field.suffixes = [".json", ".yaml", ".yml"] - field.file_types = ["json", "yaml", "yml"] - else: - field.field_type = "code" - return field.field_type - @staticmethod def set_field_default_value(field: TemplateField, value: dict, key: str) -> None: """Sets the field value with the default value if present.""" diff --git a/src/backend/langflow/template/frontend_node/documentloaders.py b/src/backend/langflow/template/frontend_node/documentloaders.py index cdf67e54a..eed9dc473 100644 --- a/src/backend/langflow/template/frontend_node/documentloaders.py +++ b/src/backend/langflow/template/frontend_node/documentloaders.py @@ -170,7 +170,7 @@ class DocumentLoaderFrontNode(FrontendNode): # add a metadata field of type dict self.template.add_field( TemplateField( - field_type="code", + field_type="dict", required=True, show=True, name="metadata", diff --git a/src/backend/langflow/template/frontend_node/embeddings.py b/src/backend/langflow/template/frontend_node/embeddings.py index 4e7e25112..665328e78 100644 --- a/src/backend/langflow/template/frontend_node/embeddings.py +++ b/src/backend/langflow/template/frontend_node/embeddings.py @@ -89,7 +89,7 @@ class EmbeddingFrontendNode(FrontendNode): if field.name == "headers": field.show = False if field.name == "model_kwargs": - field.field_type = "code" + field.field_type = "dict" field.advanced = True field.show = True elif field.name in [ diff --git a/src/backend/langflow/template/frontend_node/formatter/field_formatters.py b/src/backend/langflow/template/frontend_node/formatter/field_formatters.py index 7987b134a..247f3b421 100644 --- a/src/backend/langflow/template/frontend_node/formatter/field_formatters.py +++ b/src/backend/langflow/template/frontend_node/formatter/field_formatters.py @@ -153,10 +153,13 @@ class DictCodeFileFormatter(FieldFormatter): key = field.name value = field.to_dict() _type = value["type"] - if "dict" in _type.lower(): - if key == "dict_": - field.field_type = "file" - field.suffixes = [".json", ".yaml", ".yml"] - field.file_types = ["json", "yaml", "yml"] - else: - field.field_type = "code" + if "dict" in _type.lower() and key == "dict_": + field.field_type = "file" + field.suffixes = [".json", ".yaml", ".yml"] + field.file_types = ["json", "yaml", "yml"] + elif ( + _type.startswith("Dict") + or _type.startswith("Mapping") + or _type.startswith("dict") + ): + field.field_type = "dict" diff --git a/src/backend/langflow/template/frontend_node/prompts.py b/src/backend/langflow/template/frontend_node/prompts.py index da5d2a300..c52b1901c 100644 --- a/src/backend/langflow/template/frontend_node/prompts.py +++ b/src/backend/langflow/template/frontend_node/prompts.py @@ -15,6 +15,7 @@ from langflow.template.template.base import Template class PromptFrontendNode(FrontendNode): @staticmethod def format_field(field: TemplateField, name: Optional[str] = None) -> None: + FrontendNode.format_field(field, name) # if field.field_type == "StringPromptTemplate" # change it to str PROMPT_FIELDS = [ diff --git a/src/backend/langflow/template/frontend_node/vectorstores.py b/src/backend/langflow/template/frontend_node/vectorstores.py index 23c293437..73e9aaaca 100644 --- a/src/backend/langflow/template/frontend_node/vectorstores.py +++ b/src/backend/langflow/template/frontend_node/vectorstores.py @@ -56,7 +56,7 @@ class VectorStoreFrontendNode(FrontendNode): # Add search_kwargs field extra_field = TemplateField( name="search_kwargs", - field_type="code", + field_type="NestedDict", required=False, placeholder="", show=True, diff --git a/src/backend/langflow/utils/util.py b/src/backend/langflow/utils/util.py index 519ee79ca..4fd9350d2 100644 --- a/src/backend/langflow/utils/util.py +++ b/src/backend/langflow/utils/util.py @@ -405,14 +405,6 @@ def is_multiline_field(key: str) -> bool: } -def replace_dict_type_with_code(value: Dict[str, Any]) -> None: - """ - Replaces the type value with 'code' if the type is a dict. - """ - if "dict" in value["type"].lower(): - value["type"] = "code" - - def set_dict_file_attributes(value: Dict[str, Any]) -> None: """ Sets the file attributes for the 'dict_' key. From 1243c0b644e7cacb9cfdf093912e02d926eed8b0 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 19 Sep 2023 14:08:12 -0300 Subject: [PATCH 47/56] =?UTF-8?q?=F0=9F=90=9B=20fix(test=5Fllms=5Ftemplate?= =?UTF-8?q?.py):=20remove=20unused=20test=5Fllms=5Fsettings=20function=20t?= =?UTF-8?q?o=20improve=20code=20readability=20and=20maintainability=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(test=5Ftemplate.py):=20update=20type=20annot?= =?UTF-8?q?ation=20in=20test=5Fformat=5Fdict=20function=20to=20reflect=20t?= =?UTF-8?q?he=20correct=20type=20of=20the=20field=20=F0=9F=90=9B=20fix(tes?= =?UTF-8?q?t=5Fprompts=5Ftemplate.py):=20update=20type=20annotation=20in?= =?UTF-8?q?=20test=5Fprompt=5Ftemplate=20function=20to=20reflect=20the=20c?= =?UTF-8?q?orrect=20type=20of=20the=20field?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_llms_template.py | 17 ++++------------- tests/test_prompts_template.py | 2 +- tests/test_template.py | 4 ++-- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/tests/test_llms_template.py b/tests/test_llms_template.py index 14e151479..3da176192 100644 --- a/tests/test_llms_template.py +++ b/tests/test_llms_template.py @@ -2,15 +2,6 @@ from fastapi.testclient import TestClient from langflow.services.utils import get_settings_manager -def test_llms_settings(client: TestClient, logged_in_headers): - settings_manager = get_settings_manager() - response = client.get("api/v1/all", headers=logged_in_headers) - assert response.status_code == 200 - json_response = response.json() - llms = json_response["llms"] - assert set(llms.keys()) == set(settings_manager.settings.LLMS) - - # def test_hugging_face_hub(client: TestClient): # response = client.get("api/v1/all") # assert response.status_code == 200 @@ -85,7 +76,7 @@ def test_llms_settings(client: TestClient, logged_in_headers): # "multiline": False, # "password": False, # "name": "model_kwargs", -# "type": "code", +# "type": "dict" , # "list": False, # "advanced": True, # } @@ -279,7 +270,7 @@ def test_openai(client: TestClient, logged_in_headers): "multiline": False, "password": False, "name": "model_kwargs", - "type": "code", + "type": "dict", "list": False, "advanced": True, "info": "", @@ -334,7 +325,7 @@ def test_openai(client: TestClient, logged_in_headers): "multiline": False, "password": False, "name": "logit_bias", - "type": "code", + "type": "dict", "list": False, "advanced": False, "info": "", @@ -451,7 +442,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers): "multiline": False, "password": False, "name": "model_kwargs", - "type": "code", + "type": "dict", "list": False, "advanced": True, "info": "", diff --git a/tests/test_prompts_template.py b/tests/test_prompts_template.py index 676448f73..434691038 100644 --- a/tests/test_prompts_template.py +++ b/tests/test_prompts_template.py @@ -55,7 +55,7 @@ def test_prompt_template(client: TestClient, logged_in_headers): "multiline": False, "password": False, "name": "partial_variables", - "type": "code", + "type": "dict", "list": False, "advanced": False, "info": "", diff --git a/tests/test_template.py b/tests/test_template.py index 4be6dff06..81f2a6020 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -135,7 +135,7 @@ def test_format_dict(): } expected_output = { "field1": { - "type": "code", # Mapping type is replaced with dict which is replaced with code + "type": "dict[str, int]", # Mapping type is replaced with dict which is replaced with code "required": False, "list": False, "show": False, @@ -249,7 +249,7 @@ def test_format_dict(): } expected_output = { "field1": { - "type": "code", + "type": "Dict[str, int]", "required": False, "list": False, "show": False, From 0389d8ec1e7514828859bf00831cc6d897cca963 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 19 Sep 2023 14:14:11 -0300 Subject: [PATCH 48/56] =?UTF-8?q?=F0=9F=90=9B=20fix(documentloaders.py):?= =?UTF-8?q?=20change=20value=20of=20metadata=20from=20string=20to=20empty?= =?UTF-8?q?=20object=20to=20fix=20incorrect=20type=20assignment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/template/frontend_node/documentloaders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/langflow/template/frontend_node/documentloaders.py b/src/backend/langflow/template/frontend_node/documentloaders.py index eed9dc473..8118593f3 100644 --- a/src/backend/langflow/template/frontend_node/documentloaders.py +++ b/src/backend/langflow/template/frontend_node/documentloaders.py @@ -174,7 +174,7 @@ class DocumentLoaderFrontNode(FrontendNode): required=True, show=True, name="metadata", - value="{}", + value={}, display_name="Metadata", multiline=False, ) From e528b1363e19b343b4199c7b96102a9a0d959480 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 19 Sep 2023 14:33:57 -0300 Subject: [PATCH 49/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20add=20condition=20to=20prevent=20setting=20state=20if=20tabI?= =?UTF-8?q?d=20does=20not=20exist=20in=20previous=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericNode/components/parameterComponent/index.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index a9e279e21..9cf84491d 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -90,6 +90,9 @@ export default function ParameterComponent({ // Set state to pending //@ts-ignore setTabsState((prev: TabsState) => { + if (!prev[tabId]) { + return prev; + } return { ...prev, [tabId]: { From fe92ce85f91b4c6e5ce30b1e661d982581b6c076 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Tue, 19 Sep 2023 14:42:49 -0300 Subject: [PATCH 50/56] =?UTF-8?q?=F0=9F=90=9B=20fix(parameterComponent):?= =?UTF-8?q?=20change=20default=20key-value=20pair=20in=20case=20of=20empty?= =?UTF-8?q?=20value=20to=20improve=20clarity=20=F0=9F=90=9B=20fix(keypairL?= =?UTF-8?q?istComponent):=20update=20placeholder=20text=20to=20improve=20u?= =?UTF-8?q?ser=20guidance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericNode/components/parameterComponent/index.tsx | 2 +- src/frontend/src/components/keypairListComponent/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 9cf84491d..15dd2bb3c 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -398,7 +398,7 @@ export default function ParameterComponent({ value={ data.node!.template[name].value?.length === 0 || !data.node!.template[name].value - ? [{ yourKey: "yourValue" }] + ? [{ "": "" }] : convertObjToArray(data.node!.template[name].value) } duplicateKey={errorDuplicateKey} diff --git a/src/frontend/src/components/keypairListComponent/index.tsx b/src/frontend/src/components/keypairListComponent/index.tsx index 416e2c7b5..e9c016ece 100644 --- a/src/frontend/src/components/keypairListComponent/index.tsx +++ b/src/frontend/src/components/keypairListComponent/index.tsx @@ -70,7 +70,7 @@ export default function KeypairListComponent({ type="text" value={obj[key]} className={editNode ? "input-edit-node" : ""} - placeholder="Click to input a value..." + placeholder="Type a value..." onChange={(event) => handleChangeValue(event.target.value, index) } From c9126fdb625fded561ef0cf40722e8b7f639c730 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Tue, 19 Sep 2023 14:51:01 -0300 Subject: [PATCH 51/56] =?UTF-8?q?=F0=9F=94=80=20refactor(parameterComponen?= =?UTF-8?q?t):=20remove=20unused=20properties=20from=20default=20parameter?= =?UTF-8?q?=20value=20object=20to=20improve=20code=20readability=20and=20m?= =?UTF-8?q?aintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenericNode/components/parameterComponent/index.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 15dd2bb3c..63b3b109f 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -374,14 +374,10 @@ export default function ParameterComponent({ value={ data.node!.template[name].value ?? { arr: ["test", 123456, false, null], - boolean: false, - number: 123456, try: { k1: 123, - k2: "123", - k3: false, }, - string: "string", + yourkey: "value", } } onChange={(newValue) => { From a9034b6937c3068c85851e0dcf2fa932561c7ee4 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 19 Sep 2023 15:01:40 -0300 Subject: [PATCH 52/56] =?UTF-8?q?=F0=9F=93=9D=20docs(custom.mdx):=20add=20?= =?UTF-8?q?explanation=20about=20the=20difference=20between=20dict=20and?= =?UTF-8?q?=20langflow.field=5Ftyping.NestedDict=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 📝 docs(custom.mdx): clarify that langflow.field_typing.NestedDict opens a more robust dictionary editor compared to dict type --- docs/docs/components/custom.mdx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/docs/components/custom.mdx b/docs/docs/components/custom.mdx index ffa747c1b..90282a73e 100644 --- a/docs/docs/components/custom.mdx +++ b/docs/docs/components/custom.mdx @@ -33,6 +33,7 @@ The CustomComponent class serves as the foundation for creating custom component | Supported Types | | --------------------------------------------------------- | | _`str`_, _`int`_, _`float`_, _`bool`_, _`list`_, _`dict`_ | + | _`langflow.field_typing.NestedDict`_ | | _`langchain.chains.base.Chain`_ | | _`langchain.PromptTemplate`_ | | _`langchain.llms.base.BaseLLM`_ | @@ -44,6 +45,8 @@ The CustomComponent class serves as the foundation for creating custom component | _`langchain.embeddings.base.Embeddings`_ | | _`langchain.schema.BaseRetriever`_ | + The difference between _`dict`_ and _`langflow.field_typing.NestedDict`_ is that one adds a simple key-value pair field, while the other opens a more robust dictionary editor. + Unlike Langchain types, base Python types do not add a [handle](../guidelines/components) to the field by default. To add handles, From 2f63d29ce417f7f02800065a0d7b1dcfc918e973 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Tue, 19 Sep 2023 15:03:12 -0300 Subject: [PATCH 53/56] =?UTF-8?q?=F0=9F=8E=A8=20style(App.css):=20add=20pa?= =?UTF-8?q?dding=20to=20the=20.jv-card=20class=20to=20improve=20spacing=20?= =?UTF-8?q?and=20readability=20=F0=9F=94=A5=20refactor(parameterComponent/?= =?UTF-8?q?index.tsx):=20remove=20unnecessary=20code=20block=20in=20the=20?= =?UTF-8?q?value=20prop=20to=20improve=20code=20clarity=20and=20maintainab?= =?UTF-8?q?ility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/App.css | 1 + .../GenericNode/components/parameterComponent/index.tsx | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/frontend/src/App.css b/src/frontend/src/App.css index d24c4127c..fc28a9c83 100644 --- a/src/frontend/src/App.css +++ b/src/frontend/src/App.css @@ -50,6 +50,7 @@ height: 370px !important; background-color: #2c2c2c !important; border-radius: 10px !important; + padding: 10px !important; } .jv-indent { diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index 63b3b109f..08eb261a6 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -373,10 +373,6 @@ export default function ParameterComponent({ editNode={false} value={ data.node!.template[name].value ?? { - arr: ["test", 123456, false, null], - try: { - k1: 123, - }, yourkey: "value", } } From ce35caa59f021880a08923a496c26ad4484f2ac4 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 19 Sep 2023 15:11:36 -0300 Subject: [PATCH 54/56] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20fix=20vari?= =?UTF-8?q?able=20name=20in=20if=20condition=20to=20correctly=20check=20fi?= =?UTF-8?q?eld=20name=20for=20'dict'=20type=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/template/frontend_node/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/langflow/template/frontend_node/base.py b/src/backend/langflow/template/frontend_node/base.py index 979054c9b..442e2ffd7 100644 --- a/src/backend/langflow/template/frontend_node/base.py +++ b/src/backend/langflow/template/frontend_node/base.py @@ -140,7 +140,7 @@ class FrontendNode(BaseModel): @staticmethod def handle_dict_type(field: TemplateField, _type: str) -> str: """Handles 'dict' type by replacing it with 'code' or 'file' based on the field name.""" - if "dict" in _type.lower() and key == "dict_": + if "dict" in _type.lower() and field.name == "dict_": field.field_type = "file" field.suffixes = [".json", ".yaml", ".yml"] field.file_types = ["json", "yaml", "yml"] From 1e5ef1c8c00bcbd57e9fea1d08274b7c5fb63d7f Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 19 Sep 2023 15:13:03 -0300 Subject: [PATCH 55/56] =?UTF-8?q?=F0=9F=94=A5=20refactor(test=5Fllms=5Ftem?= =?UTF-8?q?plate.py):=20remove=20commented=20out=20code=20and=20unused=20i?= =?UTF-8?q?mport=20to=20improve=20code=20readability=20and=20maintainabili?= =?UTF-8?q?ty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_llms_template.py | 93 ------------------------------------- 1 file changed, 93 deletions(-) diff --git a/tests/test_llms_template.py b/tests/test_llms_template.py index 3da176192..0a30a825e 100644 --- a/tests/test_llms_template.py +++ b/tests/test_llms_template.py @@ -1,97 +1,4 @@ from fastapi.testclient import TestClient -from langflow.services.utils import get_settings_manager - - -# def test_hugging_face_hub(client: TestClient): -# response = client.get("api/v1/all") -# assert response.status_code == 200 -# json_response = response.json() -# language_models = json_response["llms"] - -# model = language_models["HuggingFaceHub"] -# template = model["template"] - -# assert template["cache"] == { -# "required": False, -# "placeholder": "", -# "show": False, -# "multiline": False, -# "password": False, -# "name": "cache", -# "type": "bool", -# "list": False, -# "advanced": False, -# } -# assert template["verbose"] == { -# "required": False, -# "placeholder": "", -# "show": False, -# "multiline": False, -# "value": False, -# "password": False, -# "name": "verbose", -# "type": "bool", -# "list": False, -# "advanced": False, -# } -# assert template["client"] == { -# "required": False, -# "placeholder": "", -# "show": False, -# "multiline": False, -# "password": False, -# "name": "client", -# "type": "Any", -# "list": False, -# "advanced": False, -# } -# assert template["repo_id"] == { -# "required": False, -# "placeholder": "", -# "show": True, -# "multiline": False, -# "value": "gpt2", -# "password": False, -# "name": "repo_id", -# "type": "str", -# "list": False, -# "advanced": False, -# } -# assert template["task"] == { -# "required": True, -# "placeholder": "", -# "show": True, -# "multiline": False, -# "password": False, -# "options": ["text-generation", "text2text-generation"], -# "name": "task", -# "type": "str", -# "list": True, -# "advanced": True, -# } -# assert template["model_kwargs"] == { -# "required": False, -# "placeholder": "", -# "show": True, -# "multiline": False, -# "password": False, -# "name": "model_kwargs", -# "type": "dict" , -# "list": False, -# "advanced": True, -# } -# assert template["huggingfacehub_api_token"] == { -# "required": False, -# "placeholder": "", -# "show": True, -# "multiline": False, -# "password": True, -# "name": "huggingfacehub_api_token", -# "display_name": "HuggingFace Hub API Token", -# "type": "str", -# "list": False, -# "advanced": False, -# } def test_openai(client: TestClient, logged_in_headers): From 2b454dc645d3a49f119409c87265890c404ac25c Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 19 Sep 2023 15:27:12 -0300 Subject: [PATCH 56/56] Formatting --- src/backend/langflow/interface/run.py | 5 ++-- src/frontend/src/constants/constants.ts | 1 - src/frontend/src/types/components/index.ts | 24 ++++++++--------- src/frontend/src/utils/reactflowUtils.ts | 30 +++++++++++++++------- src/frontend/src/utils/styleUtils.ts | 4 +-- 5 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/backend/langflow/interface/run.py b/src/backend/langflow/interface/run.py index 1aff2f0e2..eb012e182 100644 --- a/src/backend/langflow/interface/run.py +++ b/src/backend/langflow/interface/run.py @@ -59,7 +59,7 @@ def get_memory_key(langchain_object): "history": "chat_history", } # Check if memory_key attribute exists - if hasattr(langchain_object.memory, 'memory_key'): + if hasattr(langchain_object.memory, "memory_key"): memory_key = langchain_object.memory.memory_key return mem_key_dict.get(memory_key) else: @@ -90,5 +90,4 @@ def update_memory_keys(langchain_object, possible_new_mem_key): try: setattr(langchain_object.memory, attr, key) except ValueError as exc: - logger.debug( - f"{langchain_object.memory} has no attribute {attr} ({exc})") + logger.debug(f"{langchain_object.memory} has no attribute {attr} ({exc})") diff --git a/src/frontend/src/constants/constants.ts b/src/frontend/src/constants/constants.ts index cd0eaac06..d6ba802ee 100644 --- a/src/frontend/src/constants/constants.ts +++ b/src/frontend/src/constants/constants.ts @@ -115,7 +115,6 @@ export const EDIT_DIALOG_SUBTITLE = export const CODE_PROMPT_DIALOG_SUBTITLE = "Edit your Python code. This code snippet accepts module import and a single function definition. Make sure that your function returns a string."; - export const CODE_DICT_DIALOG_SUBTITLE = "Edit your dictionary. This dialog allows you to create your own customized dictionary. You can add as many key-value pairs as you want. While in edit mode, you can enter ({}) or ([]), and this will result in adding a new object or array."; diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index e4339a041..1d0825f7f 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -123,18 +123,18 @@ export type TooltipComponentType = { children: ReactElement; title: string | ReactElement; placement?: - | "bottom-end" - | "bottom-start" - | "bottom" - | "left-end" - | "left-start" - | "left" - | "right-end" - | "right-start" - | "right" - | "top-end" - | "top-start" - | "top"; + | "bottom-end" + | "bottom-start" + | "bottom" + | "left-end" + | "left-start" + | "left" + | "right-end" + | "right-start" + | "right" + | "top-end" + | "top-start" + | "top"; }; export type ProgressBarType = { diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 108871bb1..df8c784c4 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -219,21 +219,34 @@ export function validateNode( edge.targetHandle.split("|")[2] === node.id ) ) { - errors.push(`${type} is missing ${template.display_name || toNormalCase(template[t].name)}.`); + errors.push( + `${type} is missing ${ + template.display_name || toNormalCase(template[t].name) + }.` + ); } else if ( - (template[t].type === "dict") && + template[t].type === "dict" && template[t].required && template[t].show && (template[t].value !== undefined || template[t].value !== null || template[t].value !== "") ) { - if (hasDuplicateKeys(template[t].value)) errors.push(`${type} (${template.display_name || template[t].name}) contains duplicate keys with the same values.`); - if (hasEmptyKey(template[t].value)) errors.push(`${type} (${template.display_name || template[t].name}) field must not be empty.`); + if (hasDuplicateKeys(template[t].value)) + errors.push( + `${type} (${ + template.display_name || template[t].name + }) contains duplicate keys with the same values.` + ); + if (hasEmptyKey(template[t].value)) + errors.push( + `${type} (${ + template.display_name || template[t].name + }) field must not be empty.` + ); } return errors; }, [] as string[]); - } export function validateNodes(reactFlowInstance: ReactFlowInstance) { @@ -299,7 +312,6 @@ export function getConnectedNodes( } export function convertObjToArray(singleObject) { - if (Array.isArray(singleObject)) return singleObject; let arrConverted: any = []; @@ -329,7 +341,7 @@ export function hasDuplicateKeys(array) { export function hasEmptyKey(objArray) { for (const obj of objArray) { for (const key in obj) { - if (obj.hasOwnProperty(key) && key === '') { + if (obj.hasOwnProperty(key) && key === "") { return true; // Found an empty key } } @@ -346,10 +358,10 @@ export function convertValuesToNumbers(arr) { if (/\s/g.test(value)) { value = value.trim(); } - newObj[key] = value === "" || isNaN(value) ? value.toString() : Number(value); + newObj[key] = + value === "" || isNaN(value) ? value.toString() : Number(value); } } return newObj; }); } - diff --git a/src/frontend/src/utils/styleUtils.ts b/src/frontend/src/utils/styleUtils.ts index f04e02df9..158ab9b36 100644 --- a/src/frontend/src/utils/styleUtils.ts +++ b/src/frontend/src/utils/styleUtils.ts @@ -1,6 +1,7 @@ import { ArrowUpToLine, Bell, + BookMarked, Check, CheckCircle2, ChevronDown, @@ -78,7 +79,6 @@ import { X, XCircle, Zap, - BookMarked } from "lucide-react"; import { FaApple, FaGithub } from "react-icons/fa"; import { AirbyteIcon } from "../icons/Airbyte"; @@ -309,5 +309,5 @@ export const nodeIconsLucide: iconsType = { Key, Unplug, BookMarked, - ChevronUp + ChevronUp, };