How can I replicate the load_qa_with_sources_chain() from the python library in the javascript library? #4037
Replies: 2 comments 2 replies
-
🤖 Hello @Simbaclaws, Nice to meet you! I'm Dosu, a bot designed to assist with issues and questions regarding the langchainjs repository, as well as help guide contributors. While we're waiting for a human maintainer to respond, feel free to ask me any questions you may have. I'll do my best to help you. Based on the context you've provided, it seems like you're trying to replicate the functionality of In the current setup, the To ensure that all source documents are included in the model's context, you could modify the function formatDocumentsAsString(documents) {
return documents.map(doc => doc.content).join('\n');
} This will create a single string that includes the content of all source documents, separated by newline characters. As for including the source URLs in the model's response, you could modify the final step of the chain to append the source URLs to the model's output. Here's an example: {
result: prompt.pipe(model).pipe(new StringOutputParser()),
sourceDocuments: (previousStepResult) => previousStepResult.sourceDocuments,
finalResult: (previousStepResult) => {
let result = previousStepResult.result;
let sources = previousStepResult.sourceDocuments.map(doc => doc.url).join(', ');
return `${result}\nSource(s): ${sources}`;
},
} This will append a line to the model's output that includes the source URLs of all source documents. I hope this helps! If you have any further questions or if something is not clear, please let me know. SourcesThis 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. |
Beta Was this translation helpful? Give feedback.
-
I fixed my source code already, thanks for giving feedback bot :) |
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.
-
Hi there,
For my web application I'm trying to use faiss with source documents that have url's to a web page. These url's should be mentioned as source inside the answer of what my gpt is going to give me back. My gpt should search all of the documents that it can find in a chain, and create an answer based on all of the provided documents from a single or sometimes multiple sources.
I haven't seen any load_qa_with_sources_chain equivalents of the python library that does just that.
So I found some code somewhere (can't remember where, sorry for the original author) that should replicate this functionality the way I want it to:
However, currently my gpt is responding with just the last sourceDocument in the sourceDocuments array. As well as not return any of the sources in the answer it should generate....
Does anyone know what I am doing wrong in order to get my gpt to respond based on all of the sourceDocuments in the chain, as well as with the correct source url's?
Please help me solve this last issue I'm having.
Beta Was this translation helpful? Give feedback.
All reactions