From a445b079e08d1d48c43fbc876914ccc84f47608f Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 28 Jun 2023 17:59:57 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20refactor(loading.py):=20simplify?= =?UTF-8?q?=20instantiation=20of=20prompt=20and=20format=5Fkwargs=20assign?= =?UTF-8?q?ment=20=F0=9F=92=A1=20chore(loading.py):=20improve=20code=20rea?= =?UTF-8?q?dability=20and=20maintainability=20by=20simplifying=20the=20ins?= =?UTF-8?q?tantiation=20of=20the=20prompt=20object=20and=20assignment=20of?= =?UTF-8?q?=20format=5Fkwargs=20dictionary.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code has been refactored to use a dictionary comprehension to create the format_kwargs dictionary. This simplifies the logic and improves code readability. The commented out code for the prompt.partial() method has been removed as it is no longer necessary. --- .../langflow/interface/initialize/loading.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/backend/langflow/interface/initialize/loading.py b/src/backend/langflow/interface/initialize/loading.py index 1a075184e..4c24843d4 100644 --- a/src/backend/langflow/interface/initialize/loading.py +++ b/src/backend/langflow/interface/initialize/loading.py @@ -112,17 +112,13 @@ def instantiate_prompt(node_type, 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) + format_kwargs = { + input_variable: params[input_variable] + for input_variable in prompt.input_variables + if input_variable in params + } + # if format_kwargs: + # prompt = prompt.partial(**format_kwargs) return prompt, format_kwargs