97 lines
No EOL
2 KiB
Markdown
97 lines
No EOL
2 KiB
Markdown
# Implementation Tools: DeepEval RedTeamer
|
|
|
|
<div class="code-container themed-code fullpage-code">
|
|
|
|
```py
|
|
from deepeval.red_teaming import RedTeamer
|
|
from deepeval.vulnerabilities import Bias, Misinformation
|
|
|
|
red_teamer = RedTeamer(
|
|
target_purpose="Provide financial advice and answer user finance queries",
|
|
target_system_prompt="You are a financial assistant for planning and advice"
|
|
)
|
|
|
|
vulnerabilities = [
|
|
Bias(types=[BiasType.GENDER, BiasType.POLITICS]),
|
|
Misinformation(types=[MisinformationType.FACTUAL_ERRORS])
|
|
]
|
|
|
|
results = red_teamer.scan(
|
|
target_model_callback=target_model_callback,
|
|
attacks_per_vulnerability_type=5,
|
|
vulnerabilities=vulnerabilities,
|
|
)
|
|
|
|
print(f"Total attacks: {len(results.attacks)}")
|
|
print(f"Successful attacks: {len(results.successful_attacks)}")
|
|
print(f"Success rate: {results.attack_success_rate}")
|
|
```
|
|
|
|
</div>
|
|
|
|
<style>
|
|
.code-container {
|
|
max-height: 75vh;
|
|
height: 75vh;
|
|
overflow-y: auto;
|
|
margin-bottom: 0;
|
|
margin-top: 1rem;
|
|
border-radius: 8px;
|
|
border: 1px solid var(--primary-color);
|
|
box-shadow: 0 4px 12px var(--card-shadow);
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.code-container:hover {
|
|
transform: scale(1.01);
|
|
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
|
|
border-color: var(--highlight);
|
|
}
|
|
|
|
.fullpage-code pre {
|
|
padding: 1.5rem !important;
|
|
}
|
|
|
|
.fullpage-code code {
|
|
font-size: 0.8rem !important;
|
|
line-height: 1.5 !important;
|
|
}
|
|
|
|
/* Hover effect for each word in code */
|
|
.fullpage-code .token {
|
|
transition: all 0.15s ease;
|
|
display: inline-block;
|
|
}
|
|
|
|
.fullpage-code .token:hover {
|
|
transform: scale(1.2);
|
|
z-index: 10;
|
|
position: relative;
|
|
cursor: pointer;
|
|
color: var(--highlight);
|
|
}
|
|
|
|
.themed-code pre {
|
|
background-color: #0c1525 !important;
|
|
}
|
|
|
|
.themed-code .token.comment {
|
|
color: #6272a4 !important;
|
|
}
|
|
|
|
.themed-code .token.string {
|
|
color: #a43e3e !important;
|
|
}
|
|
|
|
.themed-code .token.function {
|
|
color: #0066CC !important;
|
|
}
|
|
|
|
.themed-code .token.keyword {
|
|
color: #800020 !important;
|
|
}
|
|
|
|
.themed-code .token.builtin {
|
|
color: #B22222 !important;
|
|
}
|
|
</style> |