跳到主要内容

追踪 Mistral

Mistral tracing via autolog

MLflow 追踪确保了您与 Mistral AI 模型交互的可观察性。当通过调用 mlflow.mistral.autolog() 函数启用 Mistral 自动追踪时,Mistral SDK 的使用将在交互式开发过程中自动记录生成的追踪。

请注意,仅支持对文本生成 API 的同步调用,异步 API 和流式方法不受追踪。

示例用法

import os

from mistralai import Mistral

import mlflow

# Turn on auto tracing for Mistral AI by calling mlflow.mistral.autolog()
mlflow.mistral.autolog()

# Configure your API key.
client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])

# Use the chat complete method to create new chat.
chat_response = client.chat.complete(
model="mistral-small-latest",
messages=[
{
"role": "user",
"content": "Who is the best French painter? Answer in one short sentence.",
},
],
)
print(chat_response.choices[0].message)

禁用自动跟踪

可以通过调用 mlflow.mistral.autolog(disable=True)mlflow.autolog(disable=True) 来全局禁用 Mistral 的自动追踪。