🔧 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:
parent
3bd103dbc5
commit
a445b079e0
1 changed files with 7 additions and 11 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue