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

Add PromptBuilder #5713

Merged
merged 4 commits into from
Sep 5, 2023
Merged

Add PromptBuilder #5713

merged 4 commits into from
Sep 5, 2023

Conversation

silvanocerza
Copy link
Contributor

@silvanocerza silvanocerza commented Sep 4, 2023

Related Issues

Proposed Changes:

Add minimal PromptBuilder implementation to render string templates to prompt strings so they can be passed to Generator Components.

Usage:

from haystack.preview.components.generators.prompt_builder import PromptBuilder

template = "Translate the following context to {{ target_language }}. Context: {{ snippet }}; Translation:"
builder = PromptBuilder(template=template)
res = builder.run(target_language="spanish", snippet="I can't speak spanish.")

assert res["prompt"] == "Translate the following context to spanish. Context: I can't speak spanish.; Translation:"

How did you test it?

Added unit tests.

Notes for the reviewer

I didn't add support for PromptHub as we still have no prompt templates using the new format.
Also it can be easily added in the future and I wanted to keep the PR small.

I already added Jinja2 as a dependency in haystack-ai package.

Checklist

@silvanocerza silvanocerza added the 2.x Related to Haystack v2.0 label Sep 4, 2023
@silvanocerza silvanocerza self-assigned this Sep 4, 2023
@silvanocerza silvanocerza requested review from a team as code owners September 4, 2023 14:13
@silvanocerza silvanocerza requested review from dfokina and ZanSara and removed request for a team September 4, 2023 14:13
Copy link
Contributor

@ZanSara ZanSara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! A couple of nitpicks, then I'll approve

pyproject.toml Show resolved Hide resolved
releasenotes/notes/prompt-builder-d22954ef9c4a2a7b.yaml Outdated Show resolved Hide resolved
Copy link
Contributor

@ZanSara ZanSara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@ZanSara ZanSara merged commit 2acc41e into main Sep 5, 2023
@ZanSara ZanSara deleted the prompt-builder branch September 5, 2023 10:22
@silvanocerza silvanocerza mentioned this pull request Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants