From 14e0c496a3c2879967ed0bb681a4b7d8bfe8e8e6 Mon Sep 17 00:00:00 2001 From: Evan d'Entremont Date: Thu, 26 Dec 2024 11:32:56 -0500 Subject: [PATCH 1/2] Add Mistral Docs --- .env.sample | 3 +++ guides/README.md | 1 + guides/mistral.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 guides/mistral.md diff --git a/.env.sample b/.env.sample index cc933d9..329683e 100644 --- a/.env.sample +++ b/.env.sample @@ -23,6 +23,9 @@ HF_TOKEN= # Fireworks FIREWORKS_API_KEY= +# Mistral +MISTRAL_API_KEY= + # Together AI TOGETHER_API_KEY= diff --git a/guides/README.md b/guides/README.md index 7c2c062..fb22432 100644 --- a/guides/README.md +++ b/guides/README.md @@ -9,6 +9,7 @@ Here are the instructions for: - [Cohere](cohere.md) - [Google](google.md) - [Hugging Face](huggingface.md) +- [Mistral](mistral.md) - [OpenAI](openai.md) - [SambaNova](sambanova.md) - [xAI](xai.md) diff --git a/guides/mistral.md b/guides/mistral.md new file mode 100644 index 0000000..04cf586 --- /dev/null +++ b/guides/mistral.md @@ -0,0 +1,49 @@ +# Mistral + +To use Mistral with `aisuite`, you’ll need a [Mistral account](https://console.mistral.ai/). + +After logging in, go to [Workspace billing](https://console.mistral.ai/billing) and choose a plan +- **Experiment** *(Free, 1 request per second); or* +- **Scale** *(Pay per use).* + +Visit the [API Keys](https://console.mistral.ai/api-keys/) section in your account settings and generate a new key. Once you have your key, add it to your environment as follows: + +```shell +export MISTRAL="your-openai-api-key" +``` +## Create a Chat Completion + +Install the `mistralai` Python client: + +Example with pip: +```shell +pip install mistralai +``` + +Example with poetry: +```shell +poetry add mistralai +``` + +In your code: +```python +import aisuite as ai +client = ai.Client() + +provider = "mistral" +model_id = "mistral-large-latest" + +messages = [ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": "What’s the weather like in Montréal?"}, +] + +response = client.chat.completions.create( + model=f"{provider}:{model_id}", + messages=messages, +) + +print(response.choices[0].message.content) +``` + +Happy coding! If you’d like to contribute, please read our [Contributing Guide](../CONTRIBUTING.md). From 42d11b28b5e53999291b9ccf19a8029d92a1f9e3 Mon Sep 17 00:00:00 2001 From: Evan d'Entremont Date: Thu, 26 Dec 2024 11:35:53 -0500 Subject: [PATCH 2/2] correct sample api key name --- guides/mistral.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/mistral.md b/guides/mistral.md index 04cf586..2d12503 100644 --- a/guides/mistral.md +++ b/guides/mistral.md @@ -9,7 +9,7 @@ After logging in, go to [Workspace billing](https://console.mistral.ai/billing) Visit the [API Keys](https://console.mistral.ai/api-keys/) section in your account settings and generate a new key. Once you have your key, add it to your environment as follows: ```shell -export MISTRAL="your-openai-api-key" +export MISTRAL="your-mistralai-api-key" ``` ## Create a Chat Completion