JSPM

mistral-js-tool-calls

0.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q26738F
  • License ISC

Run JS function as Mistral Tools calls

Package Exports

  • mistral-js-tool-calls
  • mistral-js-tool-calls/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mistral-js-tool-calls) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Run JS function as Mistral Tools calls

This is a "fun" experiment to turn JavaScript JSdoc comments as Function calling using the Mistral client.

It's really handy to quickly prototype or automatise something like:

  • calling an external API
  • execute a script on the machine
  • etc..

Usage

npm install mistral-js-tool-calls

Let's say you have a simple script which exposes two functions:

import { hostname } from "node:os";
import process from "node:process";

/**
 * @description get the hostname
 * @returns {string} the hostname
 */
export function getHostname() {
  return hostname();
}

/**
 * @description Get the environment variable
 * @param {string} name the name of the variable key
 * @returns {string} the environment variable value
 */
export function getEnvVariable(name) {
  return process.env[name] ?? "not found";
}

[!NOTE] The important part is the JSdoc comments. This library will extract them.

This library allow you to starts an interactive chat using the command

MISTRAL_API_KEY=<your-key> mistral-js-tool-calls ./sample/os.js
>>> what is the environment variable named `HOME` and my hostname ?

The environment variable named `HOME` is `/home/alexandre` and your hostname is `thinkpad-t14`.

Or use it as library

import { Mistral } from "@mistralai/mistralai";
import { runInteractiveChat } from "mistral-js-tool-calls";

const client = new Mistral({ apiKey: "<your-key>" });

const stream = await chatWithToolCall("./your-script.js", client, {
  model: "open-mistral-7b",
  toolChoice: "auto",
  temperature: 0.2,
  messages: [
    {
      role: "user",
      content:
        "what is the environment variable named `HOME` and my hostname ?",
    },
  ],
});
for await (const chunk of stream) process.stdout.write(chunk);

Todos

  • use other providers
  • checks the order of parameters
  • throw if function uses a non-serializable object (function, class, etc...)
  • solve issue with entrypoint from CLI not starting by ./