Add files via upload
This commit is contained in:
parent
0978bb2f1d
commit
1284bb346b
238 changed files with 13931 additions and 3 deletions
35
easyjailbreak/mutation/rule/Artificial.py
Normal file
35
easyjailbreak/mutation/rule/Artificial.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import importlib.resources
|
||||
from typing import List
|
||||
from easyjailbreak.mutation import MutationBase
|
||||
from easyjailbreak.datasets import Instance
|
||||
from easyjailbreak.seed import SeedTemplate
|
||||
|
||||
|
||||
class Artificial(MutationBase):
|
||||
"""
|
||||
Artificial mutation rule for Jailbroken
|
||||
"""
|
||||
def __init__(self, attr_name='query'):
|
||||
self.attr_name = attr_name
|
||||
|
||||
def _get_mutated_instance(self, instance) -> List[Instance]:
|
||||
|
||||
if not hasattr(instance, self.attr_name):
|
||||
raise AttributeError(f"Attribute '{self.attr_name}' not found in"
|
||||
" instance")
|
||||
|
||||
mutated_results = []
|
||||
seed_path = importlib.resources.files("easyjailbreak.seed") / "seed_template.json"
|
||||
prompt_seeds = SeedTemplate().new_seeds(
|
||||
method_list=['Jailbroken'],
|
||||
template_file=seed_path
|
||||
)
|
||||
|
||||
for prompt_seed in prompt_seeds:
|
||||
new_instance = instance.copy()
|
||||
for value in prompt_seed.values():
|
||||
new_instance.jailbreak_prompt = value
|
||||
new_instance.parents.append(instance)
|
||||
mutated_results.append(new_instance)
|
||||
|
||||
return mutated_results
|
||||
Loading…
Add table
Add a link
Reference in a new issue