aiverify-moonshot 0.4.4__py3-none-any.whl → 0.4.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {aiverify_moonshot-0.4.4.dist-info → aiverify_moonshot-0.4.6.dist-info}/METADATA +3 -2
  2. {aiverify_moonshot-0.4.4.dist-info → aiverify_moonshot-0.4.6.dist-info}/RECORD +28 -26
  3. moonshot/__main__.py +125 -54
  4. moonshot/integrations/cli/benchmark/cookbook.py +226 -42
  5. moonshot/integrations/cli/benchmark/datasets.py +53 -8
  6. moonshot/integrations/cli/benchmark/metrics.py +48 -7
  7. moonshot/integrations/cli/benchmark/recipe.py +283 -42
  8. moonshot/integrations/cli/benchmark/result.py +73 -30
  9. moonshot/integrations/cli/benchmark/run.py +43 -11
  10. moonshot/integrations/cli/benchmark/runner.py +29 -20
  11. moonshot/integrations/cli/cli_errors.py +511 -0
  12. moonshot/integrations/cli/common/connectors.py +137 -6
  13. moonshot/integrations/cli/common/dataset.py +66 -13
  14. moonshot/integrations/cli/common/prompt_template.py +38 -2
  15. moonshot/integrations/cli/redteam/session.py +126 -43
  16. moonshot/integrations/web_api/app.py +1 -1
  17. moonshot/integrations/web_api/routes/bookmark.py +7 -4
  18. moonshot/src/api/api_bookmark.py +6 -6
  19. moonshot/src/bookmark/bookmark.py +119 -60
  20. moonshot/src/bookmark/bookmark_arguments.py +10 -0
  21. moonshot/src/configs/env_variables.py +7 -3
  22. moonshot/src/messages_constants.py +40 -0
  23. moonshot/src/runners/runner.py +1 -1
  24. moonshot/src/runs/run.py +7 -0
  25. {aiverify_moonshot-0.4.4.dist-info → aiverify_moonshot-0.4.6.dist-info}/WHEEL +0 -0
  26. {aiverify_moonshot-0.4.4.dist-info → aiverify_moonshot-0.4.6.dist-info}/licenses/AUTHORS.md +0 -0
  27. {aiverify_moonshot-0.4.4.dist-info → aiverify_moonshot-0.4.6.dist-info}/licenses/LICENSE.md +0 -0
  28. {aiverify_moonshot-0.4.4.dist-info → aiverify_moonshot-0.4.6.dist-info}/licenses/NOTICES.md +0 -0
@@ -5,6 +5,12 @@ from rich.console import Console
5
5
  from rich.table import Table
6
6
 
7
7
  from moonshot.api import api_get_all_run
