scrimba
Mistral AI
Function calling - Adding a second function
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 - Adding a second function
AboutCommentsNotes
Function calling - Adding a second function
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
});

return response;
}

// Challenge:
// Change the prompt so that the LLM tells us to call the new function
const response = await agent("Is the transaction T1001 paid?");

console.log(response);
Console
{id:
"13aa01b6afac4002bbf743db72d3637a"
, object:
"chat.completion"
, created:
1711037696
, model:
"mistral-large-latest"
, choices:
[
{index:
0
, message:
{role:
"assistant"
, content:
""
, tool_calls:
[
{function:
{name:
"getPaymentStatus"
, arguments:
"{"transactionId": "T1001"}"
}
}
]
}
, finish_reason:
"tool_calls"
, logprobs:
null
}
]
, usage:
{prompt_tokens:
84
, total_tokens:
110
, completion_tokens:
26
}
}
,
/index.html
-2:22