From df8dd44a16c76d508b5018393da13d24f2d22344 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 5 Oct 2023 17:39:56 -0300 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=90=9B=20fix(manager.py):=20remove=20?= =?UTF-8?q?unnecessary=20exception=20handling=20and=20logging=20for=20JSON?= =?UTF-8?q?=20decoding=20error=20=F0=9F=90=9B=20fix(manager.py):=20fix=20c?= =?UTF-8?q?ondition=20for=20clearing=20chat=20history=20to=20only=20clear?= =?UTF-8?q?=20if=20"clear=5Fhistory"=20key=20is=20present=20and=20its=20va?= =?UTF-8?q?lue=20is=20truthy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/services/chat/manager.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/backend/langflow/services/chat/manager.py b/src/backend/langflow/services/chat/manager.py index 9d50f3026..ae5816942 100644 --- a/src/backend/langflow/services/chat/manager.py +++ b/src/backend/langflow/services/chat/manager.py @@ -204,11 +204,9 @@ class ChatService(Service): json_payload = await websocket.receive_json() try: payload = orjson.loads(json_payload) - # except TypeError or JSONDecodeError how? except Exception as exc: - logger.error(f"Error decoding JSON: {exc}") payload = json_payload - if "clear_history" in payload: + if "clear_history" in payload and payload["clear_history"]: self.chat_history.history[client_id] = [] continue From 57b9ab6843a7089c4494931c7a1d2a711f4c7ba0 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 5 Oct 2023 17:41:10 -0300 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20fix(manager.py):=20change=20?= =?UTF-8?q?try-except=20block=20to=20if-elif=20block=20to=20improve=20code?= =?UTF-8?q?=20readability=20and=20maintainability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/services/chat/manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/services/chat/manager.py b/src/backend/langflow/services/chat/manager.py index ae5816942..59488d431 100644 --- a/src/backend/langflow/services/chat/manager.py +++ b/src/backend/langflow/services/chat/manager.py @@ -202,9 +202,9 @@ class ChatService(Service): while True: json_payload = await websocket.receive_json() - try: + if isinstance(json_payload, str): payload = orjson.loads(json_payload) - except Exception as exc: + elif isinstance(json_payload, dict): payload = json_payload if "clear_history" in payload and payload["clear_history"]: self.chat_history.history[client_id] = [] From 03d12b53cdec0eeabd56f0931b06a34e2e0ef8ce Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Thu, 5 Oct 2023 17:55:44 -0300 Subject: [PATCH 3/4] fix(formModal/index.tsx): update updateLastMessage function to include prompt value when data.type is "end" fix(formModal/index.tsx): update template.current value when data.type is "prompt" and data.prompt is provided fix(formModal/index.tsx): remove unnecessary updateLastMessage call when data.type is "stream" and isStream is true --- src/frontend/src/modals/formModal/index.tsx | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 9de968ff8..2c7fa53fe 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -261,7 +261,11 @@ export default function FormModal({ } if (data.type === "end") { if (data.message) { - updateLastMessage({ str: data.message, end: true }); + updateLastMessage({ + str: data.message, + end: true, + prompt: template.current, + }); } if (data.intermediate_steps) { updateLastMessage({ @@ -276,19 +280,14 @@ export default function FormModal({ files: data.files, }); } - if (data.type === "prompt" && data.prompt) { - template.current = data.prompt; - } - setLockChat(false); isStream = false; } + if (data.type == "prompt" && data.prompt) { + template.current = data.prompt; + } if (data.type === "stream" && isStream) { - if (data.prompt) { - updateLastMessage({ prompt: data.prompt }); - } else { - updateLastMessage({ str: data.message }); - } + updateLastMessage({ str: data.message }); } } From 56c2be58675a2a5f9ad065c643c367ca199e8751 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Thu, 5 Oct 2023 18:04:21 -0300 Subject: [PATCH 4/4] fix(api.tsx): remove unnecessary try-catch block and add error logging for better debugging fix(index.ts): remove console.log statement for error logging --- src/frontend/src/controllers/API/api.tsx | 14 ++++++++------ src/frontend/src/controllers/API/index.ts | 1 - 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/frontend/src/controllers/API/api.tsx b/src/frontend/src/controllers/API/api.tsx index 75be74fac..2847fe8b0 100644 --- a/src/frontend/src/controllers/API/api.tsx +++ b/src/frontend/src/controllers/API/api.tsx @@ -31,13 +31,11 @@ function ApiInterceptor() { logout(); navigate("/login"); } - - const res = await renewAccessToken(refreshToken); - if (res?.data?.access_token && res?.data?.refresh_token) { - login(res?.data?.access_token, res?.data?.refresh_token); - } - try { + const res = await renewAccessToken(refreshToken); + if (res?.data?.access_token && res?.data?.refresh_token) { + login(res?.data?.access_token, res?.data?.refresh_token); + } if (error?.config?.headers) { delete error.config.headers["Authorization"]; error.config.headers["Authorization"] = `Bearer ${cookies.get( @@ -50,6 +48,10 @@ function ApiInterceptor() { if (axios.isAxiosError(error) && error.response?.status === 401) { logout(); navigate("/login"); + } else { + console.error(error); + logout(); + navigate("/login"); } } } diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index ddc8509b7..f66233afd 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -399,7 +399,6 @@ export async function renewAccessToken(token: string) { return await api.post(`${BASE_URL_API}refresh?token=${token}`); } } catch (error) { - console.log("Error:", error); throw error; } }