Mistral AI
Working with Mistral AI in Pixeltable¶
Pixeltable's Mistral AI integration enables you to access Mistral's LLM and other models via the Mistral AI API.
Prerequisites¶
- A Mistral AI account with an API key (https://console.mistral.ai/api-keys/)
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.
In [ ]:
%pip install -qU pixeltable mistralai
In [ ]:
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.
In [1]:
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`.
Out[1]:
<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 Anthropic.
In [2]:
from pixeltable.functions.mistralai import completions
# Create a table in Pixeltable and pick a model hosted on Anthropic with some parameters
t = pxt.create_table('mistralai_demo.chat', {'input': pxt.StringType()})
messages = [{'role': 'user', 'content': t.input}]
t['output'] = completions(
messages=messages,
model='mistral-small-latest',
# These parameters are optional and can be used to tune model behavior:
max_tokens=300,
top_p=0.9,
temperature=0.7
)
Created table `chat`. Added 0 column values with 0 errors.
In [3]:
# Parse the response into a new column
t['response'] = t.output.choices[0].message.content
Added 0 column values with 0 errors.
In [4]:
# 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.
Out[4]:
input | response |
---|---|
What three species of fish have the highest mercury content? | The three species of fish that typically have the highest mercury content are: 1. King Mackerel 2. Shark 3. Swordfish These fish are often at the top of the food chain and consume other fish that have accumulated mercury in their bodies. As a result, they tend to have higher mercury levels. It's recommended to limit consumption of these fish, especially for pregnant women, nursing mothers, young children, and people who eat fish frequently. |
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.
Updated 15 days ago