aiverify-moonshot 0.4.11__py3-none-any.whl → 0.5.1__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.
- {aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.1.dist-info}/METADATA +6 -5
- {aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.1.dist-info}/RECORD +39 -39
- {aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.1.dist-info}/WHEEL +1 -1
- moonshot/integrations/cli/benchmark/cookbook.py +1 -5
- moonshot/integrations/cli/benchmark/recipe.py +1 -5
- moonshot/integrations/cli/cli_errors.py +3 -0
- moonshot/integrations/cli/common/connectors.py +22 -10
- moonshot/integrations/cli/common/dataset.py +5 -6
- moonshot/integrations/web_api/app.py +1 -1
- moonshot/integrations/web_api/schemas/cookbook_response_model.py +1 -1
- moonshot/integrations/web_api/schemas/endpoint_create_dto.py +1 -0
- moonshot/integrations/web_api/schemas/recipe_response_model.py +1 -1
- moonshot/integrations/web_api/services/cookbook_service.py +52 -21
- moonshot/integrations/web_api/services/endpoint_service.py +1 -0
- moonshot/integrations/web_api/services/recipe_service.py +36 -15
- moonshot/src/api/api_bookmark.py +16 -5
- moonshot/src/api/api_connector.py +3 -3
- moonshot/src/api/api_connector_endpoint.py +6 -3
- moonshot/src/api/api_context_strategy.py +2 -2
- moonshot/src/api/api_cookbook.py +6 -6
- moonshot/src/api/api_dataset.py +5 -5
- moonshot/src/api/api_environment_variables.py +3 -0
- moonshot/src/api/api_metrics.py +1 -1
- moonshot/src/api/api_prompt_template.py +9 -0
- moonshot/src/api/api_recipe.py +3 -3
- moonshot/src/api/api_red_teaming.py +4 -8
- moonshot/src/api/api_result.py +10 -6
- moonshot/src/api/api_run.py +3 -3
- moonshot/src/api/api_runner.py +7 -6
- moonshot/src/api/api_session.py +11 -7
- moonshot/src/connectors/connector.py +121 -58
- moonshot/src/connectors/connector_prompt_arguments.py +7 -4
- moonshot/src/connectors/connector_response.py +5 -10
- moonshot/src/connectors_endpoints/connector_endpoint.py +32 -20
- moonshot/src/connectors_endpoints/connector_endpoint_arguments.py +4 -1
- moonshot/src/messages_constants.py +85 -3
- {aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.1.dist-info}/licenses/AUTHORS.md +0 -0
- {aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.1.dist-info}/licenses/LICENSE.md +0 -0
- {aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.1.dist-info}/licenses/NOTICES.md +0 -0
|
@@ -85,7 +85,7 @@ class RecipeService(BaseService):
|
|
|
85
85
|
filtered_recipes.sort(key=lambda x: x.id)
|
|
86
86
|
|
|
87
87
|
for recipe in filtered_recipes:
|
|
88
|
-
recipe.
|
|
88
|
+
recipe.required_config = get_metric_dependency_in_recipe(recipe)
|
|
89
89
|
|
|
90
90
|
return filtered_recipes
|
|
91
91
|
|
|
@@ -157,28 +157,49 @@ def get_total_prompt_in_recipe(recipe: Recipe) -> tuple[int, int]:
|
|
|
157
157
|
|
|
158
158
|
return total_prompt_count, int(recipe.stats.get("num_of_datasets", 0))
|
|
159
159
|
|
|
160
|
+
|
|
160
161
|
@staticmethod
|
|
161
|
-
def
|
|
162
|
+
def get_metric_dependency_in_recipe(recipe: Recipe) -> dict | None:
|
|
162
163
|
"""
|
|
163
|
-
Retrieve
|
|
164
|
+
Retrieve endpoint and configuration dependencies for a given recipe.
|
|
164
165
|
|
|
165
|
-
This function
|
|
166
|
-
|
|
167
|
-
of endpoint dependencies.
|
|
166
|
+
This function gathers all available metrics along with their endpoints and configurations,
|
|
167
|
+
then identifies and compiles the dependencies based on the metrics present in the provided recipe.
|
|
168
168
|
|
|
169
169
|
Args:
|
|
170
|
-
recipe (Recipe): The recipe object containing
|
|
170
|
+
recipe (Recipe): The recipe object containing metrics information.
|
|
171
171
|
|
|
172
172
|
Returns:
|
|
173
|
-
list[str] | None: A
|
|
173
|
+
dict[str, dict[str, list[str]]] | None: A dictionary with 'endpoints' and 'configurations' as keys,
|
|
174
|
+
where 'endpoints' is a list of endpoint dependencies and 'configurations' is a dictionary of configuration
|
|
175
|
+
dependencies. Returns None if no dependencies are found.
|
|
174
176
|
"""
|
|
175
177
|
metrics = recipe.metrics
|
|
176
178
|
all_metrics = moonshot_api.api_get_all_metric()
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
aggregated_endpoints = set()
|
|
180
|
+
aggregated_configurations = {}
|
|
181
|
+
|
|
179
182
|
for metric in metrics:
|
|
180
|
-
for m in all_metrics
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
metric_data = next((m for m in all_metrics if m["id"] == metric), None)
|
|
184
|
+
if metric_data:
|
|
185
|
+
# Aggregate endpoints
|
|
186
|
+
aggregated_endpoints.update(metric_data.get("endpoints", []))
|
|
187
|
+
|
|
188
|
+
# Aggregate configurations
|
|
189
|
+
for key, value in metric_data.get("configurations", {}).items():
|
|
190
|
+
if key in aggregated_configurations:
|
|
191
|
+
aggregated_configurations[key].extend(
|
|
192
|
+
v for v in value if v not in aggregated_configurations[key]
|
|
193
|
+
)
|
|
194
|
+
else:
|
|
195
|
+
aggregated_configurations[key] = value
|
|
196
|
+
|
|
197
|
+
aggregated_data = {
|
|
198
|
+
"endpoints": list(aggregated_endpoints),
|
|
199
|
+
"configurations": aggregated_configurations,
|
|
200
|
+
}
|
|
201
|
+
return (
|
|
202
|
+
aggregated_data
|
|
203
|
+
if aggregated_data["endpoints"] or aggregated_data["configurations"]
|
|
204
|
+
else None
|
|
205
|
+
)
|
moonshot/src/api/api_bookmark.py
CHANGED
|
@@ -21,10 +21,15 @@ def api_insert_bookmark(
|
|
|
21
21
|
Args:
|
|
22
22
|
name (str): The unique name of the bookmark.
|
|
23
23
|
prompt (str): The associated prompt text for the bookmark.
|
|
24
|
+
prepared_prompt (str): The prepared prompt text for the bookmark.
|
|
24
25
|
response (str): The corresponding response text for the bookmark.
|
|
25
|
-
context_strategy (str): The strategy used for context management in the bookmark.
|
|
26
|
-
prompt_template (str): The template used for generating the prompt.
|
|
27
|
-
attack_module (str): The attack module linked with the bookmark.
|
|
26
|
+
context_strategy (str, optional): The strategy used for context management in the bookmark. Defaults to "".
|
|
27
|
+
prompt_template (str, optional): The template used for generating the prompt. Defaults to "".
|
|
28
|
+
attack_module (str, optional): The attack module linked with the bookmark. Defaults to "".
|
|
29
|
+
metric (str, optional): The metric associated with the bookmark. Defaults to "".
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
dict: A dictionary containing the details of the newly inserted bookmark.
|
|
28
33
|
"""
|
|
29
34
|
# Create a new BookmarkArguments object
|
|
30
35
|
bookmark_args = BookmarkArguments(
|
|
@@ -57,10 +62,10 @@ def api_get_bookmark(bookmark_name: str) -> dict:
|
|
|
57
62
|
Retrieves the details of a specific bookmark by its name.
|
|
58
63
|
|
|
59
64
|
Args:
|
|
60
|
-
bookmark_name (
|
|
65
|
+
bookmark_name (str): The name of the bookmark to retrieve.
|
|
61
66
|
|
|
62
67
|
Returns:
|
|
63
|
-
dict: The bookmark details corresponding to the provided
|
|
68
|
+
dict: The bookmark details corresponding to the provided name.
|
|
64
69
|
"""
|
|
65
70
|
return Bookmark().get_bookmark(bookmark_name)
|
|
66
71
|
|
|
@@ -71,6 +76,9 @@ def api_delete_bookmark(bookmark_name: str) -> dict:
|
|
|
71
76
|
|
|
72
77
|
Args:
|
|
73
78
|
bookmark_name (str): The name of the bookmark to be removed.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
dict: A dictionary containing the details of the deleted bookmark.
|
|
74
82
|
"""
|
|
75
83
|
return Bookmark().delete_bookmark(bookmark_name)
|
|
76
84
|
|
|
@@ -78,6 +86,9 @@ def api_delete_bookmark(bookmark_name: str) -> dict:
|
|
|
78
86
|
def api_delete_all_bookmark() -> dict:
|
|
79
87
|
"""
|
|
80
88
|
Removes all bookmarks from the database.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
dict: A dictionary indicating the result of the delete operation.
|
|
81
92
|
"""
|
|
82
93
|
return Bookmark().delete_all_bookmark()
|
|
83
94
|
|
|
@@ -13,8 +13,8 @@ def api_create_connector_from_endpoint(ep_id: str) -> Connector:
|
|
|
13
13
|
Creates a connector based on the provided endpoint ID.
|
|
14
14
|
|
|
15
15
|
This function retrieves the endpoint arguments using the provided endpoint ID and then creates a connector
|
|
16
|
-
based on those arguments. It utilizes the
|
|
17
|
-
arguments and then calls the
|
|
16
|
+
based on those arguments. It utilizes the ConnectorEndpoint's read method to fetch the endpoint
|
|
17
|
+
arguments and then calls the Connector's create method to initialize and return the connector.
|
|
18
18
|
|
|
19
19
|
Args:
|
|
20
20
|
ep_id (str): The ID of the endpoint for which to create a connector.
|
|
@@ -49,7 +49,7 @@ def api_get_all_connector_type() -> list[str]:
|
|
|
49
49
|
"""
|
|
50
50
|
Retrieves a list of all available connector types.
|
|
51
51
|
|
|
52
|
-
This function calls the
|
|
52
|
+
This function calls the Connector's get_available_items method to retrieve a list of all available
|
|
53
53
|
connector types. It returns the list of connector types.
|
|
54
54
|
|
|
55
55
|
Returns:
|
|
@@ -17,6 +17,7 @@ def api_create_endpoint(
|
|
|
17
17
|
token: str,
|
|
18
18
|
max_calls_per_second: int,
|
|
19
19
|
max_concurrency: int,
|
|
20
|
+
model: str,
|
|
20
21
|
params: dict,
|
|
21
22
|
) -> str:
|
|
22
23
|
"""
|
|
@@ -33,6 +34,7 @@ def api_create_endpoint(
|
|
|
33
34
|
token (str): The token for authentication with the connector.
|
|
34
35
|
max_calls_per_second (int): The maximum number of calls allowed per second.
|
|
35
36
|
max_concurrency (int): The maximum number of concurrent calls allowed.
|
|
37
|
+
model (str): The model used by the connector.
|
|
36
38
|
params (dict): Additional parameters for the connector.
|
|
37
39
|
|
|
38
40
|
Returns:
|
|
@@ -51,6 +53,7 @@ def api_create_endpoint(
|
|
|
51
53
|
token=token,
|
|
52
54
|
max_calls_per_second=max_calls_per_second,
|
|
53
55
|
max_concurrency=max_concurrency,
|
|
56
|
+
model=model,
|
|
54
57
|
params=params,
|
|
55
58
|
created_date="",
|
|
56
59
|
)
|
|
@@ -136,7 +139,7 @@ def api_get_all_endpoint() -> list[dict]:
|
|
|
136
139
|
"""
|
|
137
140
|
Retrieves a list of all available endpoints.
|
|
138
141
|
|
|
139
|
-
This function calls the
|
|
142
|
+
This function calls the ConnectorEndpoint's get_available_items method to retrieve a list of all available
|
|
140
143
|
endpoints and their details. It then converts each ConnectorEndpointArguments object into a dictionary for easier
|
|
141
144
|
consumption by the caller.
|
|
142
145
|
|
|
@@ -151,8 +154,8 @@ def api_get_all_endpoint_name() -> list[str]:
|
|
|
151
154
|
"""
|
|
152
155
|
Retrieves a list of all endpoint names.
|
|
153
156
|
|
|
154
|
-
This function calls the
|
|
155
|
-
endpoint names. It extracts the names from the tuple returned by
|
|
157
|
+
This function calls the ConnectorEndpoint's get_available_items method to retrieve a list of all available
|
|
158
|
+
endpoint names. It extracts the names from the tuple returned by get_available_items, which contains a list
|
|
156
159
|
of endpoint names and a list of ConnectorEndpointArguments objects.
|
|
157
160
|
|
|
158
161
|
Returns:
|
|
@@ -10,7 +10,7 @@ def api_get_all_context_strategies() -> list[str]:
|
|
|
10
10
|
"""
|
|
11
11
|
Retrieves and returns the names of all context strategies currently available.
|
|
12
12
|
|
|
13
|
-
This API endpoint interfaces with the `ContextStrategy.
|
|
13
|
+
This API endpoint interfaces with the `ContextStrategy.get_all_context_strategies` method to fetch a list
|
|
14
14
|
of all context strategy names. It's designed for clients that need to know what context strategies are available for
|
|
15
15
|
use in sessions or other components of the system.
|
|
16
16
|
|
|
@@ -48,7 +48,7 @@ def api_get_all_context_strategy_metadata() -> list[dict]:
|
|
|
48
48
|
returns a list of metadata dictionaries.
|
|
49
49
|
|
|
50
50
|
Returns:
|
|
51
|
-
list[dict]: A list of dictionaries, each representing the details of a context strategy metadata.
|
|
51
|
+
list[dict]: A list of dictionaries, each representing the details of a context strategy's metadata.
|
|
52
52
|
"""
|
|
53
53
|
|
|
54
54
|
return [
|
moonshot/src/api/api_cookbook.py
CHANGED
|
@@ -14,7 +14,7 @@ def api_create_cookbook(name: str, description: str, recipes: list[str]) -> str:
|
|
|
14
14
|
|
|
15
15
|
This function takes the name, description, and recipes for a new cookbook as input. It then creates a new
|
|
16
16
|
CookbookArguments object with these details and an empty id. The id is left empty because it will be generated
|
|
17
|
-
from the name during the creation process. The function then calls the Cookbook's
|
|
17
|
+
from the name during the creation process. The function then calls the Cookbook's create method to
|
|
18
18
|
create the new cookbook.
|
|
19
19
|
|
|
20
20
|
Args:
|
|
@@ -43,7 +43,7 @@ def api_read_cookbook(cb_id: str) -> dict:
|
|
|
43
43
|
"""
|
|
44
44
|
Retrieves a cookbook based on the provided cookbook ID.
|
|
45
45
|
|
|
46
|
-
This function reads a cookbook using the `
|
|
46
|
+
This function reads a cookbook using the `read` method
|
|
47
47
|
of the `Cookbook` class, and converts the returned `Cookbook` object to a dictionary using its `to_dict` method.
|
|
48
48
|
|
|
49
49
|
Args:
|
|
@@ -60,7 +60,7 @@ def api_read_cookbooks(cb_ids: conlist(str, min_length=1)) -> list[dict]:
|
|
|
60
60
|
"""
|
|
61
61
|
Retrieves a list of cookbooks based on the provided list of cookbook IDs.
|
|
62
62
|
|
|
63
|
-
This function iterates over the list of provided cookbook IDs, reads each cookbook using the `
|
|
63
|
+
This function iterates over the list of provided cookbook IDs, reads each cookbook using the `read` method
|
|
64
64
|
of the `Cookbook` class, and converts the returned `Cookbook` objects to dictionaries using their `to_dict` method.
|
|
65
65
|
It then returns a list of these dictionary representations.
|
|
66
66
|
|
|
@@ -90,7 +90,7 @@ def api_update_cookbook(cb_id: str, **kwargs) -> bool:
|
|
|
90
90
|
bool: True if the cookbook was successfully updated.
|
|
91
91
|
|
|
92
92
|
Raises:
|
|
93
|
-
|
|
93
|
+
RuntimeError: If the cookbook with the given ID does not exist.
|
|
94
94
|
"""
|
|
95
95
|
# Check if the cookbook exists
|
|
96
96
|
try:
|
|
@@ -134,7 +134,7 @@ def api_get_all_cookbook() -> list[dict]:
|
|
|
134
134
|
"""
|
|
135
135
|
Retrieves all available cookbooks.
|
|
136
136
|
|
|
137
|
-
This function calls the `
|
|
137
|
+
This function calls the `get_available_items` method of the `Cookbook` class, which returns a tuple
|
|
138
138
|
containing a list of cookbook IDs and a list of `CookbookArguments` objects. The function then returns a list
|
|
139
139
|
of dictionaries, each representing a cookbook.
|
|
140
140
|
|
|
@@ -149,7 +149,7 @@ def api_get_all_cookbook_name() -> list[str]:
|
|
|
149
149
|
"""
|
|
150
150
|
Retrieves the names of all available cookbooks.
|
|
151
151
|
|
|
152
|
-
This function calls the `
|
|
152
|
+
This function calls the `get_available_items` method of the `Cookbook` class, which returns a tuple
|
|
153
153
|
containing a list of cookbook IDs and a list of `CookbookArguments` objects. The function then returns the
|
|
154
154
|
list of cookbook IDs, which are the names of the cookbooks.
|
|
155
155
|
|
moonshot/src/api/api_dataset.py
CHANGED
|
@@ -16,7 +16,7 @@ def api_delete_dataset(ds_id: str) -> bool:
|
|
|
16
16
|
ds_id (str): The unique identifier for the dataset to be deleted.
|
|
17
17
|
|
|
18
18
|
Returns:
|
|
19
|
-
bool: True if the dataset was successfully deleted.
|
|
19
|
+
bool: True if the dataset was successfully deleted, False otherwise.
|
|
20
20
|
|
|
21
21
|
Raises:
|
|
22
22
|
Exception: If the deletion process encounters an error.
|
|
@@ -27,10 +27,10 @@ def api_delete_dataset(ds_id: str) -> bool:
|
|
|
27
27
|
def api_get_all_datasets() -> list[dict]:
|
|
28
28
|
"""
|
|
29
29
|
This function retrieves all available datasets and returns them as a list of dictionaries. Each dictionary
|
|
30
|
-
represents a
|
|
30
|
+
represents a dataset and contains its information.
|
|
31
31
|
|
|
32
32
|
Returns:
|
|
33
|
-
list[dict]: A list of dictionaries, each representing a
|
|
33
|
+
list[dict]: A list of dictionaries, each representing a dataset.
|
|
34
34
|
"""
|
|
35
35
|
_, datasets = Dataset.get_available_items()
|
|
36
36
|
return [dataset.to_dict() for dataset in datasets]
|
|
@@ -38,10 +38,10 @@ def api_get_all_datasets() -> list[dict]:
|
|
|
38
38
|
|
|
39
39
|
def api_get_all_datasets_name() -> list[str]:
|
|
40
40
|
"""
|
|
41
|
-
This function retrieves all available
|
|
41
|
+
This function retrieves all available dataset names and returns them as a list.
|
|
42
42
|
|
|
43
43
|
Returns:
|
|
44
|
-
list[str]: A list of
|
|
44
|
+
list[str]: A list of dataset names.
|
|
45
45
|
"""
|
|
46
46
|
datasets_name, _ = Dataset.get_available_items()
|
|
47
47
|
return datasets_name
|
|
@@ -8,6 +8,9 @@ def api_set_environment_variables(env_vars: dict) -> None:
|
|
|
8
8
|
"""
|
|
9
9
|
Sets the environment variables for the current session.
|
|
10
10
|
|
|
11
|
+
This function takes a dictionary of environment variables and sets them for the current session
|
|
12
|
+
by loading them into the EnvironmentVars configuration.
|
|
13
|
+
|
|
11
14
|
Args:
|
|
12
15
|
env_vars (dict): A dictionary containing the environment variables to set.
|
|
13
16
|
|
moonshot/src/api/api_metrics.py
CHANGED
|
@@ -15,7 +15,7 @@ def api_delete_metric(met_id: str) -> bool:
|
|
|
15
15
|
met_id (str): The unique identifier for the metric to be deleted.
|
|
16
16
|
|
|
17
17
|
Returns:
|
|
18
|
-
bool: True if the metric was successfully deleted.
|
|
18
|
+
bool: True if the metric was successfully deleted, False otherwise.
|
|
19
19
|
|
|
20
20
|
Raises:
|
|
21
21
|
Exception: If the deletion process encounters an error.
|
|
@@ -10,6 +10,9 @@ def api_get_all_prompt_template_detail() -> list[dict]:
|
|
|
10
10
|
"""
|
|
11
11
|
Retrieves all available prompt template details and returns them as a list of dictionaries.
|
|
12
12
|
|
|
13
|
+
This function calls the `get_all_prompt_template_details` method from the `PromptTemplate` class
|
|
14
|
+
to fetch the details of all prompt templates. It then returns these details as a list of dictionaries.
|
|
15
|
+
|
|
13
16
|
Returns:
|
|
14
17
|
list[dict]: A list of dictionaries, each representing the details of a prompt template.
|
|
15
18
|
"""
|
|
@@ -20,6 +23,9 @@ def api_get_all_prompt_template_name() -> list[str]:
|
|
|
20
23
|
"""
|
|
21
24
|
Retrieves all available prompt template names and returns them as a list.
|
|
22
25
|
|
|
26
|
+
This function calls the `get_all_prompt_template_names` method from the `PromptTemplate` class
|
|
27
|
+
to fetch the names of all prompt templates. It then returns these names as a list of strings.
|
|
28
|
+
|
|
23
29
|
Returns:
|
|
24
30
|
list[str]: A list of prompt template names.
|
|
25
31
|
"""
|
|
@@ -31,6 +37,9 @@ def api_delete_prompt_template(pt_id: str) -> bool:
|
|
|
31
37
|
"""
|
|
32
38
|
Deletes a prompt template by its identifier.
|
|
33
39
|
|
|
40
|
+
This function calls the `delete` method from the `PromptTemplate` class to delete a prompt template
|
|
41
|
+
identified by its unique ID. It returns True if the deletion was successful, otherwise it raises an exception.
|
|
42
|
+
|
|
34
43
|
Args:
|
|
35
44
|
pt_id (str): The unique identifier of the prompt template to be deleted.
|
|
36
45
|
|
moonshot/src/api/api_recipe.py
CHANGED
|
@@ -79,7 +79,7 @@ def api_read_recipes(rec_ids: conlist(str, min_length=1)) -> list[dict]:
|
|
|
79
79
|
and returns a list of dictionaries containing each recipe's information.
|
|
80
80
|
|
|
81
81
|
Args:
|
|
82
|
-
rec_ids (
|
|
82
|
+
rec_ids (conlist(str, min_length=1)): The IDs of the recipes.
|
|
83
83
|
|
|
84
84
|
Returns:
|
|
85
85
|
list[dict]: A list of dictionaries, each containing a recipe's information.
|
|
@@ -155,7 +155,7 @@ def api_get_all_recipe() -> list[dict]:
|
|
|
155
155
|
"""
|
|
156
156
|
Retrieves all available recipes.
|
|
157
157
|
|
|
158
|
-
This function calls the
|
|
158
|
+
This function calls the get_available_items method to retrieve all available recipes. It then converts each
|
|
159
159
|
recipe into a dictionary using the to_dict method and returns a list of these dictionaries.
|
|
160
160
|
|
|
161
161
|
Returns:
|
|
@@ -169,7 +169,7 @@ def api_get_all_recipe_name() -> list[str]:
|
|
|
169
169
|
"""
|
|
170
170
|
Retrieves all available recipe names.
|
|
171
171
|
|
|
172
|
-
This function calls the
|
|
172
|
+
This function calls the get_available_items method to retrieve all available recipes. It then extracts the names
|
|
173
173
|
of each recipe and returns a list of these names.
|
|
174
174
|
|
|
175
175
|
Returns:
|
|
@@ -11,9 +11,7 @@ def api_get_all_attack_modules() -> list[str]:
|
|
|
11
11
|
Retrieves all available attack module IDs.
|
|
12
12
|
|
|
13
13
|
This function calls the `get_available_items` method from the `AttackModule` class to retrieve all available
|
|
14
|
-
attack modules.
|
|
15
|
-
|
|
16
|
-
It then extracts the IDs of each attack module and returns a list of these IDs.
|
|
14
|
+
attack modules. It then extracts the IDs of each attack module and returns a list of these IDs.
|
|
17
15
|
|
|
18
16
|
Returns:
|
|
19
17
|
list[str]: A list of strings, each representing an attack module ID.
|
|
@@ -27,10 +25,8 @@ def api_get_all_attack_module_metadata() -> list[dict]:
|
|
|
27
25
|
Retrieves metadata for all available attack modules.
|
|
28
26
|
|
|
29
27
|
This function calls the `get_available_items` method from the `AttackModule` class to retrieve all available
|
|
30
|
-
attack modules metadata
|
|
31
|
-
|
|
32
|
-
It then extracts the metadata for each attack module and returns a list of dictionaries, each containing the
|
|
33
|
-
metadata of an attack module.
|
|
28
|
+
attack modules. It then extracts the metadata for each attack module and returns a list of dictionaries,
|
|
29
|
+
each containing the metadata of an attack module.
|
|
34
30
|
|
|
35
31
|
Returns:
|
|
36
32
|
list[dict]: A list of dictionaries, each representing the metadata of an attack module.
|
|
@@ -44,7 +40,7 @@ def api_delete_attack_module(am_id: str) -> bool:
|
|
|
44
40
|
"""
|
|
45
41
|
Deletes an attack module by its identifier.
|
|
46
42
|
|
|
47
|
-
This function takes an attack module ID as input and calls the delete method from the AttackModule class
|
|
43
|
+
This function takes an attack module ID as input and calls the `delete` method from the `AttackModule` class
|
|
48
44
|
to remove the specified attack module from storage.
|
|
49
45
|
|
|
50
46
|
Args:
|
moonshot/src/api/api_result.py
CHANGED
|
@@ -11,7 +11,7 @@ def api_read_result(res_id: str) -> dict:
|
|
|
11
11
|
"""
|
|
12
12
|
Reads a result and returns its information.
|
|
13
13
|
|
|
14
|
-
This function takes a result ID as input, reads the corresponding
|
|
14
|
+
This function takes a result ID as input, reads the corresponding result from the storage manager,
|
|
15
15
|
and returns a dictionary containing the result's information.
|
|
16
16
|
|
|
17
17
|
Args:
|
|
@@ -28,7 +28,7 @@ def api_read_results(res_ids: conlist(str, min_length=1)) -> list[dict]:
|
|
|
28
28
|
"""
|
|
29
29
|
Reads multiple results and returns their information.
|
|
30
30
|
|
|
31
|
-
This function takes a list of result IDs as input, reads the corresponding
|
|
31
|
+
This function takes a list of result IDs as input, reads the corresponding results from the storage manager,
|
|
32
32
|
and returns a list of dictionaries, each containing a result's information.
|
|
33
33
|
|
|
34
34
|
Args:
|
|
@@ -37,7 +37,6 @@ def api_read_results(res_ids: conlist(str, min_length=1)) -> list[dict]:
|
|
|
37
37
|
Returns:
|
|
38
38
|
list[dict]: A list of dictionaries, each containing a result's information.
|
|
39
39
|
"""
|
|
40
|
-
|
|
41
40
|
return [Result.read(res_id) for res_id in res_ids]
|
|
42
41
|
|
|
43
42
|
|
|
@@ -63,11 +62,13 @@ def api_delete_result(res_id: str) -> bool:
|
|
|
63
62
|
|
|
64
63
|
def api_get_all_result() -> list[dict]:
|
|
65
64
|
"""
|
|
66
|
-
This function retrieves all available results and returns them as a list of dictionaries.
|
|
67
|
-
|
|
65
|
+
This function retrieves all available results and returns them as a list of dictionaries.
|
|
66
|
+
|
|
67
|
+
This function calls the get_available_items method from the Result class to retrieve all available results.
|
|
68
|
+
It then returns a list of dictionaries, each containing the details of a result.
|
|
68
69
|
|
|
69
70
|
Returns:
|
|
70
|
-
list[dict]: A list of dictionaries, each representing a result.
|
|
71
|
+
list[dict]: A list of dictionaries, each representing a result's details.
|
|
71
72
|
"""
|
|
72
73
|
_, results = Result.get_available_items()
|
|
73
74
|
return [result for result in results]
|
|
@@ -77,6 +78,9 @@ def api_get_all_result_name() -> list[str]:
|
|
|
77
78
|
"""
|
|
78
79
|
This function retrieves all available result names and returns them as a list.
|
|
79
80
|
|
|
81
|
+
This function calls the get_available_items method from the Result class to retrieve all available results.
|
|
82
|
+
It then extracts the names of each result and returns a list of these names.
|
|
83
|
+
|
|
80
84
|
Returns:
|
|
81
85
|
list[str]: A list of result names.
|
|
82
86
|
"""
|
moonshot/src/api/api_run.py
CHANGED
|
@@ -14,7 +14,7 @@ def api_get_all_run(runner_id: str = "") -> list[dict]:
|
|
|
14
14
|
|
|
15
15
|
Args:
|
|
16
16
|
runner_id (str, optional): The ID of the runner to retrieve runs for. If empty, runs for all runners
|
|
17
|
-
|
|
17
|
+
are retrieved.
|
|
18
18
|
|
|
19
19
|
Returns:
|
|
20
20
|
list[dict]: A list of dictionaries, each representing a run's data.
|
|
@@ -34,8 +34,8 @@ def _api_get_available_runs(
|
|
|
34
34
|
RunArguments instances representing the runs.
|
|
35
35
|
|
|
36
36
|
Args:
|
|
37
|
-
runner_id (str): The ID of the runner for which to retrieve run information. If empty, information
|
|
38
|
-
|
|
37
|
+
runner_id (str, optional): The ID of the runner for which to retrieve run information. If empty, information
|
|
38
|
+
for all runners is retrieved.
|
|
39
39
|
|
|
40
40
|
Returns:
|
|
41
41
|
tuple[list[str], list[RunArguments]]: A tuple containing a list of runner IDs and a list of RunArguments
|
moonshot/src/api/api_runner.py
CHANGED
|
@@ -20,7 +20,7 @@ def api_create_runner(
|
|
|
20
20
|
Creates a new runner.
|
|
21
21
|
|
|
22
22
|
This function takes the name, endpoints, and an optional progress callback function to create a new Runner instance.
|
|
23
|
-
The
|
|
23
|
+
The ID of the runner is generated from the name of the runner using the slugify function,
|
|
24
24
|
so it does not need to be provided.
|
|
25
25
|
|
|
26
26
|
Args:
|
|
@@ -59,7 +59,8 @@ def api_load_runner(
|
|
|
59
59
|
|
|
60
60
|
Args:
|
|
61
61
|
runner_id (str): The ID of the runner to be loaded.
|
|
62
|
-
progress_callback_func (Callable | None):
|
|
62
|
+
progress_callback_func (Callable | None, optional): An optional progress callback function for the runner.
|
|
63
|
+
Defaults to None.
|
|
63
64
|
|
|
64
65
|
Returns:
|
|
65
66
|
Runner: An initialized Runner object.
|
|
@@ -108,8 +109,8 @@ def api_get_all_runner() -> list[dict]:
|
|
|
108
109
|
"""
|
|
109
110
|
Retrieves all available runners.
|
|
110
111
|
|
|
111
|
-
This function calls the get_available_items method to retrieve all available runners.
|
|
112
|
-
runner into a dictionary using the to_dict method and returns a list of these dictionaries.
|
|
112
|
+
This function calls the get_available_items method from the Runner class to retrieve all available runners.
|
|
113
|
+
It then converts each runner into a dictionary using the to_dict method and returns a list of these dictionaries.
|
|
113
114
|
|
|
114
115
|
Returns:
|
|
115
116
|
list[dict]: A list of dictionaries, each representing a runner.
|
|
@@ -122,8 +123,8 @@ def api_get_all_runner_name() -> list[str]:
|
|
|
122
123
|
"""
|
|
123
124
|
Retrieves all available runner names.
|
|
124
125
|
|
|
125
|
-
This function calls the get_available_items method to retrieve all available runners.
|
|
126
|
-
each runner and returns a list of these names.
|
|
126
|
+
This function calls the get_available_items method from the Runner class to retrieve all available runners.
|
|
127
|
+
It then extracts the names of each runner and returns a list of these names.
|
|
127
128
|
|
|
128
129
|
Returns:
|
|
129
130
|
list[str]: A list of runner names.
|
moonshot/src/api/api_session.py
CHANGED
|
@@ -43,11 +43,14 @@ def api_create_session(
|
|
|
43
43
|
Args:
|
|
44
44
|
runner_id (str): The unique identifier of the runner for which the session is to be created.
|
|
45
45
|
database_instance (Any): The database instance to be used for the session.
|
|
46
|
-
endpoints (list): A list of endpoints for the session.
|
|
46
|
+
endpoints (list[str]): A list of endpoints for the session.
|
|
47
47
|
runner_args (dict): A dictionary of arguments for the runner.
|
|
48
48
|
|
|
49
49
|
Returns:
|
|
50
|
-
Session
|
|
50
|
+
Session: A new Session object.
|
|
51
|
+
|
|
52
|
+
Raises:
|
|
53
|
+
RuntimeError: If the runner_id is empty or if the database_instance is not provided.
|
|
51
54
|
"""
|
|
52
55
|
if isinstance(database_instance, DBInterface):
|
|
53
56
|
if runner_id:
|
|
@@ -86,16 +89,16 @@ def api_get_all_session_names() -> list[str]:
|
|
|
86
89
|
return session_names
|
|
87
90
|
|
|
88
91
|
|
|
89
|
-
def api_get_available_session_info() -> tuple[list, list]:
|
|
92
|
+
def api_get_available_session_info() -> tuple[list[str], list[dict]]:
|
|
90
93
|
"""
|
|
91
|
-
Retrieves the IDs and
|
|
94
|
+
Retrieves the IDs and metadata of runners with active sessions.
|
|
92
95
|
|
|
93
|
-
This function retrieves the IDs and
|
|
96
|
+
This function retrieves the IDs and metadata of runners with active sessions by querying all runners
|
|
94
97
|
and checking if each runner has an active session. It returns a tuple containing a list of runner IDs and a list
|
|
95
98
|
of corresponding session metadata for runners with active sessions.
|
|
96
99
|
|
|
97
100
|
Returns:
|
|
98
|
-
tuple[list[str], list[
|
|
101
|
+
tuple[list[str], list[dict]]: A tuple containing a list of runner IDs and a list of corresponding session
|
|
99
102
|
metadata for runners with active sessions.
|
|
100
103
|
"""
|
|
101
104
|
runners_info = api_get_all_runner()
|
|
@@ -122,7 +125,8 @@ def api_get_all_session_metadata() -> list[dict]:
|
|
|
122
125
|
This function retrieves the metadata for all active sessions by calling the `api_get_available_session_info` method.
|
|
123
126
|
|
|
124
127
|
Returns:
|
|
125
|
-
list: A list containing the metadata for all active sessions, sorted by created datetime in
|
|
128
|
+
list[dict]: A list containing the metadata for all active sessions, sorted by created datetime in
|
|
129
|
+
descending order.
|
|
126
130
|
"""
|
|
127
131
|
_, session_metadata_list = api_get_available_session_info()
|
|
128
132
|
return sorted(
|