追踪 Mistral
MLflow Tracing 可确保您与 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 的自动追踪。