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

PromptTemplate prefix and suffix in FewShotPromptTemplate #785

Conversation

g-simmons
Copy link
Contributor

This PR implements #783.

Now when the format method gets called on FewShotPromptTemplate, its prefix and suffix are formatted via their own .format() methods if they are PromptTemplates. 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 are PromptTemplates, they've already been validated with the PromptTemplate.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 :)

@hwchase17 hwchase17 changed the base branch from master to harrison/prompt-template-prefix February 4, 2023 22:37
@hwchase17 hwchase17 merged commit 8e1b15f into langchain-ai:harrison/prompt-template-prefix Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants