From f9b392d5b86b7677111ce6117b8114b16d8f0977 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 8 Aug 2023 15:02:16 -0300 Subject: [PATCH] Revert "Fixes flows without input_keys not being runnable" --- src/backend/langflow/api/v1/chat.py | 2 +- src/backend/langflow/chat/manager.py | 2 +- src/backend/langflow/chat/utils.py | 4 +- .../interface/initialize/vector_store.py | 14 +- .../chatComponent/buildTrigger/index.tsx | 4 +- .../src/components/chatComponent/index.tsx | 3 +- src/frontend/src/modals/formModal/index.tsx | 139 +++++++++--------- src/frontend/src/utils/utils.ts | 28 +--- 8 files changed, 83 insertions(+), 113 deletions(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 06a2fdda0..dd3407d1b 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": None, + "input_keys": {}, "memory_keys": [], "handle_keys": [], } diff --git a/src/backend/langflow/chat/manager.py b/src/backend/langflow/chat/manager.py index 2c3427a12..1e93174e2 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 17c976eb9..7db65b8e3 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 chat_inputs.message is None: + if not chat_inputs.message: logger.debug("No message provided") - chat_inputs.message = {} + raise ValueError("No message provided") logger.debug("Generating result and thought") result, intermediate_steps = await get_result_and_steps( diff --git a/src/backend/langflow/interface/initialize/vector_store.py b/src/backend/langflow/interface/initialize/vector_store.py index 8330d7611..12cf054a5 100644 --- a/src/backend/langflow/interface/initialize/vector_store.py +++ b/src/backend/langflow/interface/initialize/vector_store.py @@ -171,7 +171,11 @@ 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 + "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 ): import chromadb # type: ignore @@ -182,14 +186,6 @@ 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) diff --git a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx index 9b0b74678..4eb69546e 100644 --- a/src/frontend/src/components/chatComponent/buildTrigger/index.tsx +++ b/src/frontend/src/components/chatComponent/buildTrigger/index.tsx @@ -82,15 +82,13 @@ 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 !== undefined) { + } else if (parsedData.input_keys) { setTabsState((old) => { return { ...old, diff --git a/src/frontend/src/components/chatComponent/index.tsx b/src/frontend/src/components/chatComponent/index.tsx index 2b32dc0c4..3cbe5bbf1 100644 --- a/src/frontend/src/components/chatComponent/index.tsx +++ b/src/frontend/src/components/chatComponent/index.tsx @@ -62,7 +62,8 @@ export default function Chat({ flow }: ChatType) { tabsState && tabsState[flow.id] && tabsState[flow.id].formKeysData && - tabsState[flow.id].formKeysData.input_keys !== null + tabsState[flow.id].formKeysData.input_keys && + Object.keys(tabsState[flow.id].formKeysData.input_keys).length > 0 ) { setCanOpen(true); } else { diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 81b15559c..751eacea1 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -67,17 +67,14 @@ export default function FormModal({ const id = useRef(flow.id); const tabsStateFlowId = tabsState[flow.id]; const tabsStateFlowIdFormKeysData = tabsStateFlowId.formKeysData; - 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 ""; - }); + 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] === "" + ) + ); + useEffect(() => { if (messagesRef.current) { messagesRef.current.scrollTop = messagesRef.current.scrollHeight; @@ -422,70 +419,68 @@ export default function FormModal({ - {tabsState[id.current]?.formKeysData?.input_keys - ? Object.keys( - tabsState[id.current].formKeysData.input_keys - ).map((i, k) => ( -
- - - {i} - + {Object.keys(tabsState[id.current].formKeysData.input_keys).map( + (i, k) => ( +
+ + + {i} + -
{ - 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 -
- )} - + > + + handleOnCheckedChange(value, i) + } + size="small" + disabled={tabsState[ + id.current + ].formKeysData.handle_keys.some((t) => t === i)} + /> +
- - - )) - : null} + } + key={k} + keyValue={i} + > +
+ {tabsState[id.current].formKeysData.handle_keys.some( + (t) => t === i + ) && ( +
+ Source: Component +
+ )} + +
+ + + ) + )} {tabsState[id.current].formKeysData.memory_keys.map((i, k) => (
@@ -399,9 +377,11 @@ 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="${chat_input_field}" + chat_input_field="${ + Object.keys(tabsState[flow.id].formKeysData.input_keys)[0] + }" ` : "" - }host_url="http://localhost:7860" + }host_url="http://localhost:7860" >`; }