🐛 fix(validate.py): set "input_variables" field to new list of variables if it exists

🐛 fix(loading.py): set input variable values if they are present in params
The "input_variables" field in the prompt's frontend_node template is now updated with the new list of variables, if it exists. This ensures that the input variables are correctly set when validating the prompt. In the loading module, the input variable values are now set if they are present in the params dictionary. This ensures that the prompt is correctly instantiated with the provided input variable values.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-28 16:41:40 -03:00
commit a0919cb649
2 changed files with 20 additions and 1 deletions

View file

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

View file

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