-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
from pydantic import BaseModel, model_validator | ||
|
||
from langchain_core.prompts import BasePromptTemplate | ||
from langchain_core.prompts.string import ( | ||
DEFAULT_FORMATTER_MAPPING, | ||
PromptTemplateFormat, | ||
|
@@ -104,12 +105,24 @@ def pre_init_validation(cls, values: dict) -> Any: | |
) | ||
|
||
if values["template_format"]: | ||
# Collect nested partial variables from | ||
# BasePromptTemplate instances in partial_variables | ||
nested_partial_vars = { | ||
key | ||
for partial_var in values["partial_variables"].values() | ||
if isinstance(partial_var, BasePromptTemplate) | ||
for key in partial_var.partial_variables | ||
} | ||
|
||
# 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 commentThe 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 |
||
var | ||
for var in get_template_variables( | ||
values["template"], values["template_format"] | ||
) | ||
if var not in values["partial_variables"] | ||
and var not in nested_partial_vars | ||
] | ||
|
||
return values | ||
|
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?