Mistral#
In this notebook we access the Mistral API, a french service that offers free API access with certain limitations.
def prompt_mistral(prompt, model="mistral-medium-2312"):
import os
from mistralai import Mistral
api_key = os.environ["MISTRAL_API_KEY"]
client = Mistral(api_key=api_key)
chat_response = client.chat.complete(
model= model,
messages = [
{
"role": "user",
"content": prompt,
},
]
)
return chat_response.choices[0].message.content
prompt_mistral("What is the best French cheese? Answer in one sentence.")
"It's subjective, but many consider Époisses de Bourgogne, a soft, pungent, and creamy cheese from Burgundy, to be one of the best French cheeses."
We can also ask the API a listing of all available models:
from mistralai import Mistral
import os
s = Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
)
res = s.models.list()
[m.id for m in res.data]
['ministral-3b-2410',
'ministral-3b-latest',
'ministral-8b-2410',
'ministral-8b-latest',
'open-mistral-7b',
'mistral-tiny',
'mistral-tiny-2312',
'open-mistral-nemo',
'open-mistral-nemo-2407',
'mistral-tiny-2407',
'mistral-tiny-latest',
'open-mixtral-8x7b',
'mistral-small',
'mistral-small-2312',
'open-mixtral-8x22b',
'open-mixtral-8x22b-2404',
'mistral-small-2402',
'mistral-small-2409',
'mistral-small-latest',
'mistral-medium-2312',
'mistral-medium',
'mistral-medium-latest',
'mistral-large-2402',
'mistral-large-2407',
'mistral-large-2411',
'mistral-large-latest',
'pixtral-large-2411',
'pixtral-large-latest',
'codestral-2405',
'codestral-latest',
'codestral-mamba-2407',
'open-codestral-mamba',
'codestral-mamba-latest',
'pixtral-12b-2409',
'pixtral-12b',
'pixtral-12b-latest',
'mistral-embed',
'mistral-moderation-2411',
'mistral-moderation-latest']