haystack icon indicating copy to clipboard operation
haystack copied to clipboard

feat: add ChatPromptBuilder, deprecate DynamicChatPromptBuilder

Open tstadel opened this issue 9 months ago • 1 comments

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

tstadel avatar May 07 '24 16:05 tstadel