Skip to content

Commit 7516601

Browse files
authored
Merge pull request #88 from RomiconEZ/fix-bugs
Add Logo and `ChatSession` Exception Handling + Fix Docs
2 parents 6eff307 + 69b2409 commit 7516601

24 files changed

+283
-302
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# LLAMATOR
1+
# ![LLAMATOR](assets/LLAMATOR.svg)
22

3-
Red Teaming python-framework for testing chatbots and LLM-systems
3+
Red Teaming python-framework for testing chatbots and LLM systems
44

55
[![License: CC BY-NC-SA 4.0](https://img.shields.io/badge/License-CC_BY--NC--SA_4.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
66
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/llamator)](https://pypi.org/project/llamator)

assets/LLAMATOR.svg

Lines changed: 27 additions & 0 deletions
Loading

docker/instruction.md

Lines changed: 0 additions & 134 deletions
This file was deleted.

docs/howtos.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ tested_model = llamator.ClientOpenAI(
3535
base_url="http://localhost:1234/v1",
3636
model="model-identifier",
3737
temperature=0.1,
38-
system_prompts=["You are a defensive model."],
38+
model_description="Model description",
3939
)
4040

4141
# List of tests with the number of attempts
@@ -74,8 +74,8 @@ config = {
7474

7575
# Start testing
7676
llamator.start_testing(
77-
attack_model,
78-
tested_model,
77+
attack_model=attack_model,
78+
tested_model=tested_model,
7979
config=config,
8080
tests_with_attempts=tests_with_attempts,
8181
multistage_depth=20,

docs/project_overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Project Overview
22

3-
LLAMATOR - Red Teaming python-framework for testing chatbots and LLM-systems
3+
LLAMATOR - Red Teaming python-framework for testing chatbots and LLM systems
44

55
[![License: CC BY-NC-SA 4.0](https://img.shields.io/badge/License-CC_BY--NC--SA_4.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
66
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/llamator)](https://pypi.org/project/llamator)

examples/llamator-api.ipynb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@
142142
" self.model_description = model_description\n",
143143
"\n",
144144
" def interact(self, history: List[Dict[str, str]], messages: List[Dict[str, str]]) -> Dict[str, str]:\n",
145-
" history += messages\n",
146145
" try:\n",
147146
" r = requests.post(self.api_url, json={\"question\": messages[-1][\"content\"]})\n",
148147
" if r.status_code == 200:\n",
@@ -152,7 +151,6 @@
152151
" except Exception as e:\n",
153152
" print(e)\n",
154153
" raise\n",
155-
" history.append(response_message)\n",
156154
" return response_message"
157155
]
158156
},
@@ -217,7 +215,7 @@
217215
"\n",
218216
"### Available Attacks\n",
219217
"\n",
220-
"Check out the [documentation](https://romiconez.github.io/llamator/attacks_description.html) for an overview of available attacks."
218+
"Check out the [documentation](https://romiconez.github.io/llamator/attack_descriptions.html) for an overview of available attacks."
221219
]
222220
},
223221
{

examples/llamator-langchain-custom-attack.ipynb

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 1,
14+
"execution_count": null,
1515
"metadata": {
1616
"id": "JuO12HZQQEnx"
1717
},
@@ -35,7 +35,7 @@
3535
"output_type": "stream",
3636
"text": [
3737
"Name: llamator\n",
38-
"Version: 1.1.1\n",
38+
"Version: 2.2.0\n",
3939
"Summary: Framework for testing vulnerabilities of large language models (LLM).\n",
4040
"Home-page: \n",
4141
"Author: \n",
@@ -239,11 +239,6 @@
239239
"\n",
240240
" # Generating a Prompt by an Attack Model\n",
241241
" for attack_prompt_index in range(self.num_attempts):\n",
242-
" chat = ChatSession(self.attack_config.attack_client.get_target_client())\n",
243-
" attack_prompt = chat.say(\n",
244-
" ORDINARY_PROMPT_TEMPLATE.format(description=self.client_config.get_model_description())\n",
245-
" )\n",
246-
" attack_prompts.append(attack_prompt)\n",
247242
" yield StatusUpdate(\n",
248243
" self.client_config,\n",
249244
" self.test_name,\n",
@@ -252,6 +247,15 @@
252247
" attack_prompt_index,\n",
253248
" self.num_attempts,\n",
254249
" )\n",
250+
" chat = ChatSession(self.attack_config.attack_client.get_target_client())\n",
251+
" attack_prompt = chat.say(\n",
252+
" ORDINARY_PROMPT_TEMPLATE.format(description=self.client_config.get_model_description())\n",
253+
" )\n",
254+
" if not attack_prompt:\n",
255+
" logger.warning(\"Error while attacking against target LLM (didn't receive response) ...\")\n",
256+
" self.status.report_error(str(attack_prompt_index))\n",
257+
" else:\n",
258+
" attack_prompts.append(attack_prompt)\n",
255259
"\n",
256260
" # Executing attack prompts and checking the output of the attacked model\n",
257261
" yield StatusUpdate(\n",
@@ -291,6 +295,9 @@
291295
" self.status.report_breach(attack_prompt, response)\n",
292296
" else:\n",
293297
" self.status.report_resilient(attack_prompt, response)\n",
298+
" # Adding a response and status to a report\n",
299+
" responses.append(response)\n",
300+
" statuses.append(current_status)\n",
294301
" yield StatusUpdate(\n",
295302
" self.client_config,\n",
296303
" self.test_name,\n",
@@ -299,9 +306,6 @@
299306
" attack_prompt_index,\n",
300307
" self.num_attempts,\n",
301308
" )\n",
302-
" # Adding a response and status to a report\n",
303-
" responses.append(response)\n",
304-
" statuses.append(current_status)\n",
305309
"\n",
306310
" # Adding data to the report\n",
307311
" self._prepare_attack_data(attack_prompts, responses, statuses)\n",
@@ -332,7 +336,7 @@
332336
"data": {
333337
"text/plain": [
334338
"{'role': 'assistant',\n",
335-
" 'content': 'Hello! How are you today? How can I assist you?'}"
339+
" 'content': \"Hello! Nice to meet you. How are you today? Is there something you would like to talk about or ask me? I'm here to help. 😊\"}"
336340
]
337341
},
338342
"execution_count": 9,
@@ -373,7 +377,7 @@
373377
"\n",
374378
"### Available Attacks\n",
375379
"\n",
376-
"Check out the [documentation](https://romiconez.github.io/llamator/attacks_description.html) for an overview of available attacks."
380+
"Check out the [documentation](https://romiconez.github.io/llamator/attack_descriptions.html) for an overview of available attacks."
377381
]
378382
},
379383
{
@@ -399,7 +403,7 @@
399403
"name": "stderr",
400404
"output_type": "stream",
401405
"text": [
402-
"Test progress ........................................: 0%| | 0/1 [00:00<?, ?it/s]: 0%| | 0/1 [00:00<?, ?it/s]: 100%|██████████| 1/1 [00:36<00:00, 36.06s/it]: 100%|██████████| 1/1 [00:36<00:00, 36.06s/it]\n"
406+
"Test progress ........................................: 0%| | 0/1 [00:00<?, ?it/s]: 0%| | 0/1 [00:00<?, ?it/s]: 100%|██████████| 1/1 [01:14<00:00, 74.54s/it]: 100%|██████████| 1/1 [01:14<00:00, 74.55s/it]\n"
403407
]
404408
},
405409
{
@@ -420,21 +424,22 @@
420424
"repeat_10_times:\n",
421425
" Tests LLM for 10 times response vulnerability\n",
422426
"\n",
423-
"Excel report created: ./artifacts\\LLAMATOR_run_2025-01-12_17-02-05\\attacks_report.xlsx\n"
427+
"DISCLAIMER: Report may contain HARMFUL and OFFENSIVE language, reader discretion is recommended.\n",
428+
"Excel report created: ./artifacts\\LLAMATOR_run_2025-02-17_11-30-47\\attacks_report.xlsx\n"
424429
]
425430
},
426431
{
427432
"name": "stderr",
428433
"output_type": "stream",
429434
"text": [
430-
"2025-01-12 17:02:46,865 [WARNING] [word_report_generator.py:352]: Test with in_code_name 'repeat_10_times' not found in JSON. Skipping file repeat_10_times.csv.\n"
435+
"2025-02-17 11:32:05,188 [WARNING] [word_report_generator.py:352]: Test with in_code_name 'repeat_10_times' not found in JSON. Skipping file repeat_10_times.csv.\n"
431436
]
432437
},
433438
{
434439
"name": "stdout",
435440
"output_type": "stream",
436441
"text": [
437-
"Word report created: ./artifacts\\LLAMATOR_run_2025-01-12_17-02-05\\attacks_report.docx\n",
442+
"Word report created: ./artifacts\\LLAMATOR_run_2025-02-17_11-30-47\\attacks_report.docx\n",
438443
"Thank you for using LLAMATOR!\n"
439444
]
440445
}

examples/llamator-selenium.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
"\n",
293293
"### Available Attacks\n",
294294
"\n",
295-
"Check out the [documentation](https://romiconez.github.io/llamator/attacks_description.html) for an overview of available attacks."
295+
"Check out the [documentation](https://romiconez.github.io/llamator/attack_descriptions.html) for an overview of available attacks."
296296
]
297297
},
298298
{

0 commit comments

Comments
 (0)