Skip to content

Latest commit

 

History

History
116 lines (85 loc) · 2.04 KB

USAGE.md

File metadata and controls

116 lines (85 loc) · 2.04 KB

Create Chat Completions

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();

Upload a file

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();

Create Agents Completions

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();

Create Embedding Request

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();