Langchain JS MapReduce - how to override default combine_prompt with custom prompt template #3371
-
Hi all! I've implemented a simple Mapreduce in javascript, Node, and it seems to be working fine. I used the documentation here: I've done a lot of searching, but am unable to override the combine_prompt that is defined in dist/chains/question_answering/map_reduce_prompts.js. I know how to create a custom prompt template. So given the following code, where do I pass my custom prompt template?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
🤖 Hello @poetsmeniet! Good to see you again. Hope you're doing well with your project. To override the default Here's an example of how you can do this: import { PromptTemplate } from "langchain/prompts";
// Define your custom prompt
const customPrompt = PromptTemplate.fromTemplate(`Your custom template {variable}`);
// Load the QA MapReduce chain with your custom prompt
const chain = loadQAMapReduceChain(model, { combinePrompt: customPrompt });
// Your existing code...
const docs = [
new Document({ pageContent: "harrison went to harvard" }),
new Document({ pageContent: "ankush went to princeton" }),
];
const res = await chain.call({
input_documents: docs,
question: "Where did harrison go to college",
});
console.log({ res }); In this example, This is based on the structure of the For more information, you can refer to the source code of the I hope this helps! Let me know if you have any other questions. 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. |
Beta Was this translation helpful? Give feedback.
🤖
Hello @poetsmeniet! Good to see you again. Hope you're doing well with your project.
To override the default
combine_prompt
with a custom prompt template in LangChain JS MapReduce, you can pass your custom prompt template as a parameter when calling theloadQAMapReduceChain
function.Here's an example of how you can do this: