scrimba
Mistral AI
Function calling - Unpacking the function and arguments
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 - Unpacking the function and arguments
AboutCommentsNotes
Function calling - Unpacking the function and arguments
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
});

}

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

console.log(response);
Console
{id:
"bf30798c11a54028b91e1431cd9128f5"
, object:
"chat.completion"
, created:
1711038962
, model:
"mistral-large-latest"
, choices:
[
{index:
0
, message:
{role:
"assistant"
, content:
""
, tool_calls:
[
{function:
{name:
"getPaymentDate"
, arguments:
"{"transactionId": "T1001"}"
}
}
]
}
, finish_reason:
"tool_calls"
, logprobs:
null
}
]
, usage:
{prompt_tokens:
154
, total_tokens:
180
, completion_tokens:
26
}
}
,
/index.html
-3:45