How to send question and get all relevant answer in json #6986
Unanswered
lakshya29154
asked this question in
Q&A
Replies: 1 comment 3 replies
-
To send multiple questions at once and receive accurate answers in JSON format using LangChain and OpenAI, you can modify your script to process multiple inputs simultaneously. Here's a streamlined approach:
Here's an example of how you can achieve this: import { ChatOpenAI } from "@langchain/openai";
import { PromptTemplate } from "@langchain/core/prompts";
async function processQuestions(questions: string[]): Promise<any> {
const model = new ChatOpenAI({ apiKey: process.env.OPENAI_API_KEY });
const promptTemplate = new PromptTemplate({
inputVariables: ["questions", "context"],
template: `
You are an expert JSON formatter. For each question, use the context provided to populate the appropriate values in the JSON format.
Questions: {questions}
Context: {context}
Please generate the output in the following JSON format:
[
{
"fund_size": "string",
"fund_manager": "string",
"fund_life_rate": "string",
"management_fee": "string",
"investment_period": "string",
"minimum_commitment": "string",
"maximum_commitment": "string",
"fixed_interest_rate": "string",
"general_partner_catch_up": "string"
}
]
`,
});
const inputs = questions.map((question) => ({ questions: question, context: "Your context here" }));
const results = await model.batch(inputs);
return JSON.stringify(
results.map((result, index) => ({
question: questions[index],
answer: result.content,
}))
);
}
// Example usage
const questions = [
"What would be the minimum and maximum commitments?",
"Who would be the fund manager?",
"What would be the life of fund?",
"What would be the management fees?",
"What would be the investment period extension?",
"What would be the minimum commitment?",
"What would be the maximum commitment?",
"What is the preferred fixed interest rate return?",
"What is the General Partner CatchUp?"
];
processQuestions(questions).then((jsonResults) => {
console.log(jsonResults);
}); Key Points:
This approach should help you get accurate answers in JSON format for multiple questions [1]. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Checked other resources
Commit to Help
Example Code
Description
I want to make a script where I can send multiple question at once and I get answer in json format . I tried this but when i earlies send single question it give me correct answer now If i send all question it doesnt get me correct answer might need to go with different approach or anything can you help so i get accurate answer and in json format
System Info
node verson - 20
paltform - windows
Beta Was this translation helpful? Give feedback.
All reactions