Replies: 1 comment
-
Based on your requirements, it seems like you're on the right track. You can indeed modify the function formatDocuments({ documents, documentPrompt, documentSeparator, config }) {
// Check if there are more than 6 documents
if (documents.length > 6) {
// Replace the 6th document with a message informing the user
documents[5] = "There are more items available. Please make a more specific request to see additional items.";
}
// Proceed with the original formatting logic
return documents.map(doc => formatSingleDocument(doc, documentPrompt)).join(documentSeparator);
} In this modification, we're checking if there are more than 6 documents. If there are, we replace the 6th document with a message informing the user that there are more items available and that they should make a more specific request to see the additional items. The rest of the documents are formatted as before. As for the Please note, the actual implementation details might vary based on the rest of your codebase and how Regarding your consideration of not chaining the retriever and making a manual call aside, it's hard to provide a concrete suggestion without more details about your implementation. However, the I hope this helps! If you have further questions or need more clarification, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
With the assistant, when users ask for listing a few things it will always returns
<= 5
items in the context, and so in the streamed answer when the assistant displays them as a list.I would like my assistant to tell the user there is more available, and that by precising its request the user will see other items. My first idea was:
asRetriever(5)
, to doasRetriever(6)
there is more items in the database, tell the user to precise the request to see others
Unfortunately by looking at the code
langchainjs/langchain/src/chains/combine_documents/stuff.ts
Line 31 in 0ea9f92
langchainjs/langchain/src/chains/combine_documents/base.ts
Line 15 in 0ea9f92
createStuffDocumentsChain()
to have a customformatDocuments()
function.Do you see another proper way to do so? Maybe I'm thinking this problem the wrong way?
I also tought about not chaining the retriever and doing manual call aside, but if doing the embeddings at first, passing them to the retriever is possible, but I'm unaware to pass those embeddings as the
input
in the.stream()
function (input of a raw text input).Any help appreciated, thank you,
cc @nfcampos @jacoblee93
System Info
EDIT: I ended duplicating and modifying https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/chains/combine_documents/stuff.ts and https://github.com/langchain-ai/langchainjs/blob/main/langchain/src/chains/combine_documents/base.ts to make the modification of the formatter. I tried at first to replace my whole logic of using langchain helpers by using a raw
RunnableSequence.from([...])
as in the example but I was having typings issue due to chat history... so just took the facility of duplicating 👍Beta Was this translation helpful? Give feedback.
All reactions