langchain-ai / langchainjs

🦜🔗 Build context-aware reasoning applications 🦜🔗
https://js.langchain.com/docs/
MIT License
12.41k stars 2.1k forks source link

FewShotChatMessagePromptTemplate won't bring prefix and suffix into chain #3851

Closed casyalex closed 2 months ago

casyalex commented 9 months ago

https://github.com/langchain-ai/langchainjs/blob/61f35dc569e56aef4df58a15f94e5d75b3a49137/langchain-core/src/prompts/few_shot.ts#L429

even though format method can print suffix and prefix.

But it won't take effect into a chat model.

dosubot[bot] commented 9 months ago

🤖

Hello @casyalex! 👋 I'm Dosu, a friendly bot that's here to assist you with any bugs, answer your questions, and streamline your journey to becoming a contributor. While you're waiting for a human maintainer, I'm here to help out. Let's get this issue sorted out together!🚀

The issue you're experiencing with the FewShotChatMessagePromptTemplate not bringing prefix and suffix into the chain is due to the way the formatMessages method is implemented in the BaseMessagePromptTemplate class, which FewShotChatMessagePromptTemplate extends.

The formatMessages method is an abstract method that is expected to be overridden in subclasses. It's responsible for formatting the messages, but it doesn't have any parameters or logic to handle prefix and suffix. Therefore, even if the format method can print suffix and prefix, they are not included in the chain because the formatMessages method does not handle them.

Here's the definition of the formatMessages method:

abstract formatMessages(
  values: TypedPromptInputValues<RunInput>
): Promise<RunOutput>;

To include prefix and suffix in the chain, you would need to modify the formatMessages method to handle them, or implement a new method that includes them.

For more details, you can refer to the langchain-core/src/prompts/chat.ts file in the repository.

I hope this clarifies the issue. If you have any further questions, feel free to ask.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

medic-code commented 9 months ago

@casyalex do you have a minimal reproducible example to illustrate this ?

dosubot[bot] commented 6 months ago

Hi, @casyalex,

I'm helping the langchainjs team manage their backlog and am marking this issue as stale. From what I understand, the issue was raised regarding the FewShotChatMessagePromptTemplate not properly handling suffix and prefix in a chat model. Dosu-bot provided an explanation that the issue stems from the formatMessages method not handling prefix and suffix, and suggested modifying the method or implementing a new one to include them. Medic-code requested a minimal reproducible example from you to further investigate the issue.

Could you please confirm if this issue is still relevant to the latest version of the langchainjs repository? If it is, please let the langchainjs team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!

casyalex commented 6 months ago

Yes, it still exist