From 16fc6bc4a218be0dc808060a07c09eaf2933f3e2 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Wed, 28 Jun 2023 16:38:21 -0300 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20fix(formModal/index.tsx):=20?= =?UTF-8?q?fix=20type=20of=20intermediate=5Fsteps=20property=20to=20be=20a?= =?UTF-8?q?=20string=20instead=20of=20"string"=20to=20prevent=20type=20err?= =?UTF-8?q?or=20=F0=9F=90=9B=20fix(formModal/index.tsx):=20format=20chatIt?= =?UTF-8?q?em.message=20only=20if=20it=20is=20not=20from=20a=20bot=20to=20?= =?UTF-8?q?improve=20readability=20=F0=9F=90=9B=20fix(formModal/index.tsx)?= =?UTF-8?q?:=20remove=20unnecessary=20console.log=20statement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/src/modals/formModal/index.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 365022026..db512ac29 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -155,7 +155,7 @@ export default function FormModal({ let newChatHistory: ChatMessageType[] = []; data.forEach( (chatItem: { - intermediate_steps?: "string"; + intermediate_steps?: string; is_bot: boolean; message: string; type: string; @@ -166,13 +166,13 @@ export default function FormModal({ chatItem.files ? { isSend: !chatItem.is_bot, - message: chatItem.message, + message: chatItem.is_bot ? chatItem.message : formatMessage(chatItem.message), thought: chatItem.intermediate_steps, files: chatItem.files, } : { isSend: !chatItem.is_bot, - message: chatItem.message, + message: chatItem.is_bot ? chatItem.message : formatMessage(chatItem.message), thought: chatItem.intermediate_steps, } ); @@ -370,6 +370,8 @@ export default function FormModal({ setChatKey(index); } } + + console.log(chatHistory) return ( From a0919cb649c123c2384c6ca0256556e5f38ef99d Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 28 Jun 2023 16:41:40 -0300 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20fix(validate.py):=20set=20"i?= =?UTF-8?q?nput=5Fvariables"=20field=20to=20new=20list=20of=20variables=20?= =?UTF-8?q?if=20it=20exists=20=F0=9F=90=9B=20fix(loading.py):=20set=20inpu?= =?UTF-8?q?t=20variable=20values=20if=20they=20are=20present=20in=20params?= =?UTF-8?q?=20The=20"input=5Fvariables"=20field=20in=20the=20prompt's=20fr?= =?UTF-8?q?ontend=5Fnode=20template=20is=20now=20updated=20with=20the=20ne?= =?UTF-8?q?w=20list=20of=20variables,=20if=20it=20exists.=20This=20ensures?= =?UTF-8?q?=20that=20the=20input=20variables=20are=20correctly=20set=20whe?= =?UTF-8?q?n=20validating=20the=20prompt.=20In=20the=20loading=20module,?= =?UTF-8?q?=20the=20input=20variable=20values=20are=20now=20set=20if=20the?= =?UTF-8?q?y=20are=20present=20in=20the=20params=20dictionary.=20This=20en?= =?UTF-8?q?sures=20that=20the=20prompt=20is=20correctly=20instantiated=20w?= =?UTF-8?q?ith=20the=20provided=20input=20variable=20values.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/validate.py | 5 +++++ .../langflow/interface/initialize/loading.py | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/api/v1/validate.py b/src/backend/langflow/api/v1/validate.py index 1223029b8..b5b886816 100644 --- a/src/backend/langflow/api/v1/validate.py +++ b/src/backend/langflow/api/v1/validate.py @@ -61,6 +61,11 @@ def post_validate_prompt(prompt: ValidatePromptRequest): logger.exception(exc) raise HTTPException(status_code=500, detail=str(exc)) from exc + # Now we will set the field "input_variables" to the new list of variables + # if it exists + if "input_variables" in prompt.frontend_node.template: + prompt.frontend_node.template["input_variables"]["value"] = input_variables + return PromptValidationResponse( input_variables=input_variables, frontend_node=prompt.frontend_node, diff --git a/src/backend/langflow/interface/initialize/loading.py b/src/backend/langflow/interface/initialize/loading.py index 235eabaff..bbaa1f131 100644 --- a/src/backend/langflow/interface/initialize/loading.py +++ b/src/backend/langflow/interface/initialize/loading.py @@ -110,7 +110,21 @@ def instantiate_prompt(node_type, class_object, params): if node_type == "ChatPromptTemplate": return class_object.from_messages(**params) - return class_object(**params) + prompt = class_object(**params) + + # Now we go through input_variables + # Check if they are in params, if so + # get their values and set them + format_kwargs = {} + for input_variable in prompt.input_variables: + if input_variable in params: + input_value = params[input_variable] + format_kwargs[input_variable] = input_value + + if format_kwargs: + prompt = prompt.partial(**format_kwargs) + + return prompt def instantiate_tool(node_type, class_object, params): From c9bb88933bdb8a6ee9a01eb7aa3b9fa2c877ff27 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 28 Jun 2023 16:51:02 -0300 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=A7=20chore(chat.py):=20reset=20ch?= =?UTF-8?q?at=20history=20when=20building=20a=20flow=20to=20ensure=20a=20c?= =?UTF-8?q?lean=20state=20The=20chat=20history=20is=20now=20reset=20when?= =?UTF-8?q?=20building=20a=20flow=20to=20ensure=20that=20the=20chat=20star?= =?UTF-8?q?ts=20with=20a=20clean=20state.=20This=20helps=20prevent=20any?= =?UTF-8?q?=20potential=20issues=20or=20conflicts=20that=20may=20arise=20f?= =?UTF-8?q?rom=20previous=20chat=20interactions.?= 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, 2 insertions(+) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 44ea0ca8a..de3c33e01 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -128,6 +128,8 @@ async def stream_build(flow_id: str): yield str(StreamData(event="message", data=input_keys_response)) chat_manager.set_cache(flow_id, langchain_object) + # We need to reset the chat history + chat_manager.chat_history.empty_history(flow_id) except Exception as exc: logger.error("Error while building the flow: %s", exc) yield str(StreamData(event="error", data={"error": str(exc)}))