Reputation: 1
Idea: To get the JSON response of some type using lanchain js, and also i want to get metadata details like usage and all.
async generateQuestionsForSummary(jobTitle: string, type: string): Promise<GenAIQuestionsDto> {
const prompt = new PromptTemplate({
template: `<<TEMPLATE>>`,
inputVariables: ["type"],
});
const formattedPrompt = await prompt.format({
type,
});
console.log("Formatted Prompt:", formattedPrompt);
// Set up a parser + inject instructions into the prompt template.
const parser = new LoggingJsonOutputParser<ResponseModel>();
const chain = prompt.pipe(this.gemini).pipe(parser);
const response = await chain.invoke({ type, jobTitle });
return response;
}
I tried to log the input, but in this also I don't have metadata details, getting just the JSON string.
class LoggingJsonOutputParser<T> extends JsonOutputParser<T> {
async parse(response: string): Promise<T> {
console.log("Unstructured Response:", response); // Log the unstructured response
return super.parse(response); // Call the original parse method
}
}
I am getting the JSON response successfully but I am unable to get the usage and metadata details.
Upvotes: 0
Views: 44