https://github.com/madeindjs/mistral-js-tool-calls
Run JS function as Mistral Tools calls
https://github.com/madeindjs/mistral-js-tool-calls
jsdoc llm mistralai
Last synced: 6 months ago
JSON representation
Run JS function as Mistral Tools calls
- Host: GitHub
- URL: https://github.com/madeindjs/mistral-js-tool-calls
- Owner: madeindjs
- Created: 2025-01-31T23:09:41.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2025-01-31T23:28:28.000Z (8 months ago)
- Last Synced: 2025-04-09T01:37:00.433Z (6 months ago)
- Topics: jsdoc, llm, mistralai
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/mistral-js-tool-calls
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Run JS function as Mistral Tools calls
This is a "fun" experiment to turn JavaScript [JSdoc](https://jsdoc.app/) comments as [Function calling](https://docs.mistral.ai/capabilities/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
```sh
npm install mistral-js-tool-calls
```Let's say you have a simple script which exposes two functions:
```js
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
```sh
MISTRAL_API_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
```js
import { Mistral } from "@mistralai/mistralai";
import { runInteractiveChat } from "mistral-js-tool-calls";const client = new Mistral({ apiKey: "" });
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 `./`