0.0.2 • Published 5 months ago
mistral-js-tool-calls v0.0.2
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
./