Niestandardowe ewaluatory (klasyka)

Aktualnie wyświetlane:Wersja - portalu Foundry (wersja klasyczna)Przełączanie do wersji dla nowego portalu Foundry

Note

Zestaw MICROSOFT Foundry SDK do oceny i portalu Foundry jest dostępny w publicznej wersji zapoznawczej, ale interfejsy API są ogólnie dostępne do oceny modelu i zestawu danych (ocena agenta pozostaje w publicznej wersji zapoznawczej). Zestaw SDK oceny Azure sztucznej inteligencji i ewaluatory oznaczone (wersja zapoznawcza) w tym artykule są obecnie dostępne w publicznej wersji zapoznawczej wszędzie.

Wbudowane ewaluatory zapewniają łatwy sposób monitorowania jakości generowania aplikacji. Aby dostosować oceny, możesz utworzyć własne ewaluatory oparte na kodzie lub monitach.

Code-based evaluators

Nie potrzebujesz dużego modelu językowego do niektórych metryk ewaluacji. Ewaluatory oparte na kodzie dają elastyczność definiowania metryk na podstawie funkcji lub klas wywołalnych. Możesz zbudować własny ewaluator oparty na kodzie, na przykład tworząc prostą klasę Python, która oblicza długość odpowiedzi w answer_length.py w katalogu answer_len/, jak w poniższym przykładzie.

Przykład ewaluatora opartego na kodzie: długość odpowiedzi

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)}

Uruchom evaluator na wierszu danych, importując klasę wywoływaną:

from answer_len.answer_length import AnswerLengthEvaluator

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

Wyjście ewaluatora opartego na kodzie: długość odpowiedzi

{"answer_length":27}

Prompt-based evaluators

Aby zbudować własny ewaluator dużych modeli językowych oparty na promptach lub adnotator wspomagany AI, stwórz niestandardowy ewaluator oparty na pliku Prompty .

Prompty to plik z rozszerzeniem .prompty do tworzenia szablonów promptów. Asset Prompty to plik markdown z zmodyfikowaną wersją frontową. Materiał wstępny jest w formacie YAML. Zawiera pola metadanych definiujące konfigurację modelu oraz oczekiwane dane wejściowe Prompty.

Aby zmierzyć przyjazność odpowiedzi, stwórz niestandardowy ewaluator o nazwie:FriendlinessEvaluator

Przykład ewaluatora opartego na promptach: Ewaluator życzliwości

Najpierw stwórz plik, friendliness.prompty który definiuje metrykę przyjazności i jej rubrykę oceniania:

---
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:

Następnie utworzę klasę FriendlinessEvaluator , która załaduje plik Prompty i przetwarza wyniki w formacie JSON:

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

Teraz stwórz własny ewaluator oparty na Prompty i uruchom go na wierszu danych:

from friendliness.friend import FriendlinessEvaluator

friendliness_eval = FriendlinessEvaluator(model_config)

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

Wyniki oceniające oparte na promptach: Ewaluator przyjazności

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