haystack
haystack copied to clipboard
feat: extend PromptBuilder and deprecate DynamicPromptBuilder
Related Issues
Currently we cannot have both:
- a default prompt template defined (PromptBuilder)
- dynamically change prompt templates at runtime (DynamicPromptBuilder)
There are two options:
-
A we extend
DynamicPromptBuilder
and leavePromptBuilder
as is -
B we extend
PromptBuilder
and deprecateDynamicPromptBuilder
Edit 07.05.: We decided to go with B
This is Option B See https://github.com/deepset-ai/haystack/pull/7652 for Option A
Proposed Changes:
This extends PromptBuilder to change prompts at query time.
default_template = "This is the default prompt: \\n Query: {{query}}"
prompt_builder = PromptBuilder(template=default_template)
pipe = Pipeline()
pipe.add_component("prompt_builder", prompt_builder)
# using the default prompt
result = pipe.run(
data={
"prompt_builder": {
"query": "Where does the speaker live?",
},
}
)
# "This is the default prompt: \n Query: Where does the speaker live?"
# using the dynamic prompt
result = pipe.run(
data={
"prompt_builder": {
"template": "This is the dynamic prompt:\\n Query: {{query}}",
"query": "Where does the speaker live?",
},
}
)
# "This is the dynamic prompt: \n Query: Where does the speaker live?"
How did you test it?
- added tests
Notes for the reviewer
- ~~There is a breaking change:
required_variables
param has been changed tooptional_variables
as most variables of templates are required anyways. We can undo that if necessary.~~ -
DynamicPromptBuilder
is being deprecated - The
Chat
counterpart toPromptBuilder
is implemented in https://github.com/deepset-ai/haystack/pull/7663
Checklist
- I have read the contributors guidelines and the code of conduct
- I have updated the related issue with new insights and changes
- I added unit tests and updated the docstrings
- I've used one of the conventional commit types for my PR title:
fix:
,feat:
,build:
,chore:
,ci:
,docs:
,style:
,refactor:
,perf:
,test:
. - I documented my code
- I ran pre-commit hooks and fixed any issue