커스텀 평가기 (클래식)

현재 보기:Foundry(클래식) 포털 버전 - 새 Foundry 포털의 버전으로 전환

Note

평가 및 Foundry 포털용 Microsoft Foundry SDK는 공개 미리 보기로 제공되지만 API는 일반적으로 모델 및 데이터 세트 평가에 사용할 수 있습니다(에이전트 평가는 공개 미리 보기로 유지됨). 이 문서에서 표시된 Azure AI 평가 SDK 및 평가자는 현재 모든 곳에서 공개 미리 보기로 제공됩니다.

기본 제공 평가기는 애플리케이션 세대의 품질을 쉽게 모니터링할 수 있는 방법을 제공합니다. 평가를 사용자 지정하려면 고유한 코드 기반 또는 프롬프트 기반 평가자를 만들 수 있습니다.

Code-based evaluators

특정 평가 지표를 위해 대규모 언어 모델이 필요하지 않습니다. 코드 기반 평가자는 함수나 호출 가능한 클래스를 기반으로 지표를 정의할 수 있는 유연성을 제공합니다. 예를 들어, answer_length.py 명령 answer_len/ 아래에서 답의 길이를 계산하는 간단한 Python 클래스를 생성하여 자신만의 코드 기반 평가기를 만들 수 있습니다.

코드 기반 평가자 예시: 답변 길이

class AnswerLengthEvaluator:
    def __init__(self):
        pass
    # A class is made callable by implementing the special method __call__
    def __call__(self, *, answer: str, **kwargs):
        return {"answer_length": len(answer)}

호출 가능한 클래스를 임포트하여 데이터 행에 대해 평가자를 실행합니다:

from answer_len.answer_length import AnswerLengthEvaluator

answer_length_evaluator = AnswerLengthEvaluator()
answer_length = answer_length_evaluator(answer="What is the speed of light?")

코드 기반 평가자 출력: 답변 길이

{"answer_length":27}

Prompt-based evaluators

자신만의 프롬프트 기반 대형 언어 모델 평가자나 AI 지원 주석기를 만들려면, Prompty 파일을 기반으로 맞춤형 평가자를 만드세요.

Prompty는 프롬프트 템플릿 개발을 위한 확장자를 가진 .prompty 파일입니다. Prompty 자산은 수정된 프론트 매터가 포함된 마크다운 파일입니다. 서두에 있는 부분은 YAML 형식으로 되어 있습니다. 이 데이터베이스에는 모델 구성과 프롬프티의 예상 입력을 정의하는 메타데이터 필드가 포함되어 있습니다.

응답의 친밀도를 측정하기 위해 다음과 같은 FriendlinessEvaluator맞춤형 평가자를 만드세요:

프롬프트 기반 평가자 예시: 친밀도 평가자

먼저, 친밀도 지표와 그 평가 기준을 정의하는 파일을 만드 friendliness.prompty 세요:

---
name: Friendliness Evaluator
description: Friendliness Evaluator to measure warmth and approachability of answers.
model:
  api: chat
  configuration:
    type: azure_openai
    azure_endpoint: ${env:AZURE_OPENAI_ENDPOINT}
    azure_deployment: gpt-4o-mini
  parameters:
    model:
    temperature: 0.1
inputs:
  response:
    type: string
outputs:
  score:
    type: int
  explanation:
    type: string
---

system:
Friendliness assesses the warmth and approachability of the answer. Rate the friendliness of the response between one to five stars using the following scale:

One star: the answer is unfriendly or hostile

Two stars: the answer is mostly unfriendly

Three stars: the answer is neutral

Four stars: the answer is mostly friendly

Five stars: the answer is very friendly

Please assign a rating between 1 and 5 based on the tone and demeanor of the response.

**Example 1**
generated_query: I just don't feel like helping you! Your questions are getting very annoying.
output:
{"score": 1, "reason": "The response is not warm and is resisting to be providing helpful information."}
**Example 2**
generated_query: I'm sorry this watch is not working for you. Very happy to assist you with a replacement.
output:
{"score": 5, "reason": "The response is warm and empathetic, offering a resolution with care."}

**Here the actual conversation to be scored:**
generated_query: {{response}}
output:

그 다음 Prompty 파일을 불러오고 JSON 형식으로 출력을 처리하는 클래스 FriendlinessEvaluator 를 만듭니다:

import os
import json
import sys
from promptflow.client import load_flow

class FriendlinessEvaluator:
    def __init__(self, model_config):
        current_dir = os.path.dirname(__file__)
        prompty_path = os.path.join(current_dir, "friendliness.prompty")
        self._flow = load_flow(source=prompty_path, model={"configuration": model_config})

    def __call__(self, *, response: str, **kwargs):
        llm_response = self._flow(response=response)
        try:
            response = json.loads(llm_response)
        except Exception as ex:
            response = llm_response
        return response

이제 자신만의 Prompty 기반 평가기를 만들어 데이터 행에 대해 실행하세요:

from friendliness.friend import FriendlinessEvaluator

friendliness_eval = FriendlinessEvaluator(model_config)

friendliness_score = friendliness_eval(response="I will not apologize for my behavior!")

프롬프트 기반 평가자 출력: 친밀도 평가자

{
    'score': 1, 
    'reason': 'The response is hostile and unapologetic, lacking warmth or approachability.'
}