In addition to the lunary.wrapAgent & lunary.wrapTool methods, we provide a wrapModel method.It allows to wrap any async function. It also takes the following options:
Copy
const wrapped = lunary.wrapModel(yourLlmModel, { nameParser: (args) => 'custom-model-1.3', // name of the model used inputParser: (args) => { // parse the input to message format return [{ role: 'system', text: args.systemPrompt }, { role: 'user', text: args.userPrompt }] }, extraParser: (args) => { // Report any extre properties like temperature return { temperature: args.temperature, } }, outputParser: (result) => { // Parse the result return { role: 'ai', text: result.content, } }, tokensUsageParser: async (result) => { // Return the number of tokens used return { completion: 10 prompt: 10 } },})