🔧 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) prompt = class_object(**params)
# Now we go through input_variables format_kwargs = {
# Check if they are in params, if so input_variable: params[input_variable]
# get their values and set them for input_variable in prompt.input_variables
format_kwargs = {} if input_variable in params
for input_variable in prompt.input_variables: }
if input_variable in params: # if format_kwargs:
input_value = params[input_variable] # prompt = prompt.partial(**format_kwargs)
format_kwargs[input_variable] = input_value
if format_kwargs:
prompt = prompt.partial(**format_kwargs)
return prompt, format_kwargs return prompt, format_kwargs