Skip to main content
Open in Kaggle  Open in Colab  Download Notebook
This documentation page is also available as an interactive notebook. You can launch the notebook in Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the above links.
Pixeltable’s Mistral AI integration enables you to access Mistral’s LLM and other models via the Mistral AI API.

Prerequisites

Important Notes

  • Mistral AI usage may incur costs based on your Mistral AI plan.
  • Be mindful of sensitive data and consider security measures when integrating with external services.
First you’ll need to install required libraries and enter a Mistral AI API key.
%pip install -qU pixeltable mistralai
import os
import getpass

if 'MISTRAL_API_KEY' not in os.environ:
    os.environ['MISTRAL_API_KEY'] = getpass.getpass('Mistral AI API Key:')
Now let’s create a Pixeltable directory to hold the tables for our demo.
import pixeltable as pxt

# Remove the 'mistralai_demo' directory and its contents, if it exists
pxt.drop_dir('mistralai_demo', force=True)
pxt.create_dir('mistralai_demo')
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/asiegel/.pixeltable/pgdata
Created directory `mistralai_demo`.
<pixeltable.catalog.dir.Dir at 0x3381254c0>

Messages

Create a Table: In Pixeltable, create a table with columns to represent your input data and the columns where you want to store the results from Mistral.
from pixeltable.functions.mistralai import chat_completions

# Create a table in Pixeltable and add a computed column that calls Mistral AI

t = pxt.create_table('mistralai_demo.chat', {'input': pxt.String})

messages = [{'role': 'user', 'content': t.input}]
t.add_computed_column(output=chat_completions(
    messages=messages,
    model='mistral-small-latest',
    model_kwargs={
        # Optional dict with parameters for the Mistral API
        'max_tokens': 300,
        'top_p': 0.9,
        'temperature': 0.7
    }
))
Created table `chat`.
Added 0 column values with 0 errors.
# Parse the response into a new column
t.add_computed_column(response=t.output.choices[0].message.content)
Added 0 column values with 0 errors.
# Start a conversation
t.insert([{'input': 'What three species of fish have the highest mercury content?'}])
t.select(t.input, t.response).show()
Computing cells: 100%|████████████████████████████████████████████| 3/3 [00:02<00:00,  1.26 cells/s]
Inserting rows into `chat`: 1 rows [00:00, 134.12 rows/s]
Computing cells: 100%|████████████████████████████████████████████| 3/3 [00:02<00:00,  1.26 cells/s]
Inserted 1 row with 0 errors.

Learn More

To learn more about advanced techniques like RAG operations in Pixeltable, check out the RAG Operations in Pixeltable tutorial. If you have any questions, don’t hesitate to reach out.