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)})) 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): 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 (