-
Notifications
You must be signed in to change notification settings - Fork 16.2k
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
prefix and suffix as PromptTemplates in FewShotPromptTemplate #783
Comments
I'm new to LangChain, so not sure, but I imagine that this pattern might occur elsewhere... I will probably try to modify FewShotPromptTemplate to support this, and I would be happy to submit a PR if I can get some advice on where else similar changes might be necessary. |
i like this a lot! will try to get this in tmrw! |
@hwchase17 thank you - let me know if I can help, happy to add tests etc. to the PR. |
i lied about the speed of getting this in :( will try hard to get it in this weekend, sorry for delay! i may end up modifying it to be a separate class for modularity |
@hwchase17 no problem :) No rush on my end, I can use my forked version for the time being. Are you thinking like a mixin for templated suffix and prefix? |
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]>
Hi, @g-simmons! I'm Dosu, and I'm here to help the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale. From what I understand, the issue is about implementing conditional logic for the prefix and suffix arguments in Before we proceed, we would like to confirm if this issue is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days. Thank you for your understanding and contribution to the LangChain project! |
Hi there!
I am wondering if it's possible to use PromptTemplates as values for the
prefix
andsuffix
arguments ofFewShotPromptTemplate
.Here's an example of what I would like to do. The following works as-is, but I would like it to work the same with the commented lines uncommented.
I would like this functionality because I have conditional logic for the prefix and suffix that would be more conveniently implemented with a PromptTemplate class rather than relying on f-string formatting.
The text was updated successfully, but these errors were encountered: