MistralAI

Instrument LLM calls made using MistralAI's SDK via the MistralAIInstrumentor

MistralAI is a leading provider for state-of-the-art LLMs. The MistralAI SDK can be instrumented using the openinference-instrumentation-mistralai package.

Launch Phoenix

Install packages:

pip install arize-phoenix

Launch Phoenix:

import phoenix as px
px.launch_app()

Connect your notebook to Phoenix:

from phoenix.otel import register

tracer_provider = register(
  project_name="my-llm-app", # Default is 'default'
)  

By default, notebook instances do not have persistent storage, so your traces will disappear after the notebook is closed. See Persistence or use one of the other deployment options to retain traces.

Install

pip install openinference-instrumentation-mistralai mistralai

Setup

Set the MISTRAL_API_KEY environment variable to authenticate calls made using the SDK.

export MISTRAL_API_KEY=[your_key_here]

Initialize the MistralAIInstrumentor before your application code.

from openinference.instrumentation.mistralai import MistralAIInstrumentor

MistralAIInstrumentor().instrument(tracer_provider=tracer_provider)

Run Mistral

from mistralai.client import MistralClient
from mistralai.models.chat_completion import ChatMessage

client = MistralClient()
response = client.chat(
    model="mistral-large-latest",
    messages=[
        ChatMessage(
            content="Who won the World Cup in 2018?",
            role="user",
        )
    ],
)
print(response.choices[0].message.content)

Observe

Now that you have tracing setup, all invocations of Mistral (completions, chat completions, embeddings) will be streamed to your running Phoenix for observability and evaluation.

Resources

Last updated