-
Notifications
You must be signed in to change notification settings - Fork 15.8k
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
core: Allow nested prompt templates #28024
base: master
Are you sure you want to change the base?
core: Allow nested prompt templates #28024
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
} | ||
|
||
# Filter template variables based on | ||
# partial_variables and nested_partial_vars | ||
values["input_variables"] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only point I found a bit counterintuitive. Imo if the user passes input_variables
to the PromptTemplate
we should not overwrite them with values from the template. This complicates the logic as I had to make sure that the nested partial variables are correctly excluded, to not break backward compatibility.
ee87817
to
6905b5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. The changes look largely OK (e.g., non-breaking) but IMO it's unclear that the added complexity here is worth it. This is ultimately somewhat niche functionality and we don't have any documentation of what this buys over doing the formatting yourself, e.g.,
template = "This is a {foo} test."
template_nested = "{bar}"
new_prompt = PromptTemplate(
template=template.format(foo=template_nested)
).partial(bar="bar")
) | ||
prompt_dict["partial_variables"] = {**self.partial_variables, **kwargs} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we losing self.partial_variables
, here?
This PR allows to use nested prompt templates.
partial
now checks if the partial variable is aPromptTemplate
and it will propagate partial variables to itformat
will first format the nested prompts and the root promptIn my application, we allow users to write part of prompts (i.e. specific instructions), which may contain input variables. After this change, it will be possible for us to instantiate those instructions as
PromptTemplate
, and pass them to the main prompts as partial variables.N.B. I know that there is PipelinePromptTemplate that does something similar, but it doesn't support partial prompts as of now, and imo it should not be needed if the
PromptTemplate
itself can handle nested prompts.Thanks for your feedback!
@hwchase17 @baskaryan