Spaces:
Sleeping
Sleeping
Commit ·
3cd5882
1
Parent(s): 57c321d
feat(inference): add generate_attack() — uses OpenAI client to craft next framing
Browse files- inference.py +19 -0
inference.py
CHANGED
|
@@ -14,3 +14,22 @@ client = OpenAI(
|
|
| 14 |
base_url = f"https://api-inference.huggingface.co/models/{MODEL_NAME}/v1",
|
| 15 |
api_key = HF_TOKEN,
|
| 16 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
base_url = f"https://api-inference.huggingface.co/models/{MODEL_NAME}/v1",
|
| 15 |
api_key = HF_TOKEN,
|
| 16 |
)
|
| 17 |
+
|
| 18 |
+
def generate_attack(defender_response: str, turn: int, previous_success: float) -> dict:
|
| 19 |
+
prompt = f"Previous response: {defender_response[:100]}. Turn: {turn}. Success: {previous_success:.2f}."
|
| 20 |
+
try:
|
| 21 |
+
response = client.chat.completions.create(
|
| 22 |
+
model = MODEL_NAME,
|
| 23 |
+
messages = [{"role": "user", "content": prompt}],
|
| 24 |
+
max_tokens = 200,
|
| 25 |
+
)
|
| 26 |
+
framing = response.choices[0].message.content.strip()[:490]
|
| 27 |
+
except Exception:
|
| 28 |
+
framing = f"Fallback framing for turn {turn}."
|
| 29 |
+
|
| 30 |
+
return {
|
| 31 |
+
"strategy_type": "roleplay",
|
| 32 |
+
"target_category": "privacy",
|
| 33 |
+
"intensity": 0.5,
|
| 34 |
+
"framing": framing,
|
| 35 |
+
}
|