PromptTemplate prefix and suffix in FewShotPromptTemplate #785
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements #783.
Now when the format method gets called on
FewShotPromptTemplate
, itsprefix
andsuffix
are formatted via their own.format()
methods if they arePromptTemplate
s. Then the remaining prompt gets formatted as before.https://github.com/g-simmons/langchain/blob/5396f0f46089658a92c04fb26dc4a12c2fdbbcff/langchain/prompts/few_shot.py#L98-L146
I also changed the
FewShotPromptTemplate.template_is_valid()
method to only check validity for prefix and suffix if they are strings. I am assuming that if they arePromptTemplates
, they've already been validated with thePromptTemplate.template_is_valid()
method when they were initialized.https://github.com/g-simmons/langchain/blob/5396f0f46089658a92c04fb26dc4a12c2fdbbcff/langchain/prompts/few_shot.py#L62-L82
I added a simple test for the functionality, just copying the previous test but converting the prefix and suffix to PromptTemplates:
https://github.com/g-simmons/langchain/blob/5396f0f46089658a92c04fb26dc4a12c2fdbbcff/tests/unit_tests/prompts/test_few_shot.py#L90-L117
Let me know what needs fixing :)