🔧 refactor(loading.py): simplify instantiation of prompt and format_kwargs assignment

💡 chore(loading.py): improve code readability and maintainability by simplifying the instantiation of the prompt object and assignment of format_kwargs dictionary.

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.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-28 17:59:57 -03:00
commit a445b079e0

View file

@ -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