Skip to content

Commit 2e8563b

Browse files
style: auto-format & lint via ruff
1 parent 7deabaa commit 2e8563b

24 files changed

Lines changed: 164 additions & 131 deletions

spikee/attacks/echo_chamber.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,6 @@ def attack(
10821082
last_message_id = sentences_message_id
10831083
continue
10841084

1085-
10861085
return (
10871086
conversation.get_attempt_total(),
10881087
False,

spikee/cli.py

Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def main():
100100

101101
subparsers = parser.add_subparsers(dest="command", help="Sub-commands")
102102

103-
#region === [INIT] Sub-command (NEW) ==============================================
103+
# region === [INIT] Sub-command (NEW) ==============================================
104104
parser_init = subparsers.add_parser(
105105
"init", help="Initialize a local SPIKEE workspace"
106106
)
@@ -120,9 +120,9 @@ def main():
120120
action="store_true",
121121
help="Include the built-in web viewer in the local workspace",
122122
)
123-
#endregion
123+
# endregion
124124

125-
#region === [GENERATE] Sub-command ===============================================
125+
# region === [GENERATE] Sub-command ===============================================
126126
parser_generate = subparsers.add_parser("generate", help="Generate a dataset")
127127
subparsers_generate = parser_generate.add_subparsers(
128128
dest="generate_command", help="Generation sub-commands"
@@ -261,9 +261,9 @@ def main():
261261
default=None,
262262
help='Plugin-specific options as "plugin1:option1,option2;plugin2:option2"',
263263
)
264-
#endregion
264+
# endregion
265265

266-
#region === [TEST] Sub-command ===================================================
266+
# region === [TEST] Sub-command ===================================================
267267
parser_test = subparsers.add_parser(
268268
"test", help="Test the dataset against a target"
269269
)
@@ -373,9 +373,9 @@ def main():
373373
action="store_true",
374374
help="Create new results file, do not attempt to resume",
375375
)
376-
#endregion
376+
# endregion
377377

