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] =?UTF-8?q?=F0=9F=90=9B=20fix(validate.py):=20set=20"input?= =?UTF-8?q?=5Fvariables"=20field=20to=20new=20list=20of=20variables=20if?= =?UTF-8?q?=20it=20exists=20=F0=9F=90=9B=20fix(loading.py):=20set=20input?= =?UTF-8?q?=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):