# Insert items into dataset
url = "https://github.com/openai/moderation-api-release/raw/main/data/samples-1680.jsonl.gz"
response = requests.get(url)
df = pd.read_json(BytesIO(response.content), lines=True, compression="gzip")

df = df.sample(n=50, random_state=42)

dataset_records = []
for x in df.to_dict(orient="records"):
    moderation_fields = ["S", "H", "V", "HR", "SH", "S3", "H2", "V2"]
    moderated_fields = [field for field in moderation_fields if x[field] == 1.0]
    expected_output = "moderated" if moderated_fields else "not_moderated"

    dataset_records.append(
        {
            "output": x["prompt"],
            "expected_output": expected_output,
            "moderated_fields": moderated_fields,
        }
    )

dataset.insert(dataset_records)
```

## Evaluating the moderation metric

In order to evaluate the performance of the Opik moderation metric, we will define:

* Evaluation task: Our evaluation task will use the data in the Dataset to return a moderation score computed using the Opik moderation metric.
* Scoring metric: We will use the `Equals` metric to check if the moderation score computed matches the expected output.

By defining the evaluation task in this way, we will be able to understand how well Opik's moderation metric is able to detect moderation violations in the dataset.

We can use the Opik SDK to compute a moderation score for each item in the dataset:

```python
from opik.evaluation.metrics import Moderation, Equals
from opik.evaluation import evaluate
from opik import Opik
from opik.evaluation.metrics.llm_judges.moderation.template import generate_query
from typing import Dict