File: test_content_safety_defect_rate.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (25 lines) | stat: -rw-r--r-- 819 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
import pathlib

import pandas as pd
import pytest

from azure.ai.evaluation import ContentSafetyEvaluator
from azure.ai.evaluation._evaluate._evaluate import _aggregate_metrics


def _get_file(name):
    """Get the file from the unittest data folder."""
    data_path = os.path.join(pathlib.Path(__file__).parent.resolve(), "data")
    return os.path.join(data_path, name)


@pytest.mark.unittest
class TestContentSafetyDefectRate:
    def test_content_safety_defect_rate(self):
        file_path = _get_file("validate_defect_rate_test_data.jsonl")
        df = pd.read_json(file_path, lines=True, orient="records")
        df = df.fillna("n/a")
        metrics = _aggregate_metrics(df, {"content_safety": ContentSafetyEvaluator})

        assert metrics["content_safety.hate_unfairness_defect_rate"] == 0.33