Prompt Engineering UI (프롬프트 엔지니어링 UI)

Prompt Engineering UI (프롬프트 엔지니어링 UI)

MLflow 2.7부터 Tracking UI에서 코드 없이 여러 LLM과 파라미터, 프롬프트를 조합해 시험해볼 수 있는 프롬프트 엔지니어링 경험을 제공해요. AI Gateway 엔드포인트의 다양한 LLM과 파라미터 설정, 프롬프트를 골라 질문 응답이나 문서 요약 같은 모델을 만들어볼 수 있죠. 내장된 Evaluation UI로 여러 모델을 같은 입력에 평가하고 비교해서 최선을 고를 수도 있어요.

출처: Prompt Engineering UI (Experimental)

준비: AI Gateway 엔드포인트

프롬프트 엔지니어링 UI를 쓰려면 하나 이상의 MLflow AI Gateway completions 또는 chat 엔드포인트가 필요해요. 아직 없으면 AI Gateway 퀵스타트로 5분 안에 만들 수 있어요. llm/v1/completions 또는 llm/v1/chat 타입 엔드포인트가 이미 있다면 이 단계는 건너뛰면 돼요.

mlflow gateway start --config-path config.yaml --port 7000

프롬프트 엔지니어링 UI는 AI Gateway와 Tracking Server의 연결도 필요해요. 서버가 도는 환경에 MLFLOW_DEPLOYMENTS_TARGET 환경변수를 설정하고 서버를 재시작하면 됩니다.

export MLFLOW_DEPLOYMENTS_TARGET="http://127.0.0.1:7000"
mlflow server --port 5000

프롬프트 시험해보기

실험을 열고 New Run 버튼 → using Prompt Engineering 선택하면 프롬프트 엔지니어링 플레이그라운드가 열려요. 여기에서 Select endpoint 드롭다운으로 AI Gateway completions 엔드포인트를 고르고, Evaluate 버튼으로 예시 프롬프트를 시험할 수 있어요.

프롬프트 템플릿은 여러 변수를 정의할 수 있어요. MLflow 문서에 대해 질문하도록 지시하는 예시 템플릿:

Read the following article from the MLflow documentation that appears between triple backticks. Then, answer the question about the documentation that appears between triple quotes. Include relevant links and code examples in your answer.
```{{article}}```
"""{{question}}"""

그다음 입력 변수를 채워요. 예를 들어 article 변수에 문서 내용을, question 변수에 "How do I create a new MLflow Run using the Python API?"를 넣고 Evaluate를 누르면 되죠.

Run으로 저장하고 비교하기

마음에 드는 프롬프트 템플릿과 파라미터를 찾았다면 Create Run 버튼으로 저장해요. 이러면 프롬프트 템플릿·파라미터·선택한 LLM이 Run params로 저장되고, 배치 또는 실시간 추론에 쓸 수 있는 MLflow Model도 자동으로 만들어져요.

새 입력에서도 동작을 확인하려면 Add Row로 변수 값을 채워 Evaluate하고 Save로 저장하면 돼요. 성능이 기대에 못 미치는 상황을 발견하면 context menu의 Duplicate run 옵션으로 새 Run을 만들어 프롬프트 템플릿을 수정한 뒤 다시 Create Run 할 수 있어요.

Evaluate all 버튼으로 이전의 모든 입력을 새 설정에 대해 평가하고, 결과를 저장해 이전 설정과 비교할 수 있어요.

입력·출력 데이터에 접근하기

UI가 만든 모든 입력·출력은 artifacts로 MLflow Runs에 저장돼요. mlflow.load_table() API로 프로그래밍 방식으로 접근할 수 있습니다.

import mlflow

mlflow.set_experiment("/Path/to/your/prompt/engineering/experiment")

# 모든 Run(설정)의 입력·출력 데이터를 Pandas DataFrame으로 로드
inputs_outputs_pdf = mlflow.load_table(
    # UI에서 만든 모든 입력·출력은 "eval_results_table.json" artifact에 저장
    artifact_file="eval_results_table.json",
    # 다른 Run에서 만든 입력·출력 구분용 run_id 컬럼 포함
    extra_columns=["run_id"],
)

학습된 모델로 추론하기

잘 동작하는 설정을 찾으면 해당 MLflow Model을 로드해 배치 추론에 쓸 수 있어요.

import mlflow

logged_model = "runs:/8451075c46964f82b85fe16c3d2b7ea0/model"

# PyFuncModel으로 로드
loaded_model = mlflow.pyfunc.load_model(logged_model)

predict() 메서드에 입력 변수 딕셔너리를 넘겨 예측을 생성해요.

article_text = """An MLflow Project is a format for packaging data science code in a reusable and reproducible way..."""
question = "What is an MLflow project?"
loaded_model.predict({"article": article_text, "question": question})

실시간 서빙으로 배포하기

모델 레지스트리에 등록하고 mlflow models serve로 실시간 서빙할 수 있어요.

mlflow.register_model(
    model_uri="runs:/8451075c46964f82b85fe16c3d2b7ea0/model",
    name="mlflow_docs_qa_model",
)

서버가 도는 환경에 MLFLOW_DEPLOYMENTS_TARGET(AI Gateway URL) 환경변수를 정의한 뒤, 포트 8000에서 모델을 서빙해요.

mlflow models serve --model-uri models:/mlflow_docs_qa_model/1 --port 8000

REST API로 조회할 수 있어요.

input='{"dataframe_records": [{"article": "An MLflow Project is a format for packaging data science code...", "question": "What is an MLflow Project?"}]}'
echo $input | curl -s -X POST https://localhost:8000/invocations \
  -H 'Content-Type: application/json' -d @-

여기서 articlequestion은 프롬프트 템플릿의 입력 변수로 바꿔 쓰면 돼요.

더 알아보기