This example shows how to create chat completions.
import { Mistral } from "@mistralai/mistralai";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.chat.complete({
model: "mistral-small-latest",
messages: [
{
content:
"Who is the best French painter? Answer in one short sentence.",
role: "user",
},
],
});
// Handle the result
console.log(result);
}
run();
This example shows how to upload a file.
import { Mistral } from "@mistralai/mistralai";
import { openAsBlob } from "node:fs";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.files.upload({
file: await openAsBlob("example.file"),
});
// Handle the result
console.log(result);
}
run();
This example shows how to create agents completions.
import { Mistral } from "@mistralai/mistralai";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.agents.complete({
messages: [
{
content:
"Who is the best French painter? Answer in one short sentence.",
role: "user",
},
],
agentId: "<value>",
});
// Handle the result
console.log(result);
}
run();
This example shows how to create embedding request.
import { Mistral } from "@mistralai/mistralai";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.embeddings.create({
inputs: [
"Embed this sentence.",
"As well as this one.",
],
model: "Wrangler",
});
// Handle the result
console.log(result);
}
run();