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

core: Allow nested prompt templates #28024

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dmenini
Copy link
Contributor

@dmenini dmenini commented Nov 11, 2024

This PR allows to use nested prompt templates.

  • partial now checks if the partial variable is a PromptTemplate and it will propagate partial variables to it
  • format will first format the nested prompts and the root prompt

In 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

Copy link

vercel bot commented Nov 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Nov 11, 2024 3:07pm

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 11, 2024
}

# Filter template variables based on
# partial_variables and nested_partial_vars
values["input_variables"] = [
Copy link
Contributor Author

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.

@dmenini dmenini force-pushed the core/inject-partial-to-partial-variables branch from ee87817 to 6905b5d Compare November 11, 2024 15:06
@efriis efriis requested a review from baskaryan December 4, 2024 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

2 participants