Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interactive mode intro #614

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion garak/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
version = -1 # eh why this is here? hm. who references it

system_params = "verbose narrow_output parallel_requests parallel_attempts".split()
run_params = "seed deprefix eval_threshold generations probe_tags".split()
run_params = "seed deprefix eval_threshold generations probe_tags interactive".split()
plugins_params = "model_type model_name extended_detectors".split()
reporting_params = "taxonomy report_prefix".split()

Expand Down
13 changes: 10 additions & 3 deletions garak/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ def main(arguments=[]) -> None:
try:
probe_cli_config = json.loads(probe_options_json)
except json.decoder.JSONDecodeError as e:
logging.warning("Failed to parse JSON probe_options: %s", {e.args[0]})
logging.warning(
"Failed to parse JSON probe_options: %s", {e.args[0]}
)
raise e

_config.plugins.probes = _config._combine_into(
Expand All @@ -358,7 +360,9 @@ def main(arguments=[]) -> None:
try:
generator_cli_config = json.loads(args.generator_options)
except json.JSONDecodeError as e:
logging.warning("Failed to parse JSON generator_options: %s", e.args[0])
logging.warning(
"Failed to parse JSON generator_options: %s", e.args[0]
)

elif "generator_option_file" in args:
with open(args.generator_option_file, encoding="utf-8") as f:
Expand Down Expand Up @@ -449,7 +453,10 @@ def main(arguments=[]) -> None:
generator = getattr(generator_mod, generator_class_name)(
_config.plugins.model_name
)
if hasattr(_config.run, "generations") and _config.run.generations is not None:
if (
hasattr(_config.run, "generations")
and _config.run.generations is not None
):
generator.generations = _config.run.generations
if hasattr(_config.run, "seed") and _config.run.seed is not None:
generator.seed = _config.run.seed
Expand Down
2 changes: 1 addition & 1 deletion garak/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def start_run():

logging.info("started at %s", _config.transient.starttime_iso)
# print("ASSIGN UUID", args)
if _config.system.lite and "probes" not in _config.transient.cli_args and not _config.transient.cli_args.list_probes and not _config.transient.cli_args.list_detectors and not _config.transient.cli_args.list_generators and not _config.transient.cli_args.list_buffs and not _config.transient.cli_args.list_config and not _config.transient.cli_args.plugin_info: # type: ignore
if _config.system.lite and "probes" not in _config.transient.cli_args and not _config.transient.cli_args.list_probes and not _config.transient.cli_args.list_detectors and not _config.transient.cli_args.list_generators and not _config.transient.cli_args.list_buffs and not _config.transient.cli_args.list_config and not _config.transient.cli_args.plugin_info and not _config.run.interactive: # type: ignore
print(
"⚠️ The current/default config is optimised for speed rather than thoroughness. Try e.g. --config full for a stronger test, or specify some probes."
)
Expand Down
17 changes: 15 additions & 2 deletions garak/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
# SPDX-License-Identifier: Apache-2.0

import argparse
import importlib
from logging import getLogger
import cmd2
import random
import sys

import cmd2
from colorama import Fore, Style
import importlib

import garak.harnesses.probewise
from garak import _config
from garak.evaluators import ThresholdEvaluator
from garak._plugins import enumerate_plugins

Expand Down Expand Up @@ -235,10 +238,20 @@ def settings_ns_provider(self) -> argparse.Namespace:
return ns


def banner():
"""Display a random banner"""
with open(
_config.transient.basedir / "resources/banners", "r", encoding="utf-8"
) as bannerfile:
banners = bannerfile.read().lstrip().split("\n\n")
print(Fore.LIGHTRED_EX + f"\n{random.choice(banners)}\n" + Fore.RESET)


def interactive_mode():
"""
Launch garak in interactive mode. Allows users to explore and use garak without CLI flags.
"""
banner()
terminal = GarakTerminal()
sys.exit(terminal.cmdloop())

Expand Down
136 changes: 136 additions & 0 deletions garak/resources/banners
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
_|
_|_|_| _|_|_| _| _|_| _|_|_| _| _|
_| _| _| _| _|_| _| _| _|_|
_| _| _| _| _| _| _| _| _|
_|_|_| _|_|_| _| _|_|_| _| _|
_|
_|_|

.,-:::::/ :::. :::::::.. :::. ::: .
,;;-'````' ;;`;; ;;;;``;;;; ;;`;; ;;; .;;,.
[[[ [[[[[[/,[[ '[[, [[[,/[[[' ,[[ '[[, [[[[[/'
"$$c. "$$c$$$cc$$$c $$$$$$c c$$$cc$$$c _$$$$,
`Y8bo,,,o88o888 888,888b "88bo,888 888,"888"88o,
`'YMUP"YMMYMM ""` MMMM "W" YMM ""` MMM "MMP"

__
_________ ____________ | | __
/ ___\__ \\_ __ \__ \ | |/ /
/ /_/ > __ \| | \// __ \| <
\___ (____ /__| (____ /__|_ \
/_____/ \/ \/ \/

_
__ _ __ _ _ __ __ _| | __
/ _` |/ _` | '__/ _` | |/ /
| (_| | (_| | | | (_| | <
\__, |\__,_|_| \__,_|_|\_\
|___/

__
____ _____ __________ _/ /__
/ __ `/ __ `/ ___/ __ `/ //_/
/ /_/ / /_/ / / / /_/ / ,<
\__, /\__,_/_/ \__,_/_/|_|
/____/

dBBBBb dBBBBBb dBBBBBb dBBBBBb dBP dBP
BB dBP BB d8P.dBP
dBBBB dBP BB dBBBBK dBP BB dBBBBP
dB' BB dBP BB dBP BB dBP BB dBP BB
dBBBBBB dBBBBBBB dBP dB' dBBBBBBB dBP dBP

__
_________ ____________ | | __
/ ___\__ \\_ __ \__ \ | |/ /
/ /_/ > __ \| | \// __ \| <
\___ (____ /__| (____ /__|_ \
/_____/ \/ \/ \/

░▒▓██████▓▒░ ░▒▓██████▓▒░░▒▓███████▓▒░ ░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
░▒▓█▓▒▒▓███▓▒░▒▓████████▓▒░▒▓███████▓▒░░▒▓████████▓▒░▒▓███████▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░

____ _ ____ _ _ __
U /"___|uU /"\ uU | _"\ u U /"\ u |"|/ /
\| | _ / \/ _ \/ \| |_) |/ \/ _ \/ | ' /
| |_| | / ___ \ | _ < / ___ \ U/| . \\u
\____| /_/ \_\ |_| \_\ /_/ \_\ |_|\_\
_)(|_ \\ >> // \\_ \\ >>,-,>> \\,-.
(__)__) (__) (__)(__) (__)(__) (__)\.) (_/

▄████ ▄▄▄ ██▀███ ▄▄▄ ██ ▄█▀
██▒ ▀█▒▒████▄ ▓██ ▒ ██▒▒████▄ ██▄█▒
▒██░▄▄▄░▒██ ▀█▄ ▓██ ░▄█ ▒▒██ ▀█▄ ▓███▄░
░▓█ ██▓░██▄▄▄▄██ ▒██▀▀█▄ ░██▄▄▄▄██ ▓██ █▄
░▒▓███▀▒ ▓█ ▓██▒░██▓ ▒██▒ ▓█ ▓██▒▒██▒ █▄
░▒ ▒ ▒▒ ▓▒█░░ ▒▓ ░▒▓░ ▒▒ ▓▒█░▒ ▒▒ ▓▒
░ ░ ▒ ▒▒ ░ ░▒ ░ ▒░ ▒ ▒▒ ░░ ░▒ ▒░
░ ░ ░ ░ ▒ ░░ ░ ░ ▒ ░ ░░ ░
░ ░ ░ ░ ░ ░░ ░

▄▄ • ▄▄▄· ▄▄▄ ▄▄▄· ▄ •▄
▐█ ▀ ▪▐█ ▀█ ▀▄ █·▐█ ▀█ █▌▄▌▪
▄█ ▀█▄▄█▀▀█ ▐▀▀▄ ▄█▀▀█ ▐▀▀▄·
▐█▄▪▐█▐█ ▪▐▌▐█•█▌▐█ ▪▐▌▐█.█▌
·▀▀▀▀ ▀ ▀ .▀ ▀ ▀ ▀ ·▀ ▀

#### ## ##### ## # #
# # # # # # # # # #
# # # # # # # ####
# ### ###### ##### ###### # #
# # # # # # # # # #
#### # # # # # # # #

.,-:::::/ :::. :::::::.. :::. ::: .
,;;-'````' ;;`;; ;;;;``;;;; ;;`;; ;;; .;;,.
[[[ [[[[[[/,[[ '[[, [[[,/[[[' ,[[ '[[, [[[[[/'
"$$c. "$$c$$$cc$$$c $$$$$$c c$$$cc$$$c _$$$$,
`Y8bo,,,o88o888 888,888b "88bo,888 888,"888"88o,
`'YMUP"YMMYMM ""` MMMM "W" YMM ""` MMM "MMP"

__
.-----.---.-.----.---.-| |--.
| _ | _ | _| _ | <
|___ |___._|__| |___._|__|__|
|_____|


G:
.Gt j. E#, :
j#W: .. EW, .. E#t .GE
;K#f ;W, E##j ;W, E#t j#K;
.G#D. j##, E###D. j##, E#GK#f
j#K; G###, E#jG#W; G###, E##D.
,K#f ,GD; :E####, E#t t##f :E####, E##Wi
j#Wi E#t ;W#DG##, E#t :K#E: ;W#DG##, E#jL#D:
.G#D: E#t j###DW##, E#KDDDD###i j###DW##, E#t ,K#j
,K#fK#t G##i,,G##, E#f,t#Wi,,, G##i,,G##, E#t jD
j###t :K#K: L##, E#t ;#W: :K#K: L##, j#t
.G#t ;##D. L##, DWi ,KK: ;##D. L##, ,;
;; ,,, .,, ,,, .,,


__
/\ \
__ __ _ __ __ \ \ \/'\
/'_ `\ /'__`\ /\`'__\/'__`\ \ \ , <
/\ \L\ \/\ \L\.\_\ \ \//\ \L\.\_\ \ \\`\
\ \____ \ \__/.\_\\ \_\\ \__/.\_\\ \_\ \_\
\/___L\ \/__/\/_/ \/_/ \/__/\/_/ \/_/\/_/
/\____/
\_/__/

dP
88
.d8888b. .d8888b. 88d888b. .d8888b. 88 .dP
88' `88 88' `88 88' `88 88' `88 88888"
88. .88 88. .88 88 88. .88 88 `8b.
`8888P88 `88888P8 dP `88888P8 dP `YP
.88
d8888P

Loading