aiverify-moonshot 0.4.1__py3-none-any.whl → 0.4.2__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.1.dist-info → aiverify_moonshot-0.4.2.dist-info}/METADATA +2 -2
- {aiverify_moonshot-0.4.1.dist-info → aiverify_moonshot-0.4.2.dist-info}/RECORD +59 -49
- moonshot/__main__.py +77 -35
- moonshot/api.py +14 -0
- moonshot/integrations/cli/benchmark/benchmark.py +29 -13
- moonshot/integrations/cli/benchmark/cookbook.py +36 -6
- moonshot/integrations/cli/benchmark/datasets.py +33 -3
- moonshot/integrations/cli/benchmark/metrics.py +33 -3
- moonshot/integrations/cli/benchmark/recipe.py +36 -6
- moonshot/integrations/cli/benchmark/result.py +33 -3
- moonshot/integrations/cli/benchmark/run.py +34 -3
- moonshot/integrations/cli/common/common.py +12 -6
- moonshot/integrations/cli/common/connectors.py +73 -9
- moonshot/integrations/cli/common/prompt_template.py +38 -3
- moonshot/integrations/cli/redteam/attack_module.py +75 -24
- moonshot/integrations/cli/redteam/context_strategy.py +77 -23
- moonshot/integrations/cli/redteam/prompt_template.py +1 -1
- moonshot/integrations/cli/redteam/redteam.py +52 -6
- moonshot/integrations/cli/redteam/session.py +539 -43
- moonshot/integrations/web_api/__main__.py +2 -0
- moonshot/integrations/web_api/app.py +6 -6
- moonshot/integrations/web_api/container.py +12 -2
- moonshot/integrations/web_api/routes/bookmark.py +173 -0
- moonshot/integrations/web_api/schemas/bookmark_create_dto.py +13 -0
- moonshot/integrations/web_api/services/bookmark_service.py +90 -0
- moonshot/integrations/web_api/services/utils/file_manager.py +52 -0
- moonshot/integrations/web_api/status_updater/moonshot_ui_webhook.py +0 -1
- moonshot/integrations/web_api/temp/.gitkeep +0 -0
- moonshot/src/api/api_bookmark.py +95 -0
- moonshot/src/api/api_connector_endpoint.py +1 -1
- moonshot/src/api/api_context_strategy.py +2 -2
- moonshot/src/api/api_session.py +1 -1
- moonshot/src/bookmark/bookmark.py +257 -0
- moonshot/src/bookmark/bookmark_arguments.py +38 -0
- moonshot/src/configs/env_variables.py +12 -2
- moonshot/src/connectors/connector.py +15 -7
- moonshot/src/connectors_endpoints/connector_endpoint.py +65 -49
- moonshot/src/cookbooks/cookbook.py +57 -37
- moonshot/src/datasets/dataset.py +9 -5
- moonshot/src/metrics/metric.py +8 -4
- moonshot/src/metrics/metric_interface.py +8 -2
- moonshot/src/prompt_templates/prompt_template.py +5 -1
- moonshot/src/recipes/recipe.py +38 -25
- moonshot/src/redteaming/attack/attack_module.py +18 -8
- moonshot/src/redteaming/attack/context_strategy.py +6 -2
- moonshot/src/redteaming/session/session.py +15 -11
- moonshot/src/results/result.py +7 -3
- moonshot/src/runners/runner.py +65 -42
- moonshot/src/runs/run.py +15 -11
- moonshot/src/runs/run_progress.py +7 -3
- moonshot/src/storage/db_interface.py +14 -0
- moonshot/src/storage/storage.py +33 -2
- moonshot/src/utils/find_feature.py +45 -0
- moonshot/src/utils/log.py +66 -0
- moonshot/src/utils/timeit.py +8 -1
- {aiverify_moonshot-0.4.1.dist-info → aiverify_moonshot-0.4.2.dist-info}/WHEEL +0 -0
- {aiverify_moonshot-0.4.1.dist-info → aiverify_moonshot-0.4.2.dist-info}/licenses/AUTHORS.md +0 -0
- {aiverify_moonshot-0.4.1.dist-info → aiverify_moonshot-0.4.2.dist-info}/licenses/LICENSE.md +0 -0
- {aiverify_moonshot-0.4.1.dist-info → aiverify_moonshot-0.4.2.dist-info}/licenses/NOTICES.md +0 -0
|
@@ -23,6 +23,7 @@ from moonshot.integrations.cli.benchmark.recipe import (
|
|
|
23
23
|
display_view_statistics_format,
|
|
24
24
|
)
|
|
25
25
|
from moonshot.integrations.cli.common.display_helper import display_view_list_format
|
|
26
|
+
from moonshot.src.utils.find_feature import find_keyword
|
|
26
27
|
|
|
27
28
|
console = Console()
|
|
28
29
|
|
|
@@ -55,7 +56,7 @@ def add_cookbook(args) -> None:
|
|
|
55
56
|
print(f"[add_cookbook]: {str(e)}")
|
|
56
57
|
|
|
57
58
|
|
|
58
|
-
def list_cookbooks() -> None:
|
|
59
|
+
def list_cookbooks(args) -> list | None:
|
|
59
60
|
"""
|
|
60
61
|
List all available cookbooks.
|
|
61
62
|
|
|
@@ -63,12 +64,27 @@ def list_cookbooks() -> None:
|
|
|
63
64
|
moonshot.api module.
|
|
64
65
|
It then displays the retrieved cookbooks using the display_cookbooks function.
|
|
65
66
|
|
|
67
|
+
Args:
|
|
68
|
+
args: A namespace object from argparse. It should have an optional attribute:
|
|
69
|
+
find (str): Optional field to find cookbook(s) with a keyword.
|
|
70
|
+
|
|
66
71
|
Returns:
|
|
67
|
-
None
|
|
72
|
+
list | None: A list of Cookbook or None if there is no result.
|
|
68
73
|
"""
|
|
69
74
|
try:
|
|
70
75
|
cookbooks_list = api_get_all_cookbook()
|
|
71
|
-
|
|
76
|
+
keyword = args.find.lower() if args.find else ""
|
|
77
|
+
if keyword:
|
|
78
|
+
filtered_cookbooks_list = find_keyword(keyword, cookbooks_list)
|
|
79
|
+
if filtered_cookbooks_list:
|
|
80
|
+
display_cookbooks(filtered_cookbooks_list)
|
|
81
|
+
return filtered_cookbooks_list
|
|
82
|
+
else:
|
|
83
|
+
print("No cookbooks containing keyword found.")
|
|
84
|
+
return None
|
|
85
|
+
else:
|
|
86
|
+
display_cookbooks(cookbooks_list)
|
|
87
|
+
return cookbooks_list
|
|
72
88
|
except Exception as e:
|
|
73
89
|
print(f"[list_cookbooks]: {str(e)}")
|
|
74
90
|
|
|
@@ -340,9 +356,9 @@ def show_cookbook_results(cookbooks, endpoints, cookbook_results, duration):
|
|
|
340
356
|
console.print("[red]There are no results.[/red]")
|
|
341
357
|
|
|
342
358
|
# Print run stats
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
)
|
|
359
|
+
run_stats = f"""{'='*50}\n[blue]Time taken to run: {duration}s[/blue]\n*Overall rating will be the lowest grade
|
|
360
|
+
that the recipes have in each cookbook\n{'='*50}"""
|
|
361
|
+
console.print(run_stats)
|
|
346
362
|
|
|
347
363
|
|
|
348
364
|
def generate_cookbook_table(cookbooks: list, endpoints: list, results: dict) -> None:
|
|
@@ -543,3 +559,17 @@ run_cookbook_args.add_argument(
|
|
|
543
559
|
default="benchmarking-result",
|
|
544
560
|
help="Result processing module to use",
|
|
545
561
|
)
|
|
562
|
+
|
|
563
|
+
# List cookbook arguments
|
|
564
|
+
list_cookbooks_args = cmd2.Cmd2ArgumentParser(
|
|
565
|
+
description="List all cookbooks.",
|
|
566
|
+
epilog='Example:\n list_cookbooks -f "risk"',
|
|
567
|
+
)
|
|
568
|
+
|
|
569
|
+
list_cookbooks_args.add_argument(
|
|
570
|
+
"-f",
|
|
571
|
+
"--find",
|
|
572
|
+
type=str,
|
|
573
|
+
help="Optional field to find cookbook(s) with keyword",
|
|
574
|
+
nargs="?",
|
|
575
|
+
)
|
|
@@ -8,6 +8,7 @@ from moonshot.api import (
|
|
|
8
8
|
api_get_all_datasets_name,
|
|
9
9
|
)
|
|
10
10
|
from moonshot.integrations.cli.common.display_helper import display_view_str_format
|
|
11
|
+
from moonshot.src.utils.find_feature import find_keyword
|
|
11
12
|
|
|
12
13
|
console = Console()
|
|
13
14
|
|
|
@@ -15,7 +16,7 @@ console = Console()
|
|
|
15
16
|
# ------------------------------------------------------------------------------
|
|
16
17
|
# CLI Functions
|
|
17
18
|
# ------------------------------------------------------------------------------
|
|
18
|
-
def list_datasets() -> None:
|
|
19
|
+
def list_datasets(args) -> list | None:
|
|
19
20
|
"""
|
|
20
21
|
List all available datasets.
|
|
21
22
|
|
|
@@ -23,13 +24,28 @@ def list_datasets() -> None:
|
|
|
23
24
|
moonshot.api module. It then displays the datasets using the display_datasets function. If an exception occurs,
|
|
24
25
|
it prints an error message.
|
|
25
26
|
|
|
27
|
+
Args:
|
|
28
|
+
args: A namespace object from argparse. It should have an optional attribute:
|
|
29
|
+
find (str): Optional field to find dataset(s) with a keyword.
|
|
30
|
+
|
|
26
31
|
Returns:
|
|
27
|
-
None
|
|
32
|
+
list | None: A list of Dataset or None if there is no result.
|
|
28
33
|
"""
|
|
29
34
|
try:
|
|
30
35
|
print("Listing datasets may take a while...")
|
|
31
36
|
datasets_list = api_get_all_datasets()
|
|
32
|
-
|
|
37
|
+
keyword = args.find.lower() if args.find else ""
|
|
38
|
+
if keyword:
|
|
39
|
+
filtered_datasets_list = find_keyword(keyword, datasets_list)
|
|
40
|
+
if filtered_datasets_list:
|
|
41
|
+
display_datasets(filtered_datasets_list)
|
|
42
|
+
return filtered_datasets_list
|
|
43
|
+
else:
|
|
44
|
+
print("No datasets containing keyword found.")
|
|
45
|
+
return None
|
|
46
|
+
else:
|
|
47
|
+
display_datasets(datasets_list)
|
|
48
|
+
return datasets_list
|
|
33
49
|
except Exception as e:
|
|
34
50
|
print(f"[list_datasets]: {str(e)}")
|
|
35
51
|
|
|
@@ -162,3 +178,17 @@ delete_dataset_args = cmd2.Cmd2ArgumentParser(
|
|
|
162
178
|
epilog="Example:\n delete_dataset bbq-lite-age-ambiguous",
|
|
163
179
|
)
|
|
164
180
|
delete_dataset_args.add_argument("dataset", type=str, help="Name of the dataset")
|
|
181
|
+
|
|
182
|
+
# List dataset arguments
|
|
183
|
+
list_datasets_args = cmd2.Cmd2ArgumentParser(
|
|
184
|
+
description="List all datasets.",
|
|
185
|
+
epilog='Example:\n list_datasets -f "bbq"',
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
list_datasets_args.add_argument(
|
|
189
|
+
"-f",
|
|
190
|
+
"--find",
|
|
191
|
+
type=str,
|
|
192
|
+
help="Optional field to find dataset(s) with keyword",
|
|
193
|
+
nargs="?",
|
|
194
|
+
)
|
|
@@ -3,6 +3,7 @@ from rich.console import Console
|
|
|
3
3
|
from rich.table import Table
|
|
4
4
|
|
|
5
5
|
from moonshot.api import api_delete_metric, api_get_all_metric, api_get_all_metric_name
|
|
6
|
+
from moonshot.src.utils.find_feature import find_keyword
|
|
6
7
|
|
|
7
8
|
console = Console()
|
|
8
9
|
|
|
@@ -10,7 +11,7 @@ console = Console()
|
|
|
10
11
|
# ------------------------------------------------------------------------------
|
|
11
12
|
# CLI Functions
|
|
12
13
|
# ------------------------------------------------------------------------------
|
|
13
|
-
def list_metrics() -> None:
|
|
14
|
+
def list_metrics(args) -> list | None:
|
|
14
15
|
"""
|
|
15
16
|
List all available metrics.
|
|
16
17
|
|
|
@@ -18,13 +19,28 @@ def list_metrics() -> None:
|
|
|
18
19
|
moonshot.api module. It then displays the metrics using the display_metrics function. If an exception occurs,
|
|
19
20
|
it prints an error message.
|
|
20
21
|
|
|
22
|
+
Args:
|
|
23
|
+
args: A namespace object from argparse. It should have an optional attribute:
|
|
24
|
+
find (str): Optional field to find metric(s) with a keyword.
|
|
25
|
+
|
|
21
26
|
Returns:
|
|
22
|
-
None
|
|
27
|
+
list | None: A list of Metric or None if there is no result.
|
|
23
28
|
"""
|
|
24
29
|
try:
|
|
25
30
|
print("Listing metrics may take a while...")
|
|
26
31
|
metrics_list = api_get_all_metric()
|
|
27
|
-
|
|
32
|
+
keyword = args.find.lower() if args.find else ""
|
|
33
|
+
if keyword:
|
|
34
|
+
filtered_metrics_list = find_keyword(keyword, metrics_list)
|
|
35
|
+
if filtered_metrics_list:
|
|
36
|
+
display_metrics(filtered_metrics_list)
|
|
37
|
+
return filtered_metrics_list
|
|
38
|
+
else:
|
|
39
|
+
print("No metrics containing keyword found.")
|
|
40
|
+
return None
|
|
41
|
+
else:
|
|
42
|
+
display_metrics(metrics_list)
|
|
43
|
+
return metrics_list
|
|
28
44
|
except Exception as e:
|
|
29
45
|
print(f"[list_metrics]: {str(e)}")
|
|
30
46
|
|
|
@@ -139,3 +155,17 @@ delete_metric_args = cmd2.Cmd2ArgumentParser(
|
|
|
139
155
|
epilog="Example:\n delete_metric my-new-metric",
|
|
140
156
|
)
|
|
141
157
|
delete_metric_args.add_argument("metric", type=str, help="Name of the metric")
|
|
158
|
+
|
|
159
|
+
# List metric arguments
|
|
160
|
+
list_metrics_args = cmd2.Cmd2ArgumentParser(
|
|
161
|
+
description="List all metrics.",
|
|
162
|
+
epilog='Example:\n list_metrics -f "exact"',
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
list_metrics_args.add_argument(
|
|
166
|
+
"-f",
|
|
167
|
+
"--find",
|
|
168
|
+
type=str,
|
|
169
|
+
help="Optional field to find metric(s) with keyword",
|
|
170
|
+
nargs="?",
|
|
171
|
+
)
|
|
@@ -18,6 +18,7 @@ from moonshot.api import (
|
|
|
18
18
|
api_update_recipe,
|
|
19
19
|
)
|
|
20
20
|
from moonshot.integrations.cli.common.display_helper import display_view_list_format
|
|
21
|
+
from moonshot.src.utils.find_feature import find_keyword
|
|
21
22
|
|
|
22
23
|
console = Console()
|
|
23
24
|
|
|
@@ -74,7 +75,7 @@ def add_recipe(args) -> None:
|
|
|
74
75
|
print(f"[add_recipe]: {str(e)}")
|
|
75
76
|
|
|
76
77
|
|
|
77
|
-
def list_recipes() -> None:
|
|
78
|
+
def list_recipes(args) -> list | None:
|
|
78
79
|
"""
|
|
79
80
|
List all available recipes.
|
|
80
81
|
|
|
@@ -82,12 +83,27 @@ def list_recipes() -> None:
|
|
|
82
83
|
moonshot.api module.
|
|
83
84
|
It then displays the retrieved recipes using the display_recipes function.
|
|
84
85
|
|
|
86
|
+
Args:
|
|
87
|
+
args: A namespace object from argparse. It should have an optional attribute:
|
|
88
|
+
find (str): Optional field to find recipe(s) with a keyword.
|
|
89
|
+
|
|
85
90
|
Returns:
|
|
86
|
-
None
|
|
91
|
+
list | None: A list of Recipe or None if there is no result.
|
|
87
92
|
"""
|
|
88
93
|
try:
|
|
89
94
|
recipes_list = api_get_all_recipe()
|
|
90
|
-
|
|
95
|
+
keyword = args.find.lower() if args.find else ""
|
|
96
|
+
if keyword:
|
|
97
|
+
filtered_recipes_list = find_keyword(keyword, recipes_list)
|
|
98
|
+
if filtered_recipes_list:
|
|
99
|
+
display_recipes(filtered_recipes_list)
|
|
100
|
+
return filtered_recipes_list
|
|
101
|
+
else:
|
|
102
|
+
print("No recipes containing keyword found.")
|
|
103
|
+
return None
|
|
104
|
+
else:
|
|
105
|
+
display_recipes(recipes_list)
|
|
106
|
+
return recipes_list
|
|
91
107
|
except Exception as e:
|
|
92
108
|
print(f"[list_recipes]: {str(e)}")
|
|
93
109
|
|
|
@@ -382,9 +398,9 @@ def show_recipe_results(recipes, endpoints, recipe_results, duration):
|
|
|
382
398
|
console.print("[red]There are no results.[/red]")
|
|
383
399
|
|
|
384
400
|
# Print run stats
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
)
|
|
401
|
+
run_stats = f"""{'='*50}\n[blue]Time taken to run: {duration}s[/blue]\n*Overall rating will be the lowest grade
|
|
402
|
+
that the recipes have in each cookbook\n{'='*50}"""
|
|
403
|
+
console.print(run_stats)
|
|
388
404
|
|
|
389
405
|
|
|
390
406
|
def generate_recipe_table(recipes: list, endpoints: list, results: dict) -> None:
|
|
@@ -596,3 +612,17 @@ run_recipe_args.add_argument(
|
|
|
596
612
|
default="benchmarking-result",
|
|
597
613
|
help="Result processing module to use",
|
|
598
614
|
)
|
|
615
|
+
|
|
616
|
+
# List recipe arguments
|
|
617
|
+
list_recipes_args = cmd2.Cmd2ArgumentParser(
|
|
618
|
+
description="List all recipes.",
|
|
619
|
+
epilog='Example:\n list_recipes -f "mmlu"',
|
|
620
|
+
)
|
|
621
|
+
|
|
622
|
+
list_recipes_args.add_argument(
|
|
623
|
+
"-f",
|
|
624
|
+
"--find",
|
|
625
|
+
type=str,
|
|
626
|
+
help="Optional field to find recipe(s) with keyword",
|
|
627
|
+
nargs="?",
|
|
628
|
+
)
|
|
@@ -9,6 +9,7 @@ from moonshot.integrations.cli.common.display_helper import (
|
|
|
9
9
|
display_view_list_format,
|
|
10
10
|
display_view_str_format,
|
|
11
11
|
)
|
|
12
|
+
from moonshot.src.utils.find_feature import find_keyword
|
|
12
13
|
|
|
13
14
|
console = Console()
|
|
14
15
|
|
|
@@ -16,7 +17,7 @@ console = Console()
|
|
|
16
17
|
# ------------------------------------------------------------------------------
|
|
17
18
|
# CLI Functions
|
|
18
19
|
# ------------------------------------------------------------------------------
|
|
19
|
-
def list_results() -> None:
|
|
20
|
+
def list_results(args) -> list | None:
|
|
20
21
|
"""
|
|
21
22
|
List all available results.
|
|
22
23
|
|
|
@@ -24,12 +25,27 @@ def list_results() -> None:
|
|
|
24
25
|
moonshot.api module. It then creates a table with the result id and name. If there are no results, it prints a
|
|
25
26
|
message indicating that no results were found.
|
|
26
27
|
|
|
28
|
+
Args:
|
|
29
|
+
args: A namespace object from argparse. It should have an optional attribute:
|
|
30
|
+
find (str): Optional field to find result(s) with a keyword.
|
|
31
|
+
|
|
27
32
|
Returns:
|
|
28
|
-
None
|
|
33
|
+
list | None: A list of Result or None if there is no result.
|
|
29
34
|
"""
|
|
30
35
|
try:
|
|
31
36
|
results_list = api_get_all_result()
|
|
32
|
-
|
|
37
|
+
keyword = args.find.lower() if args.find else ""
|
|
38
|
+
if keyword:
|
|
39
|
+
filtered_results_list = find_keyword(keyword, results_list)
|
|
40
|
+
if filtered_results_list:
|
|
41
|
+
display_results(filtered_results_list)
|
|
42
|
+
return filtered_results_list
|
|
43
|
+
else:
|
|
44
|
+
print("No results containing keyword found.")
|
|
45
|
+
return None
|
|
46
|
+
else:
|
|
47
|
+
display_results(results_list)
|
|
48
|
+
return results_list
|
|
33
49
|
except Exception as e:
|
|
34
50
|
print(f"[list_results]: {str(e)}")
|
|
35
51
|
|
|
@@ -214,3 +230,17 @@ delete_result_args = cmd2.Cmd2ArgumentParser(
|
|
|
214
230
|
epilog="Example:\n delete_result my-new-cookbook-runner",
|
|
215
231
|
)
|
|
216
232
|
delete_result_args.add_argument("result", type=str, help="Name of the result")
|
|
233
|
+
|
|
234
|
+
# List result arguments
|
|
235
|
+
list_results_args = cmd2.Cmd2ArgumentParser(
|
|
236
|
+
description="List all results.",
|
|
237
|
+
epilog='Example:\n list_results -f "my-runner"',
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
list_results_args.add_argument(
|
|
241
|
+
"-f",
|
|
242
|
+
"--find",
|
|
243
|
+
type=str,
|
|
244
|
+
help="Optional field to find result(s) with keyword",
|
|
245
|
+
nargs="?",
|
|
246
|
+
)
|
|
@@ -7,6 +7,7 @@ from moonshot.integrations.cli.common.display_helper import (
|
|
|
7
7
|
display_view_list_format,
|
|
8
8
|
display_view_str_format,
|
|
9
9
|
)
|
|
10
|
+
from moonshot.src.utils.find_feature import find_keyword
|
|
10
11
|
|
|
11
12
|
console = Console()
|
|
12
13
|
|
|
@@ -14,7 +15,7 @@ console = Console()
|
|
|
14
15
|
# ------------------------------------------------------------------------------
|
|
15
16
|
# CLI Functions
|
|
16
17
|
# ------------------------------------------------------------------------------
|
|
17
|
-
def list_runs() -> None:
|
|
18
|
+
def list_runs(args) -> list | None:
|
|
18
19
|
"""
|
|
19
20
|
List all runs.
|
|
20
21
|
|
|
@@ -23,12 +24,27 @@ def list_runs() -> None:
|
|
|
23
24
|
in a user-friendly format on the command line interface. If an exception occurs during the retrieval
|
|
24
25
|
or display process, it prints an error message.
|
|
25
26
|
|
|
27
|
+
Args:
|
|
28
|
+
args: A namespace object from argparse. It should have an optional attribute:
|
|
29
|
+
find (str): Optional field to find run(s) with a keyword.
|
|
30
|
+
|
|
26
31
|
Returns:
|
|
27
|
-
None
|
|
32
|
+
list | None: A list of Run or None if there is no result.
|
|
28
33
|
"""
|
|
29
34
|
try:
|
|
30
35
|
runner_run_info = api_get_all_run()
|
|
31
|
-
|
|
36
|
+
keyword = args.find.lower() if args.find else ""
|
|
37
|
+
if keyword:
|
|
38
|
+
filtered_runs_list = find_keyword(keyword, runner_run_info)
|
|
39
|
+
if filtered_runs_list:
|
|
40
|
+
display_runs(filtered_runs_list)
|
|
41
|
+
return filtered_runs_list
|
|
42
|
+
else:
|
|
43
|
+
print("No runs containing keyword found.")
|
|
44
|
+
return None
|
|
45
|
+
else:
|
|
46
|
+
display_runs(runner_run_info)
|
|
47
|
+
return runner_run_info
|
|
32
48
|
except Exception as e:
|
|
33
49
|
print(f"[list_runs]: {str(e)}")
|
|
34
50
|
|
|
@@ -138,3 +154,18 @@ view_run_args = cmd2.Cmd2ArgumentParser(
|
|
|
138
154
|
epilog="Example:\n view_run my-new-cookbook-runner",
|
|
139
155
|
)
|
|
140
156
|
view_run_args.add_argument("runner_id", type=str, help="Name of the runner")
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
# List run arguments
|
|
160
|
+
list_runs_args = cmd2.Cmd2ArgumentParser(
|
|
161
|
+
description="List all runs.",
|
|
162
|
+
epilog='Example:\n list_runs -f "my-run"',
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
list_runs_args.add_argument(
|
|
166
|
+
"-f",
|
|
167
|
+
"--find",
|
|
168
|
+
type=str,
|
|
169
|
+
help="Optional field to find run(s) with keyword",
|
|
170
|
+
nargs="?",
|
|
171
|
+
)
|
|
@@ -8,7 +8,9 @@ from moonshot.integrations.cli.common.connectors import (
|
|
|
8
8
|
delete_endpoint,
|
|
9
9
|
delete_endpoint_args,
|
|
10
10
|
list_connector_types,
|
|
11
|
+
list_connector_types_args,
|
|
11
12
|
list_endpoints,
|
|
13
|
+
list_endpoints_args,
|
|
12
14
|
update_endpoint,
|
|
13
15
|
update_endpoint_args,
|
|
14
16
|
view_endpoint,
|
|
@@ -18,6 +20,7 @@ from moonshot.integrations.cli.common.prompt_template import (
|
|
|
18
20
|
delete_prompt_template,
|
|
19
21
|
delete_prompt_template_args,
|
|
20
22
|
list_prompt_templates,
|
|
23
|
+
list_prompt_templates_args,
|
|
21
24
|
)
|
|
22
25
|
|
|
23
26
|
|
|
@@ -30,14 +33,17 @@ class CommonCommandSet(cmd2.CommandSet):
|
|
|
30
33
|
# List contents
|
|
31
34
|
# ------------------------------------------------------------------------------
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
@cmd2.with_argparser(list_connector_types_args)
|
|
37
|
+
def do_list_connector_types(self, args: argparse.Namespace) -> None:
|
|
38
|
+
list_connector_types(args)
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
@cmd2.with_argparser(list_endpoints_args)
|
|
41
|
+
def do_list_endpoints(self, args: argparse.Namespace) -> None:
|
|
42
|
+
list_endpoints(args)
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
@cmd2.with_argparser(list_prompt_templates_args)
|
|
45
|
+
def do_list_prompt_templates(self, args: argparse.Namespace) -> None:
|
|
46
|
+
list_prompt_templates(args)
|
|
41
47
|
|
|
42
48
|
@cmd2.with_argparser(delete_prompt_template_args)
|
|
43
49
|
def do_delete_prompt_template(self, args: argparse.Namespace) -> None:
|
|
@@ -13,6 +13,7 @@ from moonshot.api import (
|
|
|
13
13
|
api_read_endpoint,
|
|
14
14
|
api_update_endpoint,
|
|
15
15
|
)
|
|
16
|
+
from moonshot.src.utils.find_feature import find_keyword
|
|
16
17
|
|
|
17
18
|
console = Console()
|
|
18
19
|
|
|
@@ -57,36 +58,66 @@ def add_endpoint(args) -> None:
|
|
|
57
58
|
print(f"[add_endpoint]: {str(e)}")
|
|
58
59
|
|
|
59
60
|
|
|
60
|
-
def list_endpoints() -> None:
|
|
61
|
+
def list_endpoints(args) -> list | None:
|
|
61
62
|
"""
|
|
62
63
|
List all endpoints.
|
|
63
64
|
|
|
64
65
|
This function retrieves all endpoints by calling the api_get_all_endpoint function from the
|
|
65
66
|
moonshot.api module. It then displays the endpoints using the display_endpoints function.
|
|
66
67
|
|
|
68
|
+
Args:
|
|
69
|
+
args: A namespace object from argparse. It should have an optional attribute:
|
|
70
|
+
find (str): Optional field to find endpoint(s) with a keyword.
|
|
71
|
+
|
|
67
72
|
Returns:
|
|
68
|
-
None
|
|
73
|
+
list | None: A list of ConnectorEndpoint or None if there is no result.
|
|
69
74
|
"""
|
|
70
75
|
try:
|
|
71
|
-
|
|
72
|
-
|
|
76
|
+
endpoints_list = api_get_all_endpoint()
|
|
77
|
+
keyword = args.find.lower() if args.find else ""
|
|
78
|
+
if keyword:
|
|
79
|
+
filtered_endpoints_list = find_keyword(keyword, endpoints_list)
|
|
80
|
+
if filtered_endpoints_list:
|
|
81
|
+
display_endpoints(filtered_endpoints_list)
|
|
82
|
+
return filtered_endpoints_list
|
|
83
|
+
else:
|
|
84
|
+
print("No endpoints containing keyword found.")
|
|
85
|
+
return None
|
|
86
|
+
else:
|
|
87
|
+
display_endpoints(endpoints_list)
|
|
88
|
+
return endpoints_list
|
|
73
89
|
except Exception as e:
|
|
74
90
|
print(f"[list_endpoints]: {str(e)}")
|
|
75
91
|
|
|
76
92
|
|
|
77
|
-
def list_connector_types() -> None:
|
|
93
|
+
def list_connector_types(args) -> list | None:
|
|
78
94
|
"""
|
|
79
95
|
List all connector types.
|
|
80
96
|
|
|
81
97
|
This function retrieves all connector types by calling the api_get_all_connector_type function from the
|
|
82
98
|
moonshot.api module. It then displays the connector types using the display_connector_types function.
|
|
83
99
|
|
|
100
|
+
Args:
|
|
101
|
+
args: A namespace object from argparse. It should have an optional attribute:
|
|
102
|
+
find (str): Optional field to find connector type(s) with a keyword.
|
|
103
|
+
|
|
84
104
|
Returns:
|
|
85
|
-
None
|
|
105
|
+
list | None: A list of Connector or None if there is no result.
|
|
86
106
|
"""
|
|
87
107
|
try:
|
|
88
108
|
connector_type_list = api_get_all_connector_type()
|
|
89
|
-
|
|
109
|
+
keyword = args.find.lower() if args.find else ""
|
|
110
|
+
if keyword:
|
|
111
|
+
filtered_connector_type_list = find_keyword(keyword, connector_type_list)
|
|
112
|
+
if filtered_connector_type_list:
|
|
113
|
+
display_connector_types(filtered_connector_type_list)
|
|
114
|
+
return filtered_connector_type_list
|
|
115
|
+
else:
|
|
116
|
+
print("No connectors containing keyword found.")
|
|
117
|
+
return None
|
|
118
|
+
else:
|
|
119
|
+
display_connector_types(connector_type_list)
|
|
120
|
+
return connector_type_list
|
|
90
121
|
except Exception as e:
|
|
91
122
|
print(f"[list_connector_types]: {str(e)}")
|
|
92
123
|
|
|
@@ -170,7 +201,7 @@ def delete_endpoint(args) -> None:
|
|
|
170
201
|
# ------------------------------------------------------------------------------
|
|
171
202
|
# Helper functions: Display on cli
|
|
172
203
|
# ------------------------------------------------------------------------------
|
|
173
|
-
def display_connector_types(connector_types):
|
|
204
|
+
def display_connector_types(connector_types: list) -> None:
|
|
174
205
|
"""
|
|
175
206
|
Display a list of connector types.
|
|
176
207
|
|
|
@@ -305,7 +336,11 @@ update_endpoint_args = cmd2.Cmd2ArgumentParser(
|
|
|
305
336
|
"('uri', 'my-uri-loc'), ('token', 'my-token-here')]\""
|
|
306
337
|
),
|
|
307
338
|
)
|
|
308
|
-
update_endpoint_args.add_argument(
|
|
339
|
+
update_endpoint_args.add_argument(
|
|
340
|
+
"endpoint",
|
|
341
|
+
type=str,
|
|
342
|
+
help="ID of the endpoint. This field is not editable via CLI after creation.",
|
|
343
|
+
)
|
|
309
344
|
update_endpoint_args.add_argument(
|
|
310
345
|
"update_kwargs", type=str, help="Update endpoint key/value"
|
|
311
346
|
)
|
|
@@ -323,3 +358,32 @@ delete_endpoint_args = cmd2.Cmd2ArgumentParser(
|
|
|
323
358
|
epilog="Example:\n delete_endpoint openai-gpt4",
|
|
324
359
|
)
|
|
325
360
|
delete_endpoint_args.add_argument("endpoint", type=str, help="ID of the endpoint")
|
|
361
|
+
|
|
362
|
+
# List endpoint arguments
|
|
363
|
+
list_endpoints_args = cmd2.Cmd2ArgumentParser(
|
|
364
|
+
description="List all endpoints.",
|
|
365
|
+
epilog='Example:\n list_endpoints -f "gpt"',
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
list_endpoints_args.add_argument(
|
|
369
|
+
"-f",
|
|
370
|
+
"--find",
|
|
371
|
+
type=str,
|
|
372
|
+
help="Optional field to find endpoint(s) with keyword",
|
|
373
|
+
nargs="?",
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
# List connector types arguments
|
|
378
|
+
list_connector_types_args = cmd2.Cmd2ArgumentParser(
|
|
379
|
+
description="List all connector types.",
|
|
380
|
+
epilog='Example:\n list_connector_types -f "openai"',
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
list_connector_types_args.add_argument(
|
|
384
|
+
"-f",
|
|
385
|
+
"--find",
|
|
386
|
+
type=str,
|
|
387
|
+
help="Optional field to find connector type(s) with keyword",
|
|
388
|
+
nargs="?",
|
|
389
|
+
)
|
|
@@ -3,6 +3,7 @@ from rich.console import Console
|
|
|
3
3
|
from rich.table import Table
|
|
4
4
|
|
|
5
5
|
from moonshot.api import api_delete_prompt_template, api_get_all_prompt_template_detail
|
|
6
|
+
from moonshot.src.utils.find_feature import find_keyword
|
|
6
7
|
|
|
7
8
|
console = Console()
|
|
8
9
|
|
|
@@ -10,13 +11,33 @@ console = Console()
|
|
|
10
11
|
# ------------------------------------------------------------------------------
|
|
11
12
|
# CLI Functions
|
|
12
13
|
# ------------------------------------------------------------------------------
|
|
13
|
-
def list_prompt_templates() -> None:
|
|
14
|
+
def list_prompt_templates(args) -> list | None:
|
|
14
15
|
"""
|
|
15
16
|
List all prompt templates available.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
args: A namespace object from argparse. It should have an optional attribute:
|
|
20
|
+
find (str): Optional field to find prompt template(s) with a keyword.
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
list | None: A list of PromptTemplate or None if there is no result.
|
|
16
24
|
"""
|
|
17
25
|
try:
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
prompt_templates_list = api_get_all_prompt_template_detail()
|
|
27
|
+
keyword = args.find.lower() if args.find else ""
|
|
28
|
+
if keyword:
|
|
29
|
+
filtered_prompt_templates_list = find_keyword(
|
|
30
|
+
keyword, prompt_templates_list
|
|
31
|
+
)
|
|
32
|
+
if filtered_prompt_templates_list:
|
|
33
|
+
display_prompt_templates(filtered_prompt_templates_list)
|
|
34
|
+
return filtered_prompt_templates_list
|
|
35
|
+
else:
|
|
36
|
+
print("No prompt templates containing keyword found.")
|
|
37
|
+
return None
|
|
38
|
+
else:
|
|
39
|
+
display_prompt_templates(prompt_templates_list)
|
|
40
|
+
return prompt_templates_list
|
|
20
41
|
except Exception as e:
|
|
21
42
|
print(f"[list_prompt_templates]: {str(e)}")
|
|
22
43
|
|
|
@@ -92,3 +113,17 @@ delete_prompt_template_args = cmd2.Cmd2ArgumentParser(
|
|
|
92
113
|
delete_prompt_template_args.add_argument(
|
|
93
114
|
"prompt_template", type=str, help="The ID of the prompt template to delete"
|
|
94
115
|
)
|
|
116
|
+
|
|
117
|
+
# List prompt template arguments
|
|
118
|
+
list_prompt_templates_args = cmd2.Cmd2ArgumentParser(
|
|
119
|
+
description="List all prompt templates.",
|
|
120
|
+
epilog='Example:\n list_prompt_templates -f "toxicity"',
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
list_prompt_templates_args.add_argument(
|
|
124
|
+
"-f",
|
|
125
|
+
"--find",
|
|
126
|
+
type=str,
|
|
127
|
+
help="Optional field to find prompt template(s) with keyword",
|
|
128
|
+
nargs="?",
|
|
129
|
+
)
|