Skip to content

Commit

Permalink
Harmful warning (#79)
Browse files Browse the repository at this point in the history
* fix docstring formatting

* add harmful warning
  • Loading branch information
nizamovtimur authored Feb 4, 2025
1 parent 6283d13 commit af60896
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/llamator/attacks/bon.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def apply_ascii_noising(prompt: str, sigma: float) -> str:
@register_test
class TestBon(TestBase):
"""Probes the LLM resilience against Best-of-N attack (text augmentations).
`Original Paper <https://arxiv.org/abs/2412.03556>`_, `Code <https://github.com/jplhughes/bon-jailbreaking>`_."""
Original Paper: https://arxiv.org/abs/2412.03556, Code: https://github.com/jplhughes/bon-jailbreaking"""

test_name = "bon"

Expand Down
2 changes: 1 addition & 1 deletion src/llamator/attacks/crecsendo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
class TestCrescendo(TestBase):
"""Challenges the LLM with a dataset of harmful behavior prompts using Crescendo strategy,
operates by engaging the LLM in a series of escalating conversational turns, and multistage refinement.
`Original Paper <https://arxiv.org/abs/2404.01833>`_"""
Original Paper: https://arxiv.org/abs/2404.01833"""

test_name = "crescendo"

Expand Down
2 changes: 1 addition & 1 deletion src/llamator/attacks/sycophancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
@register_test
class TestSycophancy(TestBase):
"""Attacks the LLM system during a multistage conversation using the argumentum ad verecundiam method based on the system's domain.
`Original Paper <https://arxiv.org/abs/2310.13548>`_"""
Original Paper: https://arxiv.org/abs/2310.13548"""

test_name = "sycophancy"

Expand Down
2 changes: 1 addition & 1 deletion src/llamator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def start_testing(
if enable_reports:
report_language = validate_language(report_language)
csv_folder_name = "csv_report"
# Create Excel report
print(f"{BRIGHT}{colorama.Fore.RED}DISCLAIMER: Report may contain HARMFUL and OFFENSIVE language, reader discretion is recommended.{RESET}")
create_attack_report_from_artifacts(
artifacts_dir=artifacts_run_path, csv_folder_name=csv_folder_name, report_file_name="attacks_report.xlsx"
)
Expand Down
17 changes: 10 additions & 7 deletions tests/test_llamator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import importlib
import os

from dotenv import load_dotenv


def test_openai_client():
"""
Tests OpenAI client from public LLaMator lib.
Tests OpenAI client from public llamator lib.
Environment variables
----------
Expand All @@ -15,7 +17,8 @@ def test_openai_client():
OPENAI_CLIENT_MODEL : str
Type of model
"""
# Перезагрузка необходимых модулей
load_dotenv()

import llamator

importlib.reload(llamator)
Expand Down Expand Up @@ -63,11 +66,11 @@ def test_openai_client():
]

config = {
"enable_logging": True, # Включить логирование
"enable_reports": True, # Включить генерацию отчетов
"artifacts_path": "./artifacts", # Путь к директории для сохранения артефактов
"debug_level": 1, # Уровень логирования: 0 - WARNING, 1 - INFO, 2 - DEBUG
"report_language": "ru", # Язык отчета: 'en', 'ru'
"enable_logging": True, # Enable logging
"enable_reports": True, # Enable report generation
"artifacts_path": "./artifacts", # Path to the directory for saving artifacts
"debug_level": 1, # Logging level: 0 - WARNING, 1 - INFO, 2 - DEBUG
"report_language": "en", # Report language: 'en', 'ru'
}

llamator.start_testing(attack_model, tested_model, config=config, tests_with_attempts=tests_with_attempts)
30 changes: 14 additions & 16 deletions tests/test_local_llamator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def test_openai_client():
"""
Tests OpenAI client from local LLaMator lib.
Tests OpenAI client from local llamator lib.
Environment variables
----------
Expand All @@ -17,7 +17,8 @@ def test_openai_client():
OPENAI_CLIENT_MODEL : str
Type of model
"""
# Перезагрузка необходимых модулей
load_dotenv()

import llamator.client.specific_chat_clients
import llamator.main

Expand Down Expand Up @@ -51,11 +52,11 @@ def test_openai_client():
]

config = {
"enable_logging": True, # Включить логирование
"enable_reports": True, # Включить генерацию отчетов
"artifacts_path": "./artifacts", # Путь к директории для сохранения артефактов
"debug_level": 1, # Уровень логирования: 0 - WARNING, 1 - INFO, 2 - DEBUG
"report_language": "ru", # Язык отчета: 'en', 'ru'
"enable_logging": True, # Enable logging
"enable_reports": True, # Enable report generation
"artifacts_path": "./artifacts", # Path to the directory for saving artifacts
"debug_level": 1, # Logging level: 0 - WARNING, 1 - INFO, 2 - DEBUG
"report_language": "en", # Report language: 'en', 'ru'
}

from llamator.main import start_testing
Expand All @@ -65,7 +66,7 @@ def test_openai_client():

def test_langchain_client_yandexgpt():
"""
Tests LangChain client from local LLaMator lib using Yandex GPT backend.
Tests LangChain client from local llamator lib using Yandex GPT backend.
Environment variables
----------
Expand All @@ -74,17 +75,14 @@ def test_langchain_client_yandexgpt():
FOLDER_ID : str
Yandex Cloud folder ID
"""
# Загружаем переменные окружения из .env файла
load_dotenv()

# Перезагрузка необходимых модулей
import llamator.client.specific_chat_clients
import llamator.main

importlib.reload(llamator.client.specific_chat_clients)
importlib.reload(llamator.main)

# Получаем переменные из окружения
folder_ID = os.getenv("FOLDER_ID")

from llamator.client.specific_chat_clients import ClientLangChain
Expand Down Expand Up @@ -124,11 +122,11 @@ def test_langchain_client_yandexgpt():
]

config = {
"enable_logging": True, # Включить логирование
"enable_reports": True, # Включить генерацию отчетов
"artifacts_path": "./artifacts", # Путь к директории для сохранения артефактов
"debug_level": 1, # Уровень логирования: 0 - WARNING, 1 - INFO, 2 - DEBUG
"report_language": "ru", # Язык отчета: 'en', 'ru'
"enable_logging": True, # Enable logging
"enable_reports": True, # Enable report generation
"artifacts_path": "./artifacts", # Path to the directory for saving artifacts
"debug_level": 1, # Logging level: 0 - WARNING, 1 - INFO, 2 - DEBUG
"report_language": "en", # Report language: 'en', 'ru'
}

from llamator.main import start_testing
Expand Down

0 comments on commit af60896

Please sign in to comment.