Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' of github.com:mistralai/client-js
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed Dec 8, 2023
2 parents fe2763b + c2b66ed commit 2e83fa6
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 81 deletions.
33 changes: 3 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,16 @@
# Mistral Javascript Client

You can use the Mistral Javascript client to interact with the Mistral AI API
You can use the Mistral Javascript client to interact with the Mistral AI API.

## Installing

You can install the library in your project using:

`npm install mistralai`

## Usage

### Chat

The simplest use case is to chat with Mistral AI models:

```javascript
const client = require("mistralai");

const response = client.chat('le-tiny', [{role: 'user', content: 'What is your favourite French food, and why is it mayonnaise?'}])

```

You can also use `client.chatStream` for streaming results.

### Embeddings

To use our embedding API you can use the following code:

```javascript
const client = require('mistralai');

const response = client.embed('le-embed', 'My favourite place to eat mayonnaise is embed');
```

## Run examples

Examples can be found in the `examples/` directory you can run them using:

You can run the examples in the `examples/` directory using
```bash
node [example.js]

node examples/chat_no_streaming.js
```
12 changes: 12 additions & 0 deletions examples/chat_no_streaming.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import MistralClient from '@mistralai/mistralai';

const apiKey = process.env.MISTRAL_API_KEY;

const client = new MistralClient(apiKey);

const chatResponse = await client.chat(
'mistral-tiny',

Check failure on line 8 in examples/chat_no_streaming.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
[{role: 'user', content: 'What is the best French cheese?'}],

Check failure on line 9 in examples/chat_no_streaming.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
);

console.log('Chat:', chatResponse);
14 changes: 14 additions & 0 deletions examples/chat_with_streaming.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import MistralClient from '@mistralai/mistralai';

const apiKey = process.env.MISTRAL_API_KEY;

const client = new MistralClient(apiKey);

const chatStreamResponse = await client.chatStream(
'mistral-tiny',

Check failure on line 8 in examples/chat_with_streaming.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
[{role: 'user', content: 'What is the best French cheese?'}],

Check failure on line 9 in examples/chat_with_streaming.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
);

for await (const chunk of chatStreamResponse) {
console.log('Chat Stream:', '' + chunk);

Check failure on line 13 in examples/chat_with_streaming.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
}
14 changes: 14 additions & 0 deletions examples/embeddings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import MistralClient from '@mistralai/mistralai';

const apiKey = process.env.MISTRAL_API_KEY;

const client = new MistralClient(apiKey);

const input = [];
for (let i = 0; i < 10; i++) {
input.push('What is the best French cheese?');

Check failure on line 9 in examples/embeddings.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
}

const embeddingsBatchResponse = await client.embeddings('mistral-embed', input);

console.log('Embeddings Batch:', embeddingsBatchResponse.data);
51 changes: 0 additions & 51 deletions examples/examples.js

This file was deleted.

11 changes: 11 additions & 0 deletions examples/list_models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import MistralClient from '@mistralai/mistralai';

const apiKey = process.env.MISTRAL_API_KEY;

const client = new MistralClient(apiKey);

const listModelsResponse = await client.listModels();

listModelsResponse.data.forEach((model) => {
console.log('Model:', model);

Check failure on line 10 in examples/list_models.js

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
});

0 comments on commit 2e83fa6

Please sign in to comment.