fix: Change PromptBuilder to have default values for all inputs (#6934)

* Change PromptBuilder to have default values for all inputs

* Add release notes
This commit is contained in:
Silvano Cerza 2024-02-07 16:03:17 +01:00 committed by GitHub
parent 929baf3961
commit b49e86d007
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View File

@ -1,9 +1,8 @@
from typing import Dict, Any from typing import Any, Dict
from jinja2 import Template, meta from jinja2 import Template, meta
from haystack import component from haystack import component, default_to_dict
from haystack import default_to_dict
@component @component
@ -31,7 +30,8 @@ class PromptBuilder:
self.template = Template(template) self.template = Template(template)
ast = self.template.environment.parse(template) ast = self.template.environment.parse(template)
template_variables = meta.find_undeclared_variables(ast) template_variables = meta.find_undeclared_variables(ast)
component.set_input_types(self, **{var: Any for var in template_variables}) for var in template_variables:
component.set_input_type(self, var, Any, "")
def to_dict(self) -> Dict[str, Any]: def to_dict(self) -> Dict[str, Any]:
return default_to_dict(self, template=self._template_string) return default_to_dict(self, template=self._template_string)

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Fix `PromptBuilder` missing input default values.
These missing default value was causing the PromptBuilder to never run if certain inputs are not received.