const messages = [
{
role: "system",
content: "You are a math tutor that handles math exercises and makes output in json in format { result: number }.",
},
{ role: "user", content: "2 + 2 * 2" },
];
const aiInvokeMsg = await llm.invoke(messages, { response_format: { type: "json_object" } });
// if you want not to pass response_format in every invoke, you can bind it to the instance
const llmWithResponseFormat = llm.bind({ response_format: { type: "json_object" } });
const aiBindMsg = await llmWithResponseFormat.invoke(messages);
// they are the same
console.log({ aiInvokeMsgContent: aiInvokeMsg.content, aiBindMsg: aiBindMsg.content });