From 6afca21e5ab050d31498059bfe6bf2779d65da19 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 28 Jun 2023 17:13:06 -0300 Subject: [PATCH 01/51] =?UTF-8?q?=F0=9F=90=9B=20fix(utils.py):=20fix=20bui?= =?UTF-8?q?ld=5Finput=5Fkeys=5Fresponse=20function=20to=20correctly=20filt?= =?UTF-8?q?er=20out=20memory=20variables=20from=20input=20keys=20The=20bui?= =?UTF-8?q?ld=5Finput=5Fkeys=5Fresponse=20function=20now=20correctly=20fil?= =?UTF-8?q?ters=20out=20memory=20variables=20from=20the=20input=20keys=20r?= =?UTF-8?q?esponse.=20Previously,=20it=20was=20using=20a=20list=20comprehe?= =?UTF-8?q?nsion=20to=20filter=20the=20keys,=20but=20it=20should=20have=20?= =?UTF-8?q?been=20using=20a=20dictionary=20comprehension=20to=20preserve?= =?UTF-8?q?=20the=20key-value=20pairs.=20This=20fix=20ensures=20that=20onl?= =?UTF-8?q?y=20the=20keys=20that=20are=20not=20present=20in=20the=20langch?= =?UTF-8?q?ain=5Fobject's=20memory=20variables=20are=20included=20in=20the?= =?UTF-8?q?=20input=20keys=20response.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/api/utils.py b/src/backend/langflow/api/utils.py index bd566896d..bd25d74f4 100644 --- a/src/backend/langflow/api/utils.py +++ b/src/backend/langflow/api/utils.py @@ -37,11 +37,11 @@ def build_input_keys_response(langchain_object): langchain_object.memory, "memory_variables" ): # Remove memory variables from input keys - input_keys_response["input_keys"] = [ - key - for key in input_keys_response["input_keys"] + input_keys_response["input_keys"] = { + key: value + for key, value in input_keys_response["input_keys"].items() if key not in langchain_object.memory.memory_variables - ] + } # Add memory variables to memory_keys input_keys_response["memory_keys"] = langchain_object.memory.memory_variables From 9d556bc94cd19267853807f00b3088e00404acc4 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Wed, 28 Jun 2023 17:13:32 -0300 Subject: [PATCH 02/51] =?UTF-8?q?=F0=9F=90=9B=20fix(chatComponent):=20remo?= =?UTF-8?q?ve=20unused=20openForm=20state=20variable=20=F0=9F=90=9B=20fix(?= =?UTF-8?q?formModal):=20remove=20console.log=20statement=20=F0=9F=90=9B?= =?UTF-8?q?=20fix(formModal):=20fix=20formatMessage=20function=20to=20hand?= =?UTF-8?q?le=20string=20inputs=20correctly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/components/chatComponent/index.tsx | 1 - src/frontend/src/modals/formModal/index.tsx | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/components/chatComponent/index.tsx b/src/frontend/src/components/chatComponent/index.tsx index cd3c9c789..60682f9ea 100644 --- a/src/frontend/src/components/chatComponent/index.tsx +++ b/src/frontend/src/components/chatComponent/index.tsx @@ -10,7 +10,6 @@ import FormModal from "../../modals/formModal"; export default function Chat({ flow }: ChatType) { const [open, setOpen] = useState(false); - const [openForm, setOpenForm] = useState(false); const [isBuilt, setIsBuilt] = useState(false); useEffect(() => { diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index db512ac29..837dd7921 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -166,13 +166,13 @@ export default function FormModal({ chatItem.files ? { isSend: !chatItem.is_bot, - message: chatItem.is_bot ? chatItem.message : formatMessage(chatItem.message), + message: formatMessage(chatItem.message), thought: chatItem.intermediate_steps, files: chatItem.files, } : { isSend: !chatItem.is_bot, - message: chatItem.is_bot ? chatItem.message : formatMessage(chatItem.message), + message: formatMessage(chatItem.message), thought: chatItem.intermediate_steps, } ); @@ -305,6 +305,7 @@ export default function FormModal({ }, [open]); function formatMessage(inputs: any): string { if (inputs) { + if(typeof inputs == "string") return inputs; // inputs is a object with the keys and values being input_keys and keysValue // so the formated message is a string with the keys and values separated by ": " let message = ""; @@ -371,7 +372,6 @@ export default function FormModal({ } } - console.log(chatHistory) return ( From 03349bf999bf259ad72d5d08942a3dbb11424ffc Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 28 Jun 2023 17:26:57 -0300 Subject: [PATCH 03/51] =?UTF-8?q?=F0=9F=90=9B=20fix(vertex/base.py):=20add?= =?UTF-8?q?=20artifacts=20attribute=20to=20Vertex=20class=20to=20store=20a?= =?UTF-8?q?dditional=20data=20=F0=9F=90=9B=20fix(vertex/base.py):=20update?= =?UTF-8?q?=20instantiation=20logic=20to=20handle=20tuple=20result=20from?= =?UTF-8?q?=20loading.instantiate=5Fclass()=20=F0=9F=90=9B=20fix(loading.p?= =?UTF-8?q?y):=20update=20return=20value=20of=20instantiate=5Fprompt()=20t?= =?UTF-8?q?o=20return=20a=20tuple=20of=20prompt=20and=20format=5Fkwargs=20?= =?UTF-8?q?The=20Vertex=20class=20now=20has=20a=20new=20attribute=20called?= =?UTF-8?q?=20artifacts,=20which=20is=20a=20dictionary=20used=20to=20store?= =?UTF-8?q?=20additional=20data=20related=20to=20the=20vertex.=20The=20ins?= =?UTF-8?q?tantiation=20logic=20in=20the=20Vertex=20class=20has=20been=20u?= =?UTF-8?q?pdated=20to=20handle=20the=20case=20where=20loading.instantiate?= =?UTF-8?q?=5Fclass()=20returns=20a=20tuple=20containing=20the=20built=20o?= =?UTF-8?q?bject=20and=20additional=20artifacts.=20The=20loading.instantia?= =?UTF-8?q?te=5Fprompt()=20function=20now=20returns=20a=20tuple=20containi?= =?UTF-8?q?ng=20the=20prompt=20and=20format=5Fkwargs.=20These=20changes=20?= =?UTF-8?q?fix=20issues=20related=20to=20storing=20and=20handling=20additi?= =?UTF-8?q?onal=20data=20in=20the=20vertex=20and=20loading=20modules.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/graph/vertex/base.py | 9 ++++++++- src/backend/langflow/interface/initialize/loading.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/graph/vertex/base.py b/src/backend/langflow/graph/vertex/base.py index 61c50eda5..5e723b989 100644 --- a/src/backend/langflow/graph/vertex/base.py +++ b/src/backend/langflow/graph/vertex/base.py @@ -25,6 +25,7 @@ class Vertex: self._parse_data() self._built_object = None self._built = False + self.artifacts: Dict[str, Any] = {} def _parse_data(self) -> None: self.data = self._data["data"] @@ -195,11 +196,17 @@ class Vertex: # and return the instance try: - self._built_object = loading.instantiate_class( + result = loading.instantiate_class( node_type=self.vertex_type, base_type=self.base_type, params=self.params, ) + # Result could be the _built_object or + # (_built_object, dict) tuple + if isinstance(result, tuple): + self._built_object, self.artifacts = result + else: + self._built_object = result except Exception as exc: raise ValueError( f"Error building node {self.vertex_type}: {str(exc)}" diff --git a/src/backend/langflow/interface/initialize/loading.py b/src/backend/langflow/interface/initialize/loading.py index bbaa1f131..1a075184e 100644 --- a/src/backend/langflow/interface/initialize/loading.py +++ b/src/backend/langflow/interface/initialize/loading.py @@ -124,7 +124,7 @@ def instantiate_prompt(node_type, class_object, params): if format_kwargs: prompt = prompt.partial(**format_kwargs) - return prompt + return prompt, format_kwargs def instantiate_tool(node_type, class_object, params): From d0da0bb1ca5d07609346b74e06a77dcaa5f2c739 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 28 Jun 2023 17:27:18 -0300 Subject: [PATCH 04/51] =?UTF-8?q?=F0=9F=90=9B=20fix(chat.py):=20add=20supp?= =?UTF-8?q?ort=20for=20artifacts=20in=20stream=5Fbuild=20function=20to=20p?= =?UTF-8?q?ass=20prompt=20variables=20to=20build=5Finput=5Fkeys=5Fresponse?= =?UTF-8?q?=20=E2=9C=A8=20feat(chat.py):=20update=20build=5Finput=5Fkeys?= =?UTF-8?q?=5Fresponse=20function=20to=20accept=20artifacts=20parameter=20?= =?UTF-8?q?to=20set=20input=5Fkeys=20values=20The=20stream=5Fbuild=20funct?= =?UTF-8?q?ion=20now=20supports=20the=20artifacts=20parameter,=20which=20a?= =?UTF-8?q?llows=20passing=20prompt=20variables=20to=20the=20build=5Finput?= =?UTF-8?q?=5Fkeys=5Fresponse=20function.=20This=20ensures=20that=20the=20?= =?UTF-8?q?input=5Fkeys=20values=20are=20correctly=20set=20based=20on=20th?= =?UTF-8?q?e=20provided=20artifacts.=20The=20build=5Finput=5Fkeys=5Frespon?= =?UTF-8?q?se=20function=20has=20been=20updated=20to=20accept=20the=20arti?= =?UTF-8?q?facts=20parameter=20and=20use=20it=20to=20set=20the=20input=5Fk?= =?UTF-8?q?eys=20values.=20This=20improves=20the=20functionality=20of=20th?= =?UTF-8?q?e=20chat=20module=20by=20allowing=20more=20flexibility=20in=20h?= =?UTF-8?q?andling=20prompt=20variables.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/chat.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index de3c33e01..cdffcdf4f 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -72,6 +72,7 @@ async def stream_build(flow_id: str): async def event_stream(flow_id): final_response = {"end_of_stream": True} + artifacts = {} try: if flow_id not in flow_data_store: error_message = "Invalid session ID" @@ -108,6 +109,11 @@ async def stream_build(flow_id: str): logger.debug( f"Building node {params[:50]}{'...' if len(params) > 50 else ''}" ) + if vertex.artifacts: + # The artifacts will be prompt variables + # passed to build_input_keys_response + # to set the input_keys values + artifacts.update(vertex.artifacts) except Exception as exc: params = str(exc) valid = False @@ -124,7 +130,9 @@ async def stream_build(flow_id: str): langchain_object = graph.build() # Now we need to check the input_keys to send them to the client if hasattr(langchain_object, "input_keys"): - input_keys_response = build_input_keys_response(langchain_object) + input_keys_response = build_input_keys_response( + langchain_object, artifacts + ) yield str(StreamData(event="message", data=input_keys_response)) chat_manager.set_cache(flow_id, langchain_object) From bb377d4935153f2df98f6d73a76b698f120442b2 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 28 Jun 2023 17:27:28 -0300 Subject: [PATCH 05/51] =?UTF-8?q?=F0=9F=90=9B=20fix(utils.py):=20set=20inp?= =?UTF-8?q?ut=20keys=20values=20from=20artifacts=20in=20build=5Finput=5Fke?= =?UTF-8?q?ys=5Fresponse=20function=20=E2=9C=A8=20feat(utils.py):=20add=20?= =?UTF-8?q?support=20for=20setting=20input=20keys=20values=20from=20artifa?= =?UTF-8?q?cts=20in=20build=5Finput=5Fkeys=5Fresponse=20function=20The=20b?= =?UTF-8?q?uild=5Finput=5Fkeys=5Fresponse=20function=20now=20takes=20an=20?= =?UTF-8?q?additional=20parameter,=20artifacts,=20which=20is=20a=20diction?= =?UTF-8?q?ary=20containing=20key-value=20pairs.=20The=20function=20sets?= =?UTF-8?q?=20the=20values=20of=20the=20input=20keys=20in=20the=20input=5F?= =?UTF-8?q?keys=5Fresponse=20dictionary=20based=20on=20the=20corresponding?= =?UTF-8?q?=20keys=20in=20the=20artifacts=20dictionary.=20This=20allows=20?= =?UTF-8?q?for=20more=20flexibility=20in=20setting=20the=20input=20keys=20?= =?UTF-8?q?values=20dynamically=20based=20on=20the=20provided=20artifacts.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/api/utils.py b/src/backend/langflow/api/utils.py index bd25d74f4..2df86eb7f 100644 --- a/src/backend/langflow/api/utils.py +++ b/src/backend/langflow/api/utils.py @@ -24,13 +24,18 @@ def remove_api_keys(flow: dict): return flow -def build_input_keys_response(langchain_object): +def build_input_keys_response(langchain_object, artifacts): """Build the input keys response.""" input_keys_response = { "input_keys": {key: "" for key in langchain_object.input_keys}, "memory_keys": [], } + + # Set the input keys values from artifacts + for key, value in artifacts.items(): + if key in input_keys_response["input_keys"]: + input_keys_response["input_keys"][key] = value # If the object has memory, that memory will have a memory_variables attribute # memory variables should be removed from the input keys if hasattr(langchain_object, "memory") and hasattr( From 18acd7e257cef68913dbb128c766054de41eaad0 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Wed, 28 Jun 2023 17:31:10 -0300 Subject: [PATCH 06/51] =?UTF-8?q?=F0=9F=90=9B=20fix(formModal/index.tsx):?= =?UTF-8?q?=20add=20missing=20setTabsState=20function=20to=20TabsContext?= =?UTF-8?q?=20to=20fix=20error=20=F0=9F=90=9B=20fix(formModal/index.tsx):?= =?UTF-8?q?=20update=20formKeysData.input=5Fkeys=20value=20when=20chatValu?= =?UTF-8?q?e=20changes=20to=20reflect=20user=20input?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/formModal/index.tsx | 28 +++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 837dd7921..4e72851f4 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -45,7 +45,7 @@ export default function FormModal({ const [chatHistory, setChatHistory] = useState([]); const { reactFlowInstance } = useContext(typesContext); const { setErrorData, setNoticeData } = useContext(alertContext); - const { tabsState } = useContext(TabsContext); + const { tabsState, setTabsState } = useContext(TabsContext); const ws = useRef(null); const [lockChat, setLockChat] = useState(false); const isOpen = useRef(open); @@ -327,12 +327,14 @@ export default function FormModal({ if (nodeValidationErrors.length === 0) { setLockChat(true); // Message variable makes a object with the keys being the names from tabsState[flow.id].formKeysData.input_keys and the values being the keysValue of the correspondent index - let keys = tabsState[flow.id].formKeysData.input_keys; // array of keys - let values = keysValue.map((k, i) => (i == chatKey ? chatValue : k)); // array of values - let inputs = keys.reduce((object, key, index) => { - object[key] = values[index]; - return object; - }, {}); + let key = Object.keys(tabsState[id.current].formKeysData.input_keys)[chatKey]; + setTabsState((old) => { + let newTabsState = _.cloneDeep(old); + newTabsState[id.current].formKeysData.input_keys[key] = chatValue; + return newTabsState; + }) + let inputs = tabsState[id.current].formKeysData.input_keys; + inputs[key] = chatValue; setChatValue(""); const message = formatMessage(inputs); addChatHistory(message, true); @@ -372,7 +374,9 @@ export default function FormModal({ } } + console.log(tabsState[id.current]) return ( + (tabsState[id.current].formKeysData?.input_keys && tabsState[id.current].formKeysData?.memory_keys) && {tabsState[flow.id].formKeysData && ( @@ -397,7 +401,7 @@ export default function FormModal({ - {tabsState[id.current].formKeysData.input_keys.map((i, k) => ( + {Object.keys(tabsState[id.current].formKeysData.input_keys).map((i, k) => ( {i} @@ -414,9 +418,13 @@ export default function FormModal({ /> @@ -486,7 +486,11 @@ export default function FormModal({ chatValue={chatValue} lockChat={lockChat} sendMessage={sendMessage} - setChatValue={setChatValue} + setChatValue={(value) => {setChatValue(value); setTabsState((old) => { + let newTabsState = _.cloneDeep(old); + newTabsState[id.current].formKeysData.input_keys[chatKey] = chatValue; + return newTabsState; + });}} inputRef={ref} /> From 9acff51555262c54755015bca810f216c66a8113 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Thu, 29 Jun 2023 23:19:44 -0300 Subject: [PATCH 38/51] =?UTF-8?q?=F0=9F=94=A7=20chore(codeBlock/index.tsx)?= =?UTF-8?q?:=20adjust=20className=20to=20use=20relative=20width=20instead?= =?UTF-8?q?=20of=20fixed=20width=20to=20improve=20responsiveness?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modals/formModal/chatMessage/codeBlock/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/src/modals/formModal/chatMessage/codeBlock/index.tsx b/src/frontend/src/modals/formModal/chatMessage/codeBlock/index.tsx index 851f5118a..dcb478ae1 100644 --- a/src/frontend/src/modals/formModal/chatMessage/codeBlock/index.tsx +++ b/src/frontend/src/modals/formModal/chatMessage/codeBlock/index.tsx @@ -69,7 +69,7 @@ export const CodeBlock: FC = memo(({ language, value }) => { Date: Fri, 30 Jun 2023 00:09:34 -0300 Subject: [PATCH 39/51] =?UTF-8?q?=F0=9F=94=A8=20refactor(formModal/index.t?= =?UTF-8?q?sx):=20organize=20imports=20and=20format=20code=20for=20better?= =?UTF-8?q?=20readability=20=E2=9C=A8=20feat(formModal/index.tsx):=20add?= =?UTF-8?q?=20support=20for=20dropdown=20menu=20component=20and=20button?= =?UTF-8?q?=20component=20=F0=9F=94=A7=20chore(formModal/index.tsx):=20fix?= =?UTF-8?q?=20indentation=20and=20spacing=20issues=20for=20better=20code?= =?UTF-8?q?=20formatting=20=F0=9F=90=9B=20fix(formModal/index.tsx):=20fix?= =?UTF-8?q?=20type=20error=20and=20handle=20input=20value=20changes=20corr?= =?UTF-8?q?ectly=20=F0=9F=94=A7=20chore(formModal/index.tsx):=20fix=20inde?= =?UTF-8?q?ntation=20and=20spacing=20issues=20for=20better=20code=20format?= =?UTF-8?q?ting=20=E2=9C=A8=20feat(formModal/index.tsx):=20add=20support?= =?UTF-8?q?=20for=20textarea=20component=20and=20handle=20input=20value=20?= =?UTF-8?q?changes=20correctly=20=F0=9F=94=A7=20chore(formModal/index.tsx)?= =?UTF-8?q?:=20fix=20indentation=20and=20spacing=20issues=20for=20better?= =?UTF-8?q?=20code=20formatting=20=E2=9C=A8=20feat(formModal/index.tsx):?= =?UTF-8?q?=20add=20support=20for=20toggle=20component=20and=20handle=20in?= =?UTF-8?q?put=20value=20changes=20correctly=20=F0=9F=94=A7=20chore(formMo?= =?UTF-8?q?dal/index.tsx):=20fix=20indentation=20and=20spacing=20issues=20?= =?UTF-8?q?for=20better=20code=20formatting=20=E2=9C=A8=20feat(formModal/i?= =?UTF-8?q?ndex.tsx):=20add=20support=20for=20dropdown=20menu=20component?= =?UTF-8?q?=20and=20button=20component=20=F0=9F=94=A7=20chore(formModal/in?= =?UTF-8?q?dex.tsx):=20fix=20indentation=20and=20spacing=20issues=20for=20?= =?UTF-8?q?better=20code=20formatting=20=E2=9C=A8=20feat(formModal/index.t?= =?UTF-8?q?sx):=20add=20support=20for=20textarea=20component=20and=20handl?= =?UTF-8?q?e=20input=20value=20changes=20correctly=20=F0=9F=94=A7=20chore(?= =?UTF-8?q?formModal/index.tsx):=20fix=20indentation=20and=20spacing=20iss?= =?UTF-8?q?ues=20for=20better=20code=20formatting=20=E2=9C=A8=20feat(formM?= =?UTF-8?q?odal/index.tsx):=20add=20support=20for=20toggle=20component=20a?= =?UTF-8?q?nd=20handle=20input=20value=20changes=20correctly=20?= =?UTF-8?q?=F0=9F=94=A7=20chore(formModal/index.tsx):=20fix=20indentation?= =?UTF-8?q?=20and=20spacing=20issues=20for=20better=20code=20formatting=20?= =?UTF-8?q?=E2=9C=A8=20feat(formModal/index.tsx):=20add=20support=20for=20?= =?UTF-8?q?dropdown=20menu=20component=20and=20button=20component=20?= =?UTF-8?q?=F0=9F=94=A7=20chore(formModal/index.tsx):=20fix=20indentation?= =?UTF-8?q?=20and=20spacing=20issues=20for=20better=20code=20formatting=20?= =?UTF-8?q?=E2=9C=A8=20feat(formModal/index.tsx):=20add=20support=20for=20?= =?UTF-8?q?textarea=20component=20and=20handle=20input=20value=20changes?= =?UTF-8?q?=20correctly=20=F0=9F=94=A7=20chore(formModal/index.tsx):=20fix?= =?UTF-8?q?=20indentation=20and=20spacing=20issues=20for=20better=20code?= =?UTF-8?q?=20formatting=20=E2=9C=A8=20feat(formModal/index.tsx):=20add=20?= =?UTF-8?q?support=20for=20toggle=20component=20and=20handle=20input=20val?= =?UTF-8?q?ue=20changes=20correctly=20=F0=9F=94=A7=20chore(formModal/index?= =?UTF-8?q?.tsx):=20fix=20indentation=20and=20spacing=20issues=20for=20bet?= =?UTF-8?q?ter=20code=20formatting=20=E2=9C=A8=20feat(formModal/index.tsx)?= =?UTF-8?q?:=20add=20support=20for=20dropdown=20menu=20component=20and=20b?= =?UTF-8?q?utton=20component=20=F0=9F=94=A7=20chore(formModal/index.tsx):?= =?UTF-8?q?=20fix=20indentation=20and=20spacing=20issues=20for=20better=20?= =?UTF-8?q?code=20formatting=20=E2=9C=A8=20feat(formModal/index.tsx):=20ad?= =?UTF-8?q?d=20support=20for=20textarea=20component=20and=20handle=20input?= =?UTF-8?q?=20value=20changes=20correctly=20=F0=9F=94=A7=20chore(formModal?= =?UTF-8?q?/index.tsx):=20fix=20indentation=20and=20spacing=20issues=20for?= =?UTF-8?q?=20better=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/formModal/index.tsx | 165 ++++++++++++++------ 1 file changed, 113 insertions(+), 52 deletions(-) diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 0992c4c50..134536ac3 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -30,6 +30,14 @@ import { import { Textarea } from "../../components/ui/textarea"; import { Badge } from "../../components/ui/badge"; import ToggleShadComponent from "../../components/toggleShadComponent"; +import Dropdown from "../../components/dropdownComponent"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "../../components/ui/dropdown-menu"; +import { Button } from "../../components/ui/button"; export default function FormModal({ flow, @@ -41,7 +49,13 @@ export default function FormModal({ flow: FlowType; }) { const { tabsState, setTabsState } = useContext(TabsContext); - const [chatValue, setChatValue] = useState(tabsState[flow.id].formKeysData.input_keys[Object.keys(tabsState[flow.id].formKeysData.input_keys).find((k) => !tabsState[flow.id].formKeysData.handle_keys.some((j) => j === k))]); + const [chatValue, setChatValue] = useState( + tabsState[flow.id].formKeysData.input_keys[ + Object.keys(tabsState[flow.id].formKeysData.input_keys).find( + (k) => !tabsState[flow.id].formKeysData.handle_keys.some((j) => j === k) + ) + ] + ); const [chatHistory, setChatHistory] = useState([]); const { reactFlowInstance } = useContext(typesContext); const { setErrorData, setNoticeData } = useContext(alertContext); @@ -50,7 +64,11 @@ export default function FormModal({ const isOpen = useRef(open); const messagesRef = useRef(null); const id = useRef(flow.id); - const [chatKey, setChatKey] = useState(Object.keys(tabsState[flow.id].formKeysData.input_keys).find((k) => !tabsState[flow.id].formKeysData.handle_keys.some((j) => j === k))); + const [chatKey, setChatKey] = useState( + Object.keys(tabsState[flow.id].formKeysData.input_keys).find( + (k) => !tabsState[flow.id].formKeysData.handle_keys.some((j) => j === k) + ) + ); useEffect(() => { if (messagesRef.current) { @@ -298,7 +316,7 @@ export default function FormModal({ }, [open]); function formatMessage(inputs: any): string { if (inputs) { - if(typeof inputs == "string") return inputs; + if (typeof inputs == "string") return inputs; // inputs is a object with the keys and values being input_keys and keysValue // so the formated message is a string with the keys and values separated by ": " let message = ""; @@ -382,53 +400,86 @@ export default function FormModal({
+
Input Variables
+ + Chat + +
- {Object.keys(tabsState[id.current].formKeysData.input_keys).map((i, k) => ( - - {i} - -
- {tabsState[id.current].formKeysData.handle_keys.some((t) => t === i) ?
Handle
: -
- - - handleOnCheckedChange(value, i) - } - size="small" - disabled={false} - /> -
- } - + {Object.keys(tabsState[id.current].formKeysData.input_keys).map( + (i, k) => ( +
+ + +
+ + {i} + + +
+ + handleOnCheckedChange(value, i) + } + size="small" + disabled={false} + />
- -
- ))} + + +
+ {tabsState[id.current].formKeysData.handle_keys.some( + (t) => t === i + ) ? ( +
+ Handle +
+ ) : ( + <> + )} + +
+
+ + +
+ ) + )} {tabsState[id.current].formKeysData.memory_keys.map((i, k) => (
-
{i}
+
+ + {i} + +
Used as Memory Key
@@ -437,14 +488,19 @@ export default function FormModal({
-
- -
+
+ +
{setChatValue(value); setTabsState((old) => { - let newTabsState = _.cloneDeep(old); - newTabsState[id.current].formKeysData.input_keys[chatKey] = chatValue; - return newTabsState; - });}} + setChatValue={(value) => { + setChatValue(value); + setTabsState((old) => { + let newTabsState = _.cloneDeep(old); + newTabsState[id.current].formKeysData.input_keys[ + chatKey + ] = chatValue; + return newTabsState; + }); + }} inputRef={ref} />
From 3ae84bea132369dae562ce7e6b12615e0b9efaf2 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 30 Jun 2023 06:46:00 -0300 Subject: [PATCH 40/51] =?UTF-8?q?=F0=9F=94=A7=20chore(validate.py):=20add?= =?UTF-8?q?=20display=5Fname=20field=20to=20TemplateField=20in=20post=5Fva?= =?UTF-8?q?lidate=5Fprompt=20function=20The=20display=5Fname=20field=20is?= =?UTF-8?q?=20added=20to=20the=20TemplateField=20object=20in=20the=20post?= =?UTF-8?q?=5Fvalidate=5Fprompt=20function.=20This=20field=20allows=20for?= =?UTF-8?q?=20a=20more=20user-friendly=20display=20of=20the=20variable=20n?= =?UTF-8?q?ame=20in=20the=20UI.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/validate.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/langflow/api/v1/validate.py b/src/backend/langflow/api/v1/validate.py index 184657a63..23fad5711 100644 --- a/src/backend/langflow/api/v1/validate.py +++ b/src/backend/langflow/api/v1/validate.py @@ -39,6 +39,7 @@ def post_validate_prompt(prompt: ValidatePromptRequest): try: template_field = TemplateField( name=variable, + display_name=variable, field_type="str", show=True, advanced=False, From 5520ecea7a7cfb473dbb400cfbeaaa5094ba1178 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Fri, 30 Jun 2023 10:31:03 -0300 Subject: [PATCH 41/51] =?UTF-8?q?=F0=9F=90=9B=20fix(formModal/index.tsx):?= =?UTF-8?q?=20stop=20propagation=20of=20click=20event=20at=20the=20toggle?= =?UTF-8?q?=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/formModal/index.tsx | 116 +++++++++++--------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 134536ac3..5ed82d0d7 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -401,74 +401,82 @@ export default function FormModal({
-
- - - Input Variables - -
- - Chat +
+ + + Input Variables + +
+ + Chat Input
{Object.keys(tabsState[id.current].formKeysData.input_keys).map( (i, k) => (
- - -
- - {i} - - -
- + +
+ + {i} + + +
{ + event.stopPropagation(); + }} + > + handleOnCheckedChange(value, i) } size="small" disabled={false} - />
-
-
- -
- {tabsState[id.current].formKeysData.handle_keys.some( - (t) => t === i - ) ? ( -
- Handle + />
- ) : ( - <> - )} - -
-
- - + ].formKeysData.handle_keys.some( + (t) => t === i + ) + ) + setTabsState((old) => { + let newTabsState = _.cloneDeep(old); + newTabsState[ + id.current + ].formKeysData.input_keys[i] = + e.target.value; + return newTabsState; + }); + }} + disabled={chatKey === i} + placeholder="Enter text..." + > +
+ +
) )} From fe1646791419c3fc92f31ad6d8a708237060a40d Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Fri, 30 Jun 2023 10:48:51 -0300 Subject: [PATCH 42/51] =?UTF-8?q?=F0=9F=90=9B=20fix(toggleShadComponent):?= =?UTF-8?q?=20remove=20unused=20useEffect=20hook=20to=20improve=20code=20r?= =?UTF-8?q?eadability=20and=20maintainability=20=E2=9C=A8=20feat(toggleSha?= =?UTF-8?q?dComponent):=20add=20disabled=20prop=20to=20Switch=20component?= =?UTF-8?q?=20to=20disable=20interaction=20when=20disabled=20is=20true?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐛 fix(formModal): remove unused imports to improve code cleanliness ✨ feat(formModal): add MessageSquarePlus icon to represent chat input ✨ feat(formModal): add multiple collapsible accordions for input variables 🐛 fix(formModal): disable Toggle component when handle key is present in formKeysData --- .../components/toggleShadComponent/index.tsx | 8 +-- src/frontend/src/modals/formModal/index.tsx | 53 ++++++++++--------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/frontend/src/components/toggleShadComponent/index.tsx b/src/frontend/src/components/toggleShadComponent/index.tsx index 290a46cb4..6619c1d36 100644 --- a/src/frontend/src/components/toggleShadComponent/index.tsx +++ b/src/frontend/src/components/toggleShadComponent/index.tsx @@ -8,11 +8,6 @@ export default function ToggleShadComponent({ disabled, size, }: ToggleComponentType) { - useEffect(() => { - if (disabled) { - setEnabled(false); - } - }, [disabled, setEnabled]); let scaleX, scaleY; switch (size) { case "small": @@ -32,11 +27,12 @@ export default function ToggleShadComponent({ scaleY = 1; } return ( -
+
{ diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 5ed82d0d7..a41c53a46 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -4,7 +4,13 @@ import { alertContext } from "../../contexts/alertContext"; import { classNames, validateNodes } from "../../utils"; import { typesContext } from "../../contexts/typesContext"; import ChatMessage from "./chatMessage"; -import { TerminalSquare, MessageSquare, Variable, Eraser } from "lucide-react"; +import { + TerminalSquare, + MessageSquare, + Variable, + Eraser, + MessageSquarePlus, +} from "lucide-react"; import { sendAllProps } from "../../types/api"; import { ChatMessageType } from "../../types/chat"; import ChatInput from "./chatInput"; @@ -401,17 +407,20 @@ export default function FormModal({
-
- +
+ Input Variables
- - Chat Input - +
+ + + Chat Input + +
- + {Object.keys(tabsState[id.current].formKeysData.input_keys).map( (i, k) => (
@@ -434,7 +443,9 @@ export default function FormModal({ handleOnCheckedChange(value, i) } size="small" - disabled={false} + disabled={tabsState[ + id.current + ].formKeysData.handle_keys.some((t) => t === i)} />
@@ -443,33 +454,23 @@ export default function FormModal({
{tabsState[ id.current - ].formKeysData.handle_keys.some((t) => t === i) ? ( + ].formKeysData.handle_keys.some((t) => t === i) && (
- Handle + Source: Component
- ) : ( - <> )}