Skip to content

Commit

Permalink
docs: distinction between mistral v0 and v1
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienbanse committed Sep 13, 2024
1 parent ad585a2 commit 2819842
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 13 deletions.
21 changes: 11 additions & 10 deletions docs/tutorial/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

## List of all providers

| Provider name | Extra for installation | Guide |
|------------------|------------------------|--------------------------------------------------------------------------------------------------|
| Anthropic | `anthropic` | [Guide for Anthropic :octicons-link-16:](providers/anthropic.md) |
| Cohere | `cohere` | [Guide for Cohere :octicons-link-16:](providers/cohere.md) |
| Google Gemini | `google-generativeai` | [Guide for Google Gemini :octicons-link-16:](providers/google.md) |
| Hugging Face Hub | `huggingface-hub` | [Guide for Hugging Face Hub :octicons-link-16:](providers/huggingface_hub.md) |
| LiteLLM | `litellm` | [Guide for LiteLLM :octicons-link-16:](providers/litellm.md) |
| Mistral AI | `mistralai` | [Guide for Mistral AI :octicons-link-16:](providers/mistralai.md) |
| OpenAI | `openai` | [Guide for OpenAI :octicons-link-16:](providers/openai.md) |
| Azure OpenAI | `openai` | [Guide for Azure OpenAI :octicons-link-16:](providers/openai.md#compatibility-with-azure-openai) |
| Provider name | Extra for installation | Guide |
|---------------------|------------------------|--------------------------------------------------------------------------------------------------|
| Anthropic | `anthropic` | [Guide for Anthropic :octicons-link-16:](providers/anthropic.md) |
| Cohere | `cohere` | [Guide for Cohere :octicons-link-16:](providers/cohere.md) |
| Google Gemini | `google-generativeai` | [Guide for Google Gemini :octicons-link-16:](providers/google.md) |
| Hugging Face Hub | `huggingface-hub` | [Guide for Hugging Face Hub :octicons-link-16:](providers/huggingface_hub.md) |
| LiteLLM | `litellm` | [Guide for LiteLLM :octicons-link-16:](providers/litellm.md) |
| Mistral AI `>1.0.0` | `mistralai` | [Guide for Mistral AI v0 (soon deprecated) :octicons-link-16:](providers/mistralai_v0.md) |
| Mistral AI `<=1.0.0`| `mistralai` | [Guide for Mistral AI v1 :octicons-link-16:](providers/mistralai_v1.md) |
| OpenAI | `openai` | [Guide for OpenAI :octicons-link-16:](providers/openai.md) |
| Azure OpenAI | `openai` | [Guide for Azure OpenAI :octicons-link-16:](providers/openai.md#compatibility-with-azure-openai) |


## Chat Completions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Mistral AI
# Mistral AI v0

This guide focuses on the integration of :seedling: **EcoLogits** with the [Mistral AI official python client :octicons-link-external-16:](https://github.com/mistralai/client-python).
This guide focuses on the integration of :seedling: **EcoLogits** with the [Mistral AI official python client :octicons-link-external-16:](https://github.com/mistralai/client-python) for versions `<1.0.0`.

!!! warning "Mistral AI v0 will soon be deprecated"

Mistral AI client with version `<1.0.0` will soon no longer be supported by :seedling: **EcoLogits**. See [this page](https://github.com/mistralai/client-python/blob/main/MIGRATION.md) for a migration guide from v0 to v1.

Official links:

Expand Down
131 changes: 131 additions & 0 deletions docs/tutorial/providers/mistralai_v1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Mistral AI v1

This guide focuses on the integration of :seedling: **EcoLogits** with the [Mistral AI official python client :octicons-link-external-16:](https://github.com/mistralai/client-python) for versions `>=1.0.0`.

Official links:

* Repository: [:simple-github: mistralai/client-python](https://github.com/mistralai/client-python)
* Documentation: [:material-file-document: docs.mistral.ai](https://docs.mistral.ai/getting-started/clients/)


## Installation

To install EcoLogits along with all necessary dependencies for compatibility with the Mistral AI client, please use the `mistralai` extra-dependency option as follows:

```shell
pip install ecologits[mistralai]
```

This installation command ensures that EcoLogits is set up with the specific libraries required to interface seamlessly with Mistral AI's Python client.


## Chat Completions

### Example

Integrating EcoLogits with your applications does not alter the standard outputs from the API responses. Instead, it enriches them by adding the `Impacts` object, which contains detailed environmental impact data.

=== "Sync"

```python
from ecologits import EcoLogits
from mistralai import Mistral

# Initialize EcoLogits
EcoLogits.init()

client = Mistral(api_key="<MISTRAL_API_KEY>")

response = client.chat.complete(
messages=[
{"role": "user", "content": "Tell me a funny joke!"}
],
model="mistral-tiny"
)

# Get estimated environmental impacts of the inference
print(response.impacts)
```

=== "Async"

```python
import asyncio
from ecologits import EcoLogits
from mistralai import Mistral

# Initialize EcoLogits
EcoLogits.init()

client = Mistral(api_key="<MISTRAL_API_KEY>")

async def main() -> None:
response = await client.chat.complete_async(
messages=[
{"role": "user", "content": "Tell me a funny joke!"}
],
model="mistral-tiny"
)
# Get estimated environmental impacts of the inference
print(response.impacts)


asyncio.run(main())
```

### Streaming example

**In streaming mode, the impacts are calculated incrementally**, which means you don't need to sum the impacts from each data chunk. Instead, the impact information in the last chunk reflects the total cumulative environmental impacts for the entire request.

=== "Sync"

```python
from ecologits import EcoLogits
from mistralai import Mistral

# Initialize EcoLogits
EcoLogits.init()

client = Mistral(api_key="<MISTRAL_API_KEY>")

stream = client.chat.stream(
messages=[
{"role": "user", "content": "Tell me a funny joke!"}
],
model="mistral-tiny"
)

for chunk in stream:
# Get cumulative estimated environmental impacts of the inference
print(chunk.data.impacts)
```

=== "Async"

```python
import asyncio
from ecologits import EcoLogits
from mistralai import Mistral

# Initialize EcoLogits
EcoLogits.init()

client = Mistral(api_key="<MISTRAL_API_KEY>")

async def main() -> None:
response = await client.chat.stream_async(
messages=[
{"role": "user", "content": "Tell me a funny joke!"}
],
model="mistral-tiny"
)

async for chunk in stream:
# Get cumulative estimated environmental impacts of the inference
if hasattr(chunk, "impacts"):
print(chunk.data.impacts)


asyncio.run(main())
```
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ nav:
- 'Google Gemini': tutorial/providers/google.md
- 'Hugging Face Hub': tutorial/providers/huggingface_hub.md
- 'LiteLLM': tutorial/providers/litellm.md
- 'Mistral AI': tutorial/providers/mistralai.md
- 'Mistral AI v0 (soon deprecated)': tutorial/providers/mistralai_v0.md
- 'Mistral AI v1': tutorial/providers/mistralai_v1.md
- 'OpenAI': tutorial/providers/openai.md
- 'Methodology':
- 'Introduction': methodology/index.md
Expand Down

0 comments on commit 2819842

Please sign in to comment.