haystack
haystack copied to clipboard
feat: add ChatPromptBuilder, deprecate DynamicChatPromptBuilder
Related Issues
- follow up from https://github.com/deepset-ai/haystack/pull/7655 regarding
ChatPromptBuilder
Proposed Changes:
This extends ChatPromptBuilder to change prompts at query time.
default_template = [ChatMessage.from_user("This is the default prompt: \\n Query: {{query}}")]
prompt_builder = ChatPromptBuilder(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": [ChatMessage.from_user("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 are no breaking changes
-
DynamicChatPromptBuilder
is being deprecated
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