-
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
core: Add aformat_messages to FewShotChatMessagePromptTemplate and ChatPromptTemplate #19648
core: Add aformat_messages to FewShotChatMessagePromptTemplate and ChatPromptTemplate #19648
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
@@ -901,19 +929,31 @@ def from_messages( | |||
partial_variables=partial_vars, | |||
) | |||
|
|||
def format(self, **kwargs: Any) -> str: |
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.
Removed format
from ChatPromptTemplate
as it is identical to the one in the parent class BaseChatPromptTemplate
1073750
to
8ae8e21
Compare
8ae8e21
to
c9ee89f
Compare
Returns: | ||
List of BaseMessages. | ||
""" | ||
return await run_in_executor(None, self.format_messages, **kwargs) |
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.
This is another place where I feel like we need to delegate to the sync implementation.
I'm a bit worried about having this dichotomy / how to make it obvious that this is is what's going on
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.
cc @baskaryan / @nfcampos
Do we keep run_in_executor for consistency or use a blocking call to the sync code?
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.
Another PR where this question comes up: https://github.com/langchain-ai/langchain/pull/19652/files
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.
This is the part that makes it all weird:
message = message_template.format_messages(**kwargs) |
Chat prompt templates are constructed of multiple messages each of which can be formatted independently -- this
would mean that interpolating a few variables into essentially a list of dicts we're launching several threads
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.
Another possibility if we don't want to choose now is to raise NotImplementedError in the default interface.
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.
I intend to implement all subclasses in the end so the default interface won't be called anyway.
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.
a list of dicts we're launching several threads
Actually, it's not launching several threads, it's submitting tasks to the default thread-pool (which has 1 thread per core).
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.
Anyway, I updated the PR to call the sync method directly. PTAL
… and ChatPromptTemplate (langchain-ai#19648) Needed since the example selector may use a vector store.
… and ChatPromptTemplate (#19648) Needed since the example selector may use a vector store.
Needed since the example selector may use a vector store.