378-
#region === [RESULTS] Sub-command ================================================
378+
# region === [RESULTS] Sub-command ================================================
379379
parser_results = subparsers.add_parser("results", help="Analyze or convert results")
380380
subparsers_results = parser_results.add_subparsers(
381381
dest="results_command", help="Results sub-commands"
@@ -526,9 +526,9 @@ def main():
526526
parser_dataset_comparison.add_argument(
527527
"--tag", default=None, help="Include a tag at the end of the results filename"
528528
)
529-
#endregion
529+
# endregion
530530

531-
#region === [Viewer] Sub-command ================================================
531+
# region === [Viewer] Sub-command ================================================
532532
parser_viewer = subparsers.add_parser("viewer", help="Launch local web viewers")
533533
subparsers_viewer = parser_viewer.add_subparsers(
534534
dest="viewer_command", help="Viewer sub-commands"
@@ -587,9 +587,9 @@ def main():
587587
parser_convert_to_excel.add_argument(
588588
"--result-file", type=str, required=True, help="Path to the results JSONL file"
589589
)
590-
#endregion
590+
# endregion
591591

592-
#region === [LIST] Sub-command ================================================
592+
# region === [LIST] Sub-command ================================================
593593
parser_list = subparsers.add_parser(
594594
"list",
595595
help="List seeds, datasets, judges, targets, plugins, attacks, or providers",
@@ -614,38 +614,60 @@ def main():
614614
action="store_true",
615615
help="Include descriptions of modules where available",
616616
)
617-
#endregion
617+
# endregion
618618

619-
#region === [DEBUG] Sub-command ================================================
620-
parser_debug = subparsers.add_parser("debug", help="Debugging and testing utilities")
619+
# region === [DEBUG] Sub-command ================================================
620+
parser_debug = subparsers.add_parser(
621+
"debug", help="Debugging and testing utilities"
622+
)
623+
624+
debug_subparsers = parser_debug.add_subparsers(
625+
dest="debug_command", help="Debugging sub-commands"
626+
)
621627

622-
debug_subparsers = parser_debug.add_subparsers(dest="debug_command", help="Debugging sub-commands")
623-
624628
# -- module debug --
625629
module_subparser = debug_subparsers.add_parser("module", help="Debug module")
626-
module_subparsers = module_subparser.add_subparsers(dest="module_type", help="Type of module to debug")
630+
module_subparsers = module_subparser.add_subparsers(
631+
dest="module_type", help="Type of module to debug"
632+
)
627633

628-
target_subparser = module_subparsers.add_parser("targets", help="Debug target module")
634+
target_subparser = module_subparsers.add_parser(
635+
"targets", help="Debug target module"
636+
)
629637
judge_subparser = module_subparsers.add_parser("judges", help="Debug judge module")
630-
plugin_subparser = module_subparsers.add_parser("plugins", help="Debug plugin module")
631-
attack_subparser = module_subparsers.add_parser("attacks", help="Debug attack module")
632-
provider_subparser = module_subparsers.add_parser("providers", help="Debug provider module")
638+
plugin_subparser = module_subparsers.add_parser(
639+
"plugins", help="Debug plugin module"
640+
)
641+
attack_subparser = module_subparsers.add_parser(
642+
"attacks", help="Debug attack module"
643+
)
644+
provider_subparser = module_subparsers.add_parser(
645+
"providers", help="Debug provider module"
646+
)
633647

634-
for subparser in [target_subparser, judge_subparser, plugin_subparser, attack_subparser, provider_subparser]:
648+
for subparser in [
649+
target_subparser,
650+
judge_subparser,
651+
plugin_subparser,
652+
attack_subparser,
653+
provider_subparser,
654+
]:
635655
subparser.add_argument(
636-
"-m", "--module",
656+
"-m",
657+
"--module",
637658
type=str,
638659
required=True,
639660
help="Name of the module to debug",
640661
)
641662
subparser.add_argument(
642-
"-i", "--input",
663+
"-i",
664+
"--input",
643665
type=str,
644666
default="",
645667
required=True,
646668
help="Input string for the module (if applicable)",
647669
)
648-
670+
649671
# Target-specific arguments
650672
target_subparser.add_argument(
651673
"--system-message",
@@ -674,7 +696,8 @@ def main():
674696
help="Additional arguments for the judge module (if applicable)",
675697
)
676698
judge_subparser.add_argument(
677-
"-o", "--output",
699+
"-o",
700+
"--output",
678701
type=str,
679702
default="",
680703
required=True,
@@ -715,7 +738,7 @@ def main():
715738
default=None,
716739
help="Options to pass to the attack module (if applicable)",
717740
)
718-
741+
719742
# Provider-specific arguments
720743
provider_subparser.add_argument(
721744
"--max-tokens",
@@ -730,7 +753,7 @@ def main():
730753
help="Temperature for the provider module (if applicable)",
731754
)
732755

733-
#endregion
756+
# endregion
734757

735758
args = convert_to_new_args(parser.parse_args())
736759

@@ -744,8 +767,11 @@ def main():
744767
if args.command == "init":
745768
# Guard against running init inside the spikee source package directory
746769
cwd = Path(os.getcwd())
747-
if (cwd / "cli.py").exists() and (cwd / "tester.py").exists() and (cwd / "generator.py").exists():
748-
770+
if (
771+
(cwd / "cli.py").exists()
772+
and (cwd / "tester.py").exists()
773+
and (cwd / "generator.py").exists()
774+
):
749775
if not args.force:
750776
print(
751777
"[init] ERROR: It looks like you are running 'spikee init' within the Spikee sourcecode directory (e.g. ./spikee/)."
@@ -759,7 +785,7 @@ def main():
759785
print("[init] spikee init\n")
760786
print("[init] Use --force to override warnings.")
761787
sys.exit(1)
762-
788+
763789
else:
764790
print(
765791
"[init] WARNING: You are running 'spikee init' inside the Spikee sourcecode directory with --force. This will overwrite Spikee's source code with workspace files. Proceeding with initialization..."
@@ -816,7 +842,7 @@ def main():
816842
list_providers(args)
817843
else:
818844
parser_list.print_help()
819-
845+
820846
elif args.command == "debug":
821847
if args.debug_command == "module":
822848
if args.module_type == "targets":
@@ -954,4 +980,4 @@ def copy_builtin_modules(include_option, force=False):
954980
print(f"[init] No built-in {module_type} were copied")
955981

956982
except Exception as e:
957-
print(f"[init] Error processing {module_type}: {e}")
983+
print(f"[init] Error processing {module_type}: {e}")

spikee/data/workspace/providers/sample_provider.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def setup(
5050
def get_description(self) -> ModuleDescriptionHint:
5151
return [ModuleTag.LLM], "Sample provider for OpenAI API based AnyLLM providers."
5252

53-
def _invoke(
54-
self, messages: MessageHint
55-
) -> AIMessage:
53+
def _invoke(self, messages: MessageHint) -> AIMessage:
5654
"""Return Mock Message"""
5755

5856
# upgraded_messages = agent_framework_message_translation(upgrade_messages(messages))

spikee/debug.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from spikee.judge import call_judge
2323
from spikee.utilities.llm import get_llm
2424

25+
2526
def debug_module_target(args):
2627
"""
2728
Debug a target module by sending a single input and printing the response.
@@ -41,13 +42,16 @@ def debug_module_target(args):
4142

4243
if args.system_message:
4344
target_args["system_message"] = args.system_message
44-
45+
4546
if args.target_options:
4647
target_args["target_options"] = args.target_options
4748

4849
response = target.process_input(args.input, **target_args)
4950

50-
print(f"[{target.__class__.__name__}] Response: {get_content(response) if response else 'No response'}")
51+
print(
52+
f"[{target.__class__.__name__}] Response: {get_content(response) if response else 'No response'}"
53+
)
54+
5155

5256
def debug_module_judge(args):
5357
"""
@@ -72,7 +76,7 @@ def debug_module_judge(args):
7276

7377
if args.output:
7478
judge_args["llm_output"] = args.output
75-
79+
7680
else:
7781
raise ValueError("Judges require an output argument to evaluate the response.")
7882

@@ -81,11 +85,12 @@ def debug_module_judge(args):
8185

8286
if args.judge_args:
8387
judge_args["judge_args"] = args.judge_args
84-
88+
8589
response = judge.judge(args.input, **judge_args)
8690

8791
print(f"[{judge.__class__.__name__}] Judge Result: {response}")
8892

93+
8994
def debug_module_plugin(args):
9095
"""
9196
Debug a plugin module by transforming an input and printing the result.
@@ -112,7 +117,10 @@ def debug_module_plugin(args):
112117

113118
response = plugin.transform(args.input, **plugin_args)
114119

115-
print(f"[{plugin.__class__.__name__}] Plugin Response: {get_content(response) if response else 'No response'}")
120+
print(
121+
f"[{plugin.__class__.__name__}] Plugin Response: {get_content(response) if response else 'No response'}"
122+
)
123+
116124

117125
def debug_module_attack(args):
118126
"""
@@ -151,14 +159,16 @@ def debug_module_attack(args):
151159
entry = json.loads(base64.b64decode(args.input).decode("utf-8"))
152160
except (json.JSONDecodeError, base64.binascii.Error):
153161
raise ValueError("Attack input must be a valid base64-encoded JSON entry.")
154-
162+
155163
missing_entry_args = []
156164
for arg in ["id", "long_id", "content", "content_type", "judge_name", "judge_args"]:
157165
if arg not in entry:
158166
missing_entry_args.append(arg)
159-
167+
160168
if len(missing_entry_args) > 0:
161-
raise ValueError(f"Missing required entry arguments for attack: {', '.join(missing_entry_args)}")
169+
raise ValueError(
170+
f"Missing required entry arguments for attack: {', '.join(missing_entry_args)}"
171+
)
162172

163173
attack_args = {}
164174

@@ -173,7 +183,10 @@ def debug_module_attack(args):
173183

174184
response = attack.attack(entry, **attack_args)
175185

176-
print(f"[{attack.__class__.__name__}] Attack Response: {str(response) if response else 'No response'}")
186+
print(
187+
f"[{attack.__class__.__name__}] Attack Response: {str(response) if response else 'No response'}"
188+
)
189+
177190

178191
def debug_module_provider(args):
179192
"""
@@ -195,7 +208,9 @@ def debug_module_provider(args):
195208
provider_args = {}
196209

197210
if args.module is None:
198-
raise ValueError("Providers require a model argument to specify the LLM model to use.")
211+
raise ValueError(
212+
"Providers require a model argument to specify the LLM model to use."
213+
)
199214

200215
provider_args["max_tokens"] = args.max_tokens
201216
provider_args["temperature"] = args.temperature
@@ -206,11 +221,14 @@ def debug_module_provider(args):
206221
)
207222

208223
if provider is None:
209-
raise ValueError("No provider could be loaded. Please check the module name and ensure it is a valid LLM provider.")
224+
raise ValueError(
225+
"No provider could be loaded. Please check the module name and ensure it is a valid LLM provider."
226+
)
210227

211228
response = provider.invoke(args.input)
212229

213230
response = response.content
214231

215-
print(f"[{provider.__class__.__name__}] Provider Response: {get_content(response) if response else 'No response'}")
216-
232+
print(
233+
f"[{provider.__class__.__name__}] Provider Response: {get_content(response) if response else 'No response'}"
234+
)

spikee/plugins/homoglyph.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ def plugin_transform(self, text: str, plugin_option: str = "") -> str:
125125

126126
rng = random.Random(seed)
127127
return "".join(
128-
self.CONFUSABLES[c] if (c in self.CONFUSABLES and rng.random() < ratio) else c
128+
self.CONFUSABLES[c]
129+
if (c in self.CONFUSABLES and rng.random() < ratio)
130+
else c
129131
for c in text
130132
)
131133

spikee/providers/aws_transcribe_stt.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ async def _write_chunks():
160160

161161
return " ".join(transcript_parts).strip()
162162

163-
def _invoke(
164-
self, messages: MessageHint
165-
) -> AIMessage:
163+
def _invoke(self, messages: MessageHint) -> AIMessage:
166164
"""Invoke AWS Transcribe streaming STT with base64-encoded audio. Returns transcribed text."""
167165

168166
msg, _ = single_message(messages)

spikee/providers/azure_openai.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ def setup(
6262
def get_description(self) -> ModuleDescriptionHint:
6363
return [ModuleTag.LLM], "LLM Provider for Azure OpenAI models via any-llm."
6464

65-
def _invoke(
66-
self, messages: MessageHint
67-
) -> AIMessage:
65+
def _invoke(self, messages: MessageHint) -> AIMessage:
6866
"""Invoke AnyLLM Azure OpenAI LLM with the provided messages."""
6967

7068
formatted_messages = format_messages(messages)

spikee/providers/bedrock.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ def setup(
112112
def get_description(self) -> ModuleDescriptionHint:
113113
return [ModuleTag.LLM], "LLM Provider for AWS Bedrock models via any-llm."
114114

115-
def _invoke(
116-
self, messages: MessageHint
117-
) -> AIMessage:
115+
def _invoke(self, messages: MessageHint) -> AIMessage:
118116
"""Invoke AnyLLM Bedrock LLM with the provided messages."""
119117

120118
formatted_messages = format_messages(messages)

0 commit comments

Comments
 (0)