scrimba
Mistral AI
Function calling - Making the call
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Function calling - Making the call
AboutCommentsNotes
Function calling - Making the call
Expand for more info
index.js
run
preview
console
import MistralClient from '@mistralai/mistralai';
import { tools } from "./tools.js";
const client = new MistralClient(process.env.MISTRAL_API_KEY);

async function agent(query) {
const messages = [
{ role: "user", content: query }
];

const response = await client.chat( {
model: 'mistral-large-latest',
messages: messages,
tools: tools
});

messages.push(response.choices[0].message);

if (response.choices[0].finish_reason === 'tool_calls') {
const functionObject = response.choices[0].message.tool_calls[0].function;
const functionName = functionObject.name;
const functionArgs = JSON.parse(functionObject.arguments);
console.log(functionName);
console.log(functionArgs);
}
}

const response = await agent("when was the transaction T1001 paid?");

//console.log(response);
Console
"getPaymentDate"
,
{transactionId:
"T1001"
}
,
/index.html
-1:46