8
+ from moonshot.integrations.cli.cli_errors import (
9
+ ERROR_BENCHMARK_LIST_RUNS_FIND_VALIDATION,
10
+ ERROR_BENCHMARK_LIST_RUNS_PAGINATION_VALIDATION,
11
+ ERROR_BENCHMARK_LIST_RUNS_PAGINATION_VALIDATION_1,
12
+ ERROR_BENCHMARK_VIEW_RUN_RUNNER_ID_VALIDATION,
13
+ )
8
14
  from moonshot.integrations.cli.common.display_helper import (
9
15
  display_view_list_format,
10
16
  display_view_str_format,
@@ -22,23 +28,41 @@ def list_runs(args) -> list | None:
22
28
  List all runs.
23
29
 
24
30
  This function retrieves all available runs by calling the api_get_all_run function from the
25
- moonshot.api module. It then calls the _display_runs function to present the retrieved run information
26
- in a user-friendly format on the command line interface. If an exception occurs during the retrieval
27
- or display process, it prints an error message.
31
+ moonshot.api module. It then filters the runs based on the provided keyword and pagination arguments.
32
+ If there are no runs, it prints a message indicating that no runs were found.
28
33
 
29
34
  Args:
30
- args: A namespace object from argparse. It should have an optional attribute:
31
- find (str): Optional field to find run(s) with a keyword.
32
- pagination (str): Optional field to paginate runs.
35
+ args (argparse.Namespace): The arguments provided to the command line interface.
36
+ find (str): Optional field to find run(s) with a keyword.
37
+ pagination (str): Optional field to paginate runs.
33
38
 
34
39
  Returns:
35
- list | None: A list of Run or None if there is no result.
40
+ list | None: A list of runs or None if there are no runs.
36
41
  """
37
42
 
38
43
  try:
44
+ if args.find is not None:
45
+ if not isinstance(args.find, str) or not args.find:
46
+ raise TypeError(ERROR_BENCHMARK_LIST_RUNS_FIND_VALIDATION)
47
+
48
+ if args.pagination is not None:
49
+ if not isinstance(args.pagination, str) or not args.pagination:
50
+ raise TypeError(ERROR_BENCHMARK_LIST_RUNS_PAGINATION_VALIDATION)
51
+ try:
52
+ pagination = literal_eval(args.pagination)
53
+ if not (
54
+ isinstance(pagination, tuple)
55
+ and len(pagination) == 2
56
+ and all(isinstance(i, int) for i in pagination)
57
+ ):
58
+ raise ValueError(ERROR_BENCHMARK_LIST_RUNS_PAGINATION_VALIDATION_1)
59
+ except (ValueError, SyntaxError):
60
+ raise ValueError(ERROR_BENCHMARK_LIST_RUNS_PAGINATION_VALIDATION_1)
61
+ else:
62
+ pagination = ()
63
+
39
64
  runner_run_info = api_get_all_run()
40
65
  keyword = args.find.lower() if args.find else ""
41
- pagination = literal_eval(args.pagination) if args.pagination else ()
42
66
 
43
67
  if runner_run_info:
44
68
  filtered_runs_list = filter_data(runner_run_info, keyword, pagination)
@@ -51,6 +75,7 @@ def list_runs(args) -> list | None:
51
75
 
52
76
  except Exception as e:
53
77
  print(f"[list_runs]: {str(e)}")
78
+ return None
54
79
 
55
80
 
56
81
  def view_run(args) -> None:
@@ -62,13 +87,20 @@ def view_run(args) -> None:
62
87
  user-friendly format.
63
88
 
64
89
  Args:
65
- args: A namespace object from argparse. It should have the following attribute:
66
- runner (str): The identifier of the runner whose runs are to be viewed.
90
+ args (argparse.Namespace): The arguments provided to the command line interface.
91
+ runner_id (str): The identifier of the runner whose runs are to be viewed.
67
92
 
68
93
  Returns:
69
94
  None
70
95
  """
71
96
  try:
97
+ if (
98
+ not isinstance(args.runner_id, str)
99
+ or not args.runner_id
100
+ or args.runner_id is None
101
+ ):
102
+ raise TypeError(ERROR_BENCHMARK_VIEW_RUN_RUNNER_ID_VALIDATION)
103
+
72
104
  runner_run_info = api_get_all_run(args.runner_id)
73
105
  _display_runs(runner_run_info)
74
106
  except Exception as e:
@@ -151,7 +183,7 @@ def _display_runs(runs_list: list):
151
183
  # ------------------------------------------------------------------------------
152
184
  # View run arguments
153
185
  view_run_args = cmd2.Cmd2ArgumentParser(
154
- description="View a runner runs.",
186
+ description="View a runner's runs.",
155
187
  epilog="Example:\n view_run my-new-cookbook-runner",
156
188
  )
157
189
  view_run_args.add_argument("runner_id", type=str, help="Name of the runner")
@@ -10,6 +10,10 @@ from moonshot.api import (
10
10
  api_load_session,
11
11
  api_read_runner,
12
12
  )
13
+ from moonshot.integrations.cli.cli_errors import (
14
+ ERROR_BENCHMARK_DELETE_RUNNER_RUNNER_VALIDATION,
15
+ ERROR_BENCHMARK_VIEW_RUNNER_RUNNER_VALIDATION,
16
+ )
13
17
  from moonshot.integrations.cli.common.display_helper import (
14
18
  display_view_list_format,
15
19
  display_view_str_format,
@@ -25,9 +29,9 @@ def list_runners() -> None:
25
29
  """
26
30
  List all runners.
27
31
 
28
- This function retrieves and displays information about all runners, including their associated runs and session
29
- information. It fetches the data using the api_get_all_runner, api_get_all_run, and api_get_available_session_info
30
- functions, then calls the display_runners function to present it in a user-friendly format.
32
+ Retrieves and displays information about all runners, including their associated runs and session
33
+ information. Fetches the data using the api_get_all_runner, api_get_all_run, and api_get_available_session_info
34
+ functions, then calls the _display_runners function to present it in a user-friendly format.
31
35
 
32
36
  Returns:
33
37
  None
@@ -36,7 +40,7 @@ def list_runners() -> None:
36
40
  runner_info = api_get_all_runner()
37
41
  runner_run_info = api_get_all_run()
38
42
  _, runner_session_info = api_get_available_session_info()
39
- display_runners(runner_info, runner_run_info, runner_session_info)
43
+ _display_runners(runner_info, runner_run_info, runner_session_info)
40
44
  except Exception as e:
41
45
  print(f"[list_runners]: {str(e)}")
42
46
 
@@ -45,22 +49,25 @@ def view_runner(args) -> None:
45
49
  """
46
50
  View a specific runner.
47
51
 
48
- This function retrieves and displays information about a specific runner, including its associated runs and session
49
- information. It uses the runner identifier provided in the arguments to fetch the data and then calls the
50
- display_runners function to present it in a user-friendly format.
52
+ Retrieves and displays information about a specific runner, including its associated runs and session
53
+ information. Uses the runner identifier provided in the arguments to fetch the data and then calls the
54
+ _display_runners function to present it in a user-friendly format.
51
55
 
52
56
  Args:
53
- args: A namespace object from argparse. It should have the following attribute:
57
+ args (argparse.Namespace): A namespace object from argparse. It should have the following attribute:
54
58
  runner (str): The identifier of the runner to view.
55
59
 
56
60
  Returns:
57
61
  None
58
62
  """
59
63
  try:
64
+ if not isinstance(args.runner, str) or not args.runner or args.runner is None:
65
+ raise TypeError(ERROR_BENCHMARK_VIEW_RUNNER_RUNNER_VALIDATION)
66
+
60
67
  runner_info = api_read_runner(args.runner)
61
68
  runner_run_info = api_get_all_run(args.runner)
62
69
  runner_session_info = api_load_session(args.runner)
63
- display_runners([runner_info], runner_run_info, [runner_session_info])
70
+ _display_runners([runner_info], runner_run_info, [runner_session_info])
64
71
  except Exception as e:
65
72
  print(f"[view_runner]: {str(e)}")
66
73
 
@@ -69,13 +76,13 @@ def delete_runner(args) -> None:
69
76
  """
70
77
  Delete a runner.
71
78
 
72
- This function deletes a runner with the specified identifier. It prompts the user for confirmation before proceeding
79
+ Deletes a runner with the specified identifier. Prompts the user for confirmation before proceeding
73
80
  with the deletion. If the user confirms, it calls the api_delete_runner function from the moonshot.api module to
74
81
  delete the runner. If the deletion is successful, it prints a confirmation message. If an exception occurs, it
75
82
  prints an error message.
76
83
 
77
84
  Args:
78
- args: A namespace object from argparse. It should have the following attribute:
85
+ args (argparse.Namespace): A namespace object from argparse. It should have the following attribute:
79
86
  runner (str): The identifier of the runner to delete.
80
87
 
81
88
  Returns:
@@ -88,7 +95,11 @@ def delete_runner(args) -> None:
88
95
  if confirmation.lower() != "y":
89
96
  console.print("[bold yellow]Runner deletion cancelled.[/]")
90
97
  return
98
+
91
99
  try:
100
+ if args.runner is None or not isinstance(args.runner, str) or not args.runner:
101
+ raise ValueError(ERROR_BENCHMARK_DELETE_RUNNER_RUNNER_VALIDATION)
102
+
92
103
  api_delete_runner(args.runner)
93
104
  print("[delete_runner]: Runner deleted.")
94
105
  except Exception as e:
@@ -98,24 +109,22 @@ def delete_runner(args) -> None:
98
109
  # ------------------------------------------------------------------------------
99
110
  # Helper functions: Display on cli
100
111
  # ------------------------------------------------------------------------------
101
- def display_runners(
112
+ def _display_runners(
102
113
  runner_list: list, runner_run_info_list: list, runner_session_info_list: list
103
114
  ) -> None:
104
115
  """
105
116
  Display runners in a table format.
106
117
 
107
- This function takes lists of runner information, run information, and session information, then displays them in a
118
+ Takes lists of runner information, run information, and session information, then displays them in a
108
119
  table format on the command line interface. Each runner is listed with details such as the runner's ID, name,
109
120
  description, number of runs, number of sessions, database file, and endpoints.
110
121
 
111
122
  Args:
112
- runner_list: A list of dictionaries, where each dictionary contains information about a runner.
113
-
114
- runner_run_info_list: A list of dictionaries, where each dictionary contains information about a run
115
- associated with a runner.
116
-
117
- runner_session_info_list: A list of dictionaries, where each dictionary contains information about a session
118
- associated with a runner.
123
+ runner_list (list): A list of dictionaries, where each dictionary contains information about a runner.
124
+ runner_run_info_list (list): A list of dictionaries, where each dictionary contains information about a run
125
+ associated with a runner.
126
+ runner_session_info_list (list): A list of dictionaries, where each dictionary contains information about a
127
+ session associated with a runner.
119
128
 
120
129
  Returns:
121
130
  None