From 7f31f7f519e4ac8ae1da5282a967bfe447cab89a Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 7 Aug 2023 18:35:14 -0300 Subject: [PATCH 1/9] refactor(chatComponent): simplify condition for setting canOpen state in Chat component The condition for setting the `canOpen` state in the Chat component was simplified by removing unnecessary checks for `formKeysData.input_keys` and `Object.keys(tabsState[flow.id].formKeysData.input_keys).length > 0`. The new condition only checks for the existence of `tabsState[flow.id].formKeysData`. This change improves code readability and reduces unnecessary complexity. --- src/frontend/src/components/chatComponent/index.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/frontend/src/components/chatComponent/index.tsx b/src/frontend/src/components/chatComponent/index.tsx index 3cbe5bbf1b..ac551f6dee 100644 --- a/src/frontend/src/components/chatComponent/index.tsx +++ b/src/frontend/src/components/chatComponent/index.tsx @@ -58,13 +58,7 @@ export default function Chat({ flow }: ChatType) { ) { setIsBuilt(false); } - if ( - tabsState && - tabsState[flow.id] && - tabsState[flow.id].formKeysData && - tabsState[flow.id].formKeysData.input_keys && - Object.keys(tabsState[flow.id].formKeysData.input_keys).length > 0 - ) { + if (tabsState && tabsState[flow.id] && tabsState[flow.id].formKeysData) { setCanOpen(true); } else { setCanOpen(false); From 9ee76fd18f9a1051aaedfa4fcc429aadb02c1f48 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 7 Aug 2023 18:37:49 -0300 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=90=9B=20fix(manager.py):=20change=20?= =?UTF-8?q?default=20value=20of=20chat=5Finputs=20from=20empty=20string=20?= =?UTF-8?q?to=20empty=20dictionary=20to=20improve=20data=20consistency=20a?= =?UTF-8?q?nd=20prevent=20potential=20errors=20=F0=9F=90=9B=20fix(utils.py?= =?UTF-8?q?):=20handle=20case=20when=20chat=5Finputs.message=20is=20None?= =?UTF-8?q?=20by=20assigning=20an=20empty=20dictionary=20to=20it=20to=20pr?= =?UTF-8?q?event=20potential=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/chat/manager.py | 2 +- src/backend/langflow/chat/utils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/chat/manager.py b/src/backend/langflow/chat/manager.py index 1e93174e2f..2c3427a123 100644 --- a/src/backend/langflow/chat/manager.py +++ b/src/backend/langflow/chat/manager.py @@ -117,7 +117,7 @@ class ChatManager: self, client_id: str, payload: Dict, langchain_object: Any ): # Process the graph data and chat message - chat_inputs = payload.pop("inputs", "") + chat_inputs = payload.pop("inputs", {}) chat_inputs = ChatMessage(message=chat_inputs) self.chat_history.add_message(client_id, chat_inputs) diff --git a/src/backend/langflow/chat/utils.py b/src/backend/langflow/chat/utils.py index 7db65b8e38..17c976eb90 100644 --- a/src/backend/langflow/chat/utils.py +++ b/src/backend/langflow/chat/utils.py @@ -21,9 +21,9 @@ async def process_graph( # Generate result and thought try: - if not chat_inputs.message: + if chat_inputs.message is None: logger.debug("No message provided") - raise ValueError("No message provided") + chat_inputs.message = {} logger.debug("Generating result and thought") result, intermediate_steps = await get_result_and_steps( From 239811dbff9c31616922b860a9d1ff222f1c51d0 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 7 Aug 2023 18:46:13 -0300 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=90=9B=20fix(chat.py):=20change=20"in?= =?UTF-8?q?put=5Fkeys"=20value=20from=20an=20empty=20dictionary=20to=20Non?= =?UTF-8?q?e=20to=20improve=20readability=20and=20reduce=20redundancy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index dd3407d1bd..06a2fdda09 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -155,7 +155,7 @@ async def stream_build(flow_id: str): ) else: input_keys_response = { - "input_keys": {}, + "input_keys": None, "memory_keys": [], "handle_keys": [], } From f61d265e77824dd448e773cbe492463455f200e9 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 7 Aug 2023 18:52:19 -0300 Subject: [PATCH 4/9] =?UTF-8?q?=F0=9F=94=A7=20chore(vector=5Fstore.py):=20?= =?UTF-8?q?refactor=20initialize=5Fchroma=20function=20to=20remove=20unnec?= =?UTF-8?q?essary=20if=20conditions=20and=20improve=20code=20readability?= =?UTF-8?q?=20=F0=9F=94=A7=20chore(vector=5Fstore.py):=20remove=20chroma?= =?UTF-8?q?=5Fserver=5F=20keys=20from=20params=20dictionary=20if=20not=20n?= =?UTF-8?q?eeded=20to=20avoid=20potential=20conflicts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/interface/initialize/vector_store.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/backend/langflow/interface/initialize/vector_store.py b/src/backend/langflow/interface/initialize/vector_store.py index 12cf054a51..8330d76112 100644 --- a/src/backend/langflow/interface/initialize/vector_store.py +++ b/src/backend/langflow/interface/initialize/vector_store.py @@ -171,11 +171,7 @@ def initialize_pinecone(class_object: Type[Pinecone], params: dict): def initialize_chroma(class_object: Type[Chroma], params: dict): """Initialize a ChromaDB object from the params""" if ( # type: ignore - "chroma_server_host" in params - or "chroma_server_http_port" in params - or "chroma_server_ssl_enabled" in params - or "chroma_server_grpc_port" in params - or "chroma_server_cors_allow_origins" in params + "chroma_server_host" in params or "chroma_server_http_port" in params ): import chromadb # type: ignore @@ -186,6 +182,14 @@ def initialize_chroma(class_object: Type[Chroma], params: dict): } chroma_settings = chromadb.config.Settings(**settings_params) params["client_settings"] = chroma_settings + else: + # remove all chroma_server_ keys from params + params = { + key: value + for key, value in params.items() + if not key.startswith("chroma_server_") + } + persist = params.pop("persist", False) if not docs_in_params(params): params.pop("documents", None) From 2abc0d2fb473a57f15d9e21dd895fe2d7364b817 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 7 Aug 2023 20:28:41 -0300 Subject: [PATCH 5/9] =?UTF-8?q?=F0=9F=90=9B=20fix(formModal/index.tsx):=20?= =?UTF-8?q?handle=20case=20when=20tabsState=20or=20formKeysData=20is=20und?= =?UTF-8?q?efined=20to=20prevent=20errors=20=E2=9C=A8=20feat(formModal/ind?= =?UTF-8?q?ex.tsx):=20add=20support=20for=20displaying=20input=20keys=20an?= =?UTF-8?q?d=20handling=20input=20changes=20in=20the=20form=20modal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/formModal/index.tsx | 139 ++++++++++---------- 1 file changed, 72 insertions(+), 67 deletions(-) diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 751eacea1f..81b15559cf 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -67,14 +67,17 @@ export default function FormModal({ const id = useRef(flow.id); const tabsStateFlowId = tabsState[flow.id]; const tabsStateFlowIdFormKeysData = tabsStateFlowId.formKeysData; - const [chatKey, setChatKey] = useState( - Object.keys(tabsState[flow.id].formKeysData.input_keys).find( - (k) => - !tabsState[flow.id].formKeysData.handle_keys.some((j) => j === k) && - tabsState[flow.id].formKeysData.input_keys[k] === "" - ) - ); - + const [chatKey, setChatKey] = useState(() => { + if (tabsState[flow.id]?.formKeysData?.input_keys) { + return Object.keys(tabsState[flow.id].formKeysData.input_keys).find( + (k) => + !tabsState[flow.id].formKeysData.handle_keys.some((j) => j === k) && + tabsState[flow.id].formKeysData.input_keys[k] === "" + ); + } + // TODO: return a sensible default + return ""; + }); useEffect(() => { if (messagesRef.current) { messagesRef.current.scrollTop = messagesRef.current.scrollHeight; @@ -419,68 +422,70 @@ export default function FormModal({ - {Object.keys(tabsState[id.current].formKeysData.input_keys).map( - (i, k) => ( -
- - - {i} - + {tabsState[id.current]?.formKeysData?.input_keys + ? Object.keys( + tabsState[id.current].formKeysData.input_keys + ).map((i, k) => ( +
+ + + {i} + -
{ - event.stopPropagation(); +
{ + event.stopPropagation(); + }} + > + + handleOnCheckedChange(value, i) + } + size="small" + disabled={tabsState[ + id.current + ].formKeysData.handle_keys.some((t) => t === i)} + /> +
+
+ } + key={k} + keyValue={i} + > +
+ {tabsState[id.current].formKeysData.handle_keys.some( + (t) => t === i + ) && ( +
+ Source: Component +
+ )} +
- } - key={k} - keyValue={i} - > -
- {tabsState[id.current].formKeysData.handle_keys.some( - (t) => t === i - ) && ( -
- Source: Component -
- )} - -
-
-
- ) - )} +
+
+ )) + : null} {tabsState[id.current].formKeysData.memory_keys.map((i, k) => (
Date: Mon, 7 Aug 2023 20:31:32 -0300 Subject: [PATCH 6/9] =?UTF-8?q?=F0=9F=90=9B=20fix(utils.ts):=20fix=20missi?= =?UTF-8?q?ng=20closing=20bracket=20in=20getChatInputField=20function=20?= =?UTF-8?q?=E2=9C=A8=20feat(utils.ts):=20add=20getChatInputField=20functio?= =?UTF-8?q?n=20to=20retrieve=20the=20chat=20input=20field=20based=20on=20t?= =?UTF-8?q?he=20current=20flow=20and=20tabs=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/utils/utils.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts index 462e720847..615e06d641 100644 --- a/src/frontend/src/utils/utils.ts +++ b/src/frontend/src/utils/utils.ts @@ -248,6 +248,26 @@ export function buildTweakObject(tweak) { return tweakString; } +/** + * Function to get Chat Input Field + * @param {FlowType} flow - The current flow. + * @param {TabsState} tabsState - The current tabs state. + * @returns {string} - The chat input field + */ +export function getChatInputField(flow: FlowType, tabsState?: TabsState) { + let chat_input_field = "text"; + + if ( + tabsState[flow.id] && + tabsState[flow.id].formKeysData && + tabsState[flow.id].formKeysData.input_keys + ) { + chat_input_field = Object.keys( + tabsState[flow.id].formKeysData.input_keys + )[0]; + } + return chat_input_field; + /** * Function to get the python code for the API * @param {string} flowId - The id of the flow @@ -365,6 +385,7 @@ export function getWidgetCode(flow: FlowType, tabsState?: TabsState): string { const flowId = flow.id; const flowName = flow.name; const inputs = buildInputs(tabsState, flow.id); + let chat_input_field = getChatInputField(flow, tabsState); return ` @@ -377,11 +398,9 @@ chat_input_field: Input key that you want the chat to send the user message with ${ tabsState[flow.id] && tabsState[flow.id].formKeysData ? `chat_inputs='${inputs}' - chat_input_field="${ - Object.keys(tabsState[flow.id].formKeysData.input_keys)[0] - }" + chat_input_field="${chat_input_field}" ` : "" - }host_url="http://localhost:7860" + }host_url="http://localhost:7860" >`; } From 16666426f729bb176f080e80a84313752bc7bc74 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 7 Aug 2023 20:31:59 -0300 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=90=9B=20fix(chatComponent):=20fix=20?= =?UTF-8?q?condition=20to=20check=20if=20parsedData.input=5Fkeys=20is=20no?= =?UTF-8?q?t=20undefined=20=E2=9C=A8=20feat(chatComponent):=20add=20logic?= =?UTF-8?q?=20to=20close=20the=20connection=20and=20finish=20when=20end=5F?= =?UTF-8?q?of=5Fstream=20event=20is=20received?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/chatComponent/buildTrigger/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx index 4eb69546e1..9b0b74678d 100644 --- a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx +++ b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx @@ -82,13 +82,15 @@ export default function BuildTrigger({ const parsedData = JSON.parse(event.data); // if the event is the end of the stream, close the connection if (parsedData.end_of_stream) { + // Close the connection and finish + finished = true; eventSource.close(); return; } else if (parsedData.log) { // If the event is a log, log it setSuccessData({ title: parsedData.log }); - } else if (parsedData.input_keys) { + } else if (parsedData.input_keys !== undefined) { setTabsState((old) => { return { ...old, From bd7489206da2b38052587a0f286b8bf8905f9917 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 7 Aug 2023 20:32:27 -0300 Subject: [PATCH 8/9] =?UTF-8?q?=F0=9F=90=9B=20fix(chatComponent):=20add=20?= =?UTF-8?q?null=20check=20for=20formKeysData.input=5Fkeys=20to=20prevent?= =?UTF-8?q?=20error=20when=20accessing=20undefined=20property?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/components/chatComponent/index.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/components/chatComponent/index.tsx b/src/frontend/src/components/chatComponent/index.tsx index ac551f6dee..2b32dc0c46 100644 --- a/src/frontend/src/components/chatComponent/index.tsx +++ b/src/frontend/src/components/chatComponent/index.tsx @@ -58,7 +58,12 @@ export default function Chat({ flow }: ChatType) { ) { setIsBuilt(false); } - if (tabsState && tabsState[flow.id] && tabsState[flow.id].formKeysData) { + if ( + tabsState && + tabsState[flow.id] && + tabsState[flow.id].formKeysData && + tabsState[flow.id].formKeysData.input_keys !== null + ) { setCanOpen(true); } else { setCanOpen(false); From d1f09a6a645e358ac2cf2ee117d31da67cc4ee3d Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 7 Aug 2023 20:34:22 -0300 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=94=A8=20refactor(utils.ts):=20remove?= =?UTF-8?q?=20unnecessary=20newline=20after=20the=20return=20statement=20i?= =?UTF-8?q?n=20getChatInputField=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/utils/utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts index 615e06d641..5e30d99cfb 100644 --- a/src/frontend/src/utils/utils.ts +++ b/src/frontend/src/utils/utils.ts @@ -267,6 +267,7 @@ export function getChatInputField(flow: FlowType, tabsState?: TabsState) { )[0]; } return chat_input_field; +} /** * Function to get the python code for the API