Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add default template to DynamicPromptBuilder #7652

Closed
wants to merge 3 commits into from

Conversation

tstadel
Copy link
Member

@tstadel tstadel commented May 6, 2024

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 leave PromptBuilder as is
  • B we extend PromptBuilder and deprecate DynamicPromptBuilder

This is Option A
See #7655 for Option B

Proposed Changes:

This extends DynamicPromptBuilder to have a default prompt template that is specified at init time.

default_template = "This is the default prompt: \\n Query: {{query}}"
prompt_builder = DynamicPromptBuilder(runtime_variables=["query"], 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: prompt_source param has been renamed to template for consistency. We can undo that if necessary.
  • Given that PromptBuilder only has a subset of DynamicPromptBuilder's and no additional functionality, I would prefer Option B
  • A Chat counterpart to DynamicPromptBuilder would still need to be implemented

Checklist

@github-actions github-actions bot added topic:tests 2.x Related to Haystack v2.0 type:documentation Improvements on the docs labels May 6, 2024
@coveralls
Copy link
Collaborator

coveralls commented May 6, 2024

Pull Request Test Coverage Report for Build 8968331832

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.002%) to 90.331%

Files with Coverage Reduction New Missed Lines %
components/builders/dynamic_prompt_builder.py 1 97.44%
Totals Coverage Status
Change from base Build 8938725904: -0.002%
Covered Lines: 6521
Relevant Lines: 7219

💛 - Coveralls

@tstadel
Copy link
Member Author

tstadel commented May 7, 2024

We decided to go forward with #7655

@tstadel tstadel closed this May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Related to Haystack v2.0 topic:tests type:documentation Improvements on the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants