Replies: 1 comment
-
🤖 To implement import { PromptTemplate } from "langchain/prompts";
// Your custom question and refine prompts
const questionPromptTemplateString = `Your custom question template here`;
const refinePromptTemplateString = `Your custom refine prompt template here`;
const questionPrompt = new PromptTemplate({
inputVariables: ["context", "question"],
template: questionPromptTemplateString,
});
const refinePrompt = new PromptTemplate({
inputVariables: ["question", "existing_answer", "context"],
template: refinePromptTemplateString,
});
// Create the models and chain
const embeddings = new OpenAIEmbeddings();
const model = new OpenAI({ temperature: 0 });
const chain = loadQARefineChain(model, {
questionPrompt,
refinePrompt,
});
// Load the documents and create the vector store
const loader = new TextLoader("./state_of_the_union.txt");
const docs = await loader.loadAndSplit();
const store = await MemoryVectorStore.fromDocuments(docs, embeddings);
// Select the relevant documents
const question = "Your custom question here";
const relevantDocs = await store.similaritySearch(question);
// Call the chain
const res = await chain.call({
input_documents: relevantDocs,
question,
});
console.log(res); In this example, Please note that the You can find more information about this in the langchainjs codebase, specifically in the examples/src/chains/qa_refine.ts and examples/src/chains/qa_refine_custom_prompt.ts files. I hope this helps! If you have any more 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. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
how can i implement loadQARefineChain with my own question prompt and refine prompt. each prompt have multiple variables i need to pass
Beta Was this translation helpful? Give feedback.
All reactions