MLflow로 Mistral AI 관찰 가능성(Observability) 확보하기

MLflow로 Mistral AI 관찰 가능성(Observability) 확보하기

MLflow의 자동 추적(auto tracing) 기능을 Mistral AI에 적용하는 예제예요. mlflow.mistral.autolog() 한 줄만으로 API 호출 파라미터와 결과를 자동으로 기록할 수 있어요. 별도 계측 코드 없이도 어떤 요청이 어떻게 처리됐는지 MLflow UI에서 바로 확인할 수 있습니다.

출처: 문서

본문

Mistral AI 호출을 MLflow의 자동 추적 기능으로 관찰하는 예제입니다. MLflow Tracing에 대한 더 자세한 내용은 MLflow 공식 문서를 참고하면 돼요.

준비하기 (Getting Started)

mistralai와 mlflow를 설치합니다 (2025년 2월 4일 기준 최신 버전).

!pip install mistralai==1.5.0
!pip install mlflow==2.20.1

코드 (Code)

mlflow.mistral.autolog()를 호출하면 Mistral AI 호출이 자동으로 추적됩니다. API 키를 설정하고 chat.complete로 대화를 생성해 볼게요.

import os

from mistralai.client 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)

추적 (Tracing)

MLflow 추적 결과를 보려면 이 노트북을 실행한 디렉터리와 동일한 virtualenv에서 MLflow UI를 열어야 해요.

UI 실행하기

터미널을 열고 다음 명령을 실행합니다.

mlflow ui

브라우저에서 추적 확인하기

브라우저를 열고 MLflow UI 포트(기본값: http://localhost:5000)에 접속하면 됩니다.

더 알아보기 (Learn more)

  • MLflow Tracing 공식 문서 — MLflow의 모델 추적 기능
  • mlflow.mistral.autolog() — Mistral AI 전용 자동 추적 활성화 API
  • Mistral Python SDK의 client.chat.complete() — 대화 생성 API