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

Harrison/prompt template prefix #888

Merged
merged 4 commits into from
Feb 7, 2023
Merged

Conversation

hwchase17
Copy link
Contributor

No description provided.

g-simmons and others added 4 commits February 4, 2023 14:49
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 `PromptTemplate`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 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 :)

---------

Co-authored-by: Harrison Chase <[email protected]>
@hwchase17 hwchase17 merged commit e2b834e into master Feb 7, 2023
@hwchase17 hwchase17 deleted the harrison/prompt-template-prefix branch February 7, 2023 03:09
@blob42 blob42 mentioned this pull request Feb 21, 2023
zachschillaci27 pushed a commit to zachschillaci27/langchain that referenced this pull request Mar 8, 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