🔧 Fix Quick Start code example

- Add missing 'import os' statement
- Properly formatted imports and load_dotenv() call
- Code now correctly uses os.getenv() for environment variables
This commit is contained in:
dongdongunique
2025-12-10 18:26:50 +08:00
parent 20e8068b7b
commit eb25f2780c

View File

@@ -132,36 +132,41 @@ Create a `.env` file with your API credentials:
```python
import asyncio
import os
from jailbreak_toolbox.models.implementations.openai_model import OpenAIModel
from jailbreak_toolbox.attacks.blackbox.implementations.evosynth import EvosynthAttack, EvosynthConfig
from jailbreak_toolbox.judges.implementations import LLMJudge
from dotenv import load_dotenv
load_dotenv()
async def main():
# Initialize models (using router platform like OpenRouter or BoyueRichData)
target_model = OpenAIModel(
model_name="gpt-4o",
api_key="your_key",
base_url="https://openrouter.ai/api/v1" # or your router's endpoint
api_key=os.getenv("OPENAI_API_KEY"),
base_url=os.getenv("OPENAI_BASE_URL") # or your router's endpoint
)
judge_model = OpenAIModel(
model_name="gpt-4o",
api_key="your_key",
base_url="https://openrouter.ai/api/v1"
api_key=os.getenv("OPENAI_API_KEY"),
base_url=os.getenv("OPENAI_BASE_URL")
)
# Configure attack
config = EvosynthConfig(
max_iterations=15,
success_threshold=5,
pipeline="full_pipeline"
pipeline="full_pipeline",
openai_api_key=os.getenv("OPENAI_API_KEY"),
base_url=os.getenv("OPENAI_BASE_URL"),
attack_model_base="deepseek-chat",
langfuse_host=None
)
# Create judge and attack
judge = LLMJudge(judge_model=judge_model)
attack = EvosynthAttack(
target_model=target_model,
judge=judge,
config=config
judge=judge_model,
config=config,
)
# Execute attack (async)