Files
EvoSynth/jailbreak_toolbox/datasets/base_dataset.py
dongdongunique f3af94df0b first commit
2025-12-10 00:54:02 +08:00

30 lines
908 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from abc import ABC, abstractmethod
from typing import Iterator, Any
class BaseDataset(ABC):
"""
所有数据集的抽象基类。
确保了无论数据来自文件、数据库还是内存,
框架都能以统一的方式进行迭代。
"""
def __init__(self, **kwargs):
"""允许在配置文件中传入任意数据集特定的参数。"""
pass
@abstractmethod
def __iter__(self) -> Iterator[Any]:
"""
返回一个迭代器,每次产生一个攻击目标 (例如一个有害的prompt)。
这是让数据集能够被 for 循环遍历的关键。
"""
pass
@abstractmethod
def __len__(self) -> int:
"""返回数据集中的样本总数。"""
pass
@abstractmethod
def __getitem__(self, index: int) -> Any:
"""支持索引访问数据集中的特定样本。"""
pass