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

PromptBuilder #5622

Closed
Tracked by #5330
ZanSara opened this issue Aug 25, 2023 · 1 comment
Closed
Tracked by #5330

PromptBuilder #5622

ZanSara opened this issue Aug 25, 2023 · 1 comment
Assignees
Labels
2.x Related to Haystack v2.0
Milestone

Comments

@ZanSara
Copy link
Contributor

ZanSara commented Aug 25, 2023

See the LLM proposal: #5540


The goal of PromptBuilder is to transform prompt templates, which are strings with variables, specifically Jinja templates, and fill up those variables with values that come from other components in the pipeline or from the pipeline inputs. The output of this component is one (or more) prompts, where prompts means strings that the LLM can directly use.

PromptBuilder is not tokenizer aware: the prompt will be checked for length by the LLM component before inference. If the need arise, we may later extend the component.

Draft I/O for PromptBuilder:

@component
class PromptBuilder:

    def __init__(self, template: Union[str, Path]):
        self.template = # Download the template
        template_variables = # extracts the variables from the template text
		component.set_input_parameters(**{var: Any for var in template_variables})

  	@component.output_types(prompts=List[str])
    def run(self, **kwargs):
        # Render the template using the variables
        return {"prompts": prompts}

Due to the dynamic nature of prompt templates, the PromptBuilder.run() method takes **kwargs, which contains all the variables that will be filled in the template. However, for this component to work with Canals, we need to know in advance which values this dict will contain: therefore, we need the users to specify in the __init__ of the component the template to use.

Such template names cannot be changed at runtime.

@ZanSara ZanSara added the 2.x Related to Haystack v2.0 label Aug 25, 2023
@silvanocerza
Copy link
Contributor

Closed by #5713

@Timoeller Timoeller added this to the 2.0-beta milestone Oct 9, 2023
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
Projects
None yet
Development

No branches or pull requests

4 participants
@Timoeller @silvanocerza @ZanSara and others