From eb08ba5e849c7d5f882d857ff548c9833916add1 Mon Sep 17 00:00:00 2001 From: Theophile Gervet Date: Fri, 8 Dec 2023 11:57:50 +0100 Subject: [PATCH] Split examples, update Readme --- README.md | 33 +++------------------------- examples/examples.js | 51 -------------------------------------------- 2 files changed, 3 insertions(+), 81 deletions(-) delete mode 100644 examples/examples.js diff --git a/README.md b/README.md index 40c269f..0b70b5f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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 @@ -8,36 +8,9 @@ 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] ``` diff --git a/examples/examples.js b/examples/examples.js deleted file mode 100644 index 56f434c..0000000 --- a/examples/examples.js +++ /dev/null @@ -1,51 +0,0 @@ -import MistralClient from '../client.js'; - -const apiKey = process.env.MISTRAL_API_KEY; - -const client = new MistralClient(apiKey); - -// LIST MODELS -const listModelsResponse = await client.listModels(); - -listModelsResponse.data.forEach((model) => { - console.log('Model:', model); -}); - -// CHAT -const chatResponse = await client.chat( - 'le-tiny-v2312', - [{role: 'user', content: 'hello world'}], -); - -console.log('Chat:', chatResponse); - -// CHAT STREAM -const chatStreamResponse = await client.chatStream( - 'le-tiny-v2312', [{role: 'user', content: 'hello world'}], -); - -for await (const chunk of chatStreamResponse) { - console.log('Chat Stream:', '' + chunk); -} - -// chatStreamResponse.data.on('data', (data) => { -// console.log('Chat Stream:', '' + data); -// }); - -// EMBEDDINGS -const embeddingsResponse = await client.embeddings('le-embed', 'hello world'); - -console.log('Embeddings:', embeddingsResponse.data); - - -// EMBEDDINGS BATCH - -// Create 100 strings to embed -const input = []; -for (let i = 0; i < 10; i++) { - input.push('hello world'); -} - -const embeddingsBatchResponse = await client.embeddings('le-embed', input); - -console.log('Embeddings Batch:', embeddingsBatchResponse.data);