aiverify-moonshot 0.4.0__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 (163) hide show
  1. aiverify_moonshot-0.4.0.dist-info/METADATA +249 -0
  2. aiverify_moonshot-0.4.0.dist-info/RECORD +163 -0
  3. aiverify_moonshot-0.4.0.dist-info/WHEEL +4 -0
  4. aiverify_moonshot-0.4.0.dist-info/licenses/AUTHORS.md +5 -0
  5. aiverify_moonshot-0.4.0.dist-info/licenses/LICENSE.md +201 -0
  6. aiverify_moonshot-0.4.0.dist-info/licenses/NOTICES.md +3340 -0
  7. moonshot/__init__.py +0 -0
  8. moonshot/__main__.py +198 -0
  9. moonshot/api.py +155 -0
  10. moonshot/integrations/__init__.py +0 -0
  11. moonshot/integrations/cli/__init__.py +0 -0
  12. moonshot/integrations/cli/__main__.py +25 -0
  13. moonshot/integrations/cli/active_session_cfg.py +1 -0
  14. moonshot/integrations/cli/benchmark/__init__.py +0 -0
  15. moonshot/integrations/cli/benchmark/benchmark.py +186 -0
  16. moonshot/integrations/cli/benchmark/cookbook.py +545 -0
  17. moonshot/integrations/cli/benchmark/datasets.py +164 -0
  18. moonshot/integrations/cli/benchmark/metrics.py +141 -0
  19. moonshot/integrations/cli/benchmark/recipe.py +598 -0
  20. moonshot/integrations/cli/benchmark/result.py +216 -0
  21. moonshot/integrations/cli/benchmark/run.py +140 -0
  22. moonshot/integrations/cli/benchmark/runner.py +174 -0
  23. moonshot/integrations/cli/cli.py +64 -0
  24. moonshot/integrations/cli/common/__init__.py +0 -0
  25. moonshot/integrations/cli/common/common.py +72 -0
  26. moonshot/integrations/cli/common/connectors.py +325 -0
  27. moonshot/integrations/cli/common/display_helper.py +42 -0
  28. moonshot/integrations/cli/common/prompt_template.py +94 -0
  29. moonshot/integrations/cli/initialisation/__init__.py +0 -0
  30. moonshot/integrations/cli/initialisation/initialisation.py +14 -0
  31. moonshot/integrations/cli/redteam/__init__.py +0 -0
  32. moonshot/integrations/cli/redteam/attack_module.py +70 -0
  33. moonshot/integrations/cli/redteam/context_strategy.py +147 -0
  34. moonshot/integrations/cli/redteam/prompt_template.py +67 -0
  35. moonshot/integrations/cli/redteam/redteam.py +90 -0
  36. moonshot/integrations/cli/redteam/session.py +467 -0
  37. moonshot/integrations/web_api/.env.dev +7 -0
  38. moonshot/integrations/web_api/__init__.py +0 -0
  39. moonshot/integrations/web_api/__main__.py +56 -0
  40. moonshot/integrations/web_api/app.py +125 -0
  41. moonshot/integrations/web_api/container.py +146 -0
  42. moonshot/integrations/web_api/log/.gitkeep +0 -0
  43. moonshot/integrations/web_api/logging_conf.py +114 -0
  44. moonshot/integrations/web_api/routes/__init__.py +0 -0
  45. moonshot/integrations/web_api/routes/attack_modules.py +66 -0
  46. moonshot/integrations/web_api/routes/benchmark.py +116 -0
  47. moonshot/integrations/web_api/routes/benchmark_result.py +175 -0
  48. moonshot/integrations/web_api/routes/context_strategy.py +129 -0
  49. moonshot/integrations/web_api/routes/cookbook.py +225 -0
  50. moonshot/integrations/web_api/routes/dataset.py +120 -0
  51. moonshot/integrations/web_api/routes/endpoint.py +282 -0
  52. moonshot/integrations/web_api/routes/metric.py +78 -0
  53. moonshot/integrations/web_api/routes/prompt_template.py +128 -0
  54. moonshot/integrations/web_api/routes/recipe.py +219 -0
  55. moonshot/integrations/web_api/routes/redteam.py +609 -0
  56. moonshot/integrations/web_api/routes/runner.py +239 -0
  57. moonshot/integrations/web_api/schemas/__init__.py +0 -0
  58. moonshot/integrations/web_api/schemas/benchmark_runner_dto.py +13 -0
  59. moonshot/integrations/web_api/schemas/cookbook_create_dto.py +19 -0
  60. moonshot/integrations/web_api/schemas/cookbook_response_model.py +9 -0
  61. moonshot/integrations/web_api/schemas/dataset_response_dto.py +9 -0
  62. moonshot/integrations/web_api/schemas/endpoint_create_dto.py +21 -0
  63. moonshot/integrations/web_api/schemas/endpoint_response_model.py +11 -0
  64. moonshot/integrations/web_api/schemas/prompt_response_model.py +14 -0
  65. moonshot/integrations/web_api/schemas/prompt_template_response_model.py +10 -0
  66. moonshot/integrations/web_api/schemas/recipe_create_dto.py +32 -0
  67. moonshot/integrations/web_api/schemas/recipe_response_model.py +7 -0
  68. moonshot/integrations/web_api/schemas/session_create_dto.py +16 -0
  69. moonshot/integrations/web_api/schemas/session_prompt_dto.py +7 -0
  70. moonshot/integrations/web_api/schemas/session_response_model.py +38 -0
  71. moonshot/integrations/web_api/services/__init__.py +0 -0
  72. moonshot/integrations/web_api/services/attack_module_service.py +34 -0
  73. moonshot/integrations/web_api/services/auto_red_team_test_manager.py +86 -0
  74. moonshot/integrations/web_api/services/auto_red_team_test_state.py +57 -0
  75. moonshot/integrations/web_api/services/base_service.py +8 -0
  76. moonshot/integrations/web_api/services/benchmark_result_service.py +25 -0
  77. moonshot/integrations/web_api/services/benchmark_test_manager.py +106 -0
  78. moonshot/integrations/web_api/services/benchmark_test_state.py +56 -0
  79. moonshot/integrations/web_api/services/benchmarking_service.py +31 -0
  80. moonshot/integrations/web_api/services/context_strategy_service.py +22 -0
  81. moonshot/integrations/web_api/services/cookbook_service.py +194 -0
  82. moonshot/integrations/web_api/services/dataset_service.py +20 -0
  83. moonshot/integrations/web_api/services/endpoint_service.py +65 -0
  84. moonshot/integrations/web_api/services/metric_service.py +14 -0
  85. moonshot/integrations/web_api/services/prompt_template_service.py +39 -0
  86. moonshot/integrations/web_api/services/recipe_service.py +155 -0
  87. moonshot/integrations/web_api/services/runner_service.py +147 -0
  88. moonshot/integrations/web_api/services/session_service.py +350 -0
  89. moonshot/integrations/web_api/services/utils/exceptions_handler.py +41 -0
  90. moonshot/integrations/web_api/services/utils/results_formatter.py +47 -0
  91. moonshot/integrations/web_api/status_updater/interface/benchmark_progress_callback.py +14 -0
  92. moonshot/integrations/web_api/status_updater/interface/redteam_progress_callback.py +14 -0
  93. moonshot/integrations/web_api/status_updater/moonshot_ui_webhook.py +72 -0
  94. moonshot/integrations/web_api/types/types.py +99 -0
  95. moonshot/src/__init__.py +0 -0
  96. moonshot/src/api/__init__.py +0 -0
  97. moonshot/src/api/api_connector.py +58 -0
  98. moonshot/src/api/api_connector_endpoint.py +162 -0
  99. moonshot/src/api/api_context_strategy.py +57 -0
  100. moonshot/src/api/api_cookbook.py +160 -0
  101. moonshot/src/api/api_dataset.py +46 -0
  102. moonshot/src/api/api_environment_variables.py +17 -0
  103. moonshot/src/api/api_metrics.py +51 -0
  104. moonshot/src/api/api_prompt_template.py +43 -0
  105. moonshot/src/api/api_recipe.py +182 -0
  106. moonshot/src/api/api_red_teaming.py +59 -0
  107. moonshot/src/api/api_result.py +84 -0
  108. moonshot/src/api/api_run.py +74 -0
  109. moonshot/src/api/api_runner.py +132 -0
  110. moonshot/src/api/api_session.py +290 -0
  111. moonshot/src/configs/__init__.py +0 -0
  112. moonshot/src/configs/env_variables.py +187 -0
  113. moonshot/src/connectors/__init__.py +0 -0
  114. moonshot/src/connectors/connector.py +327 -0
  115. moonshot/src/connectors/connector_prompt_arguments.py +17 -0
  116. moonshot/src/connectors_endpoints/__init__.py +0 -0
  117. moonshot/src/connectors_endpoints/connector_endpoint.py +211 -0
  118. moonshot/src/connectors_endpoints/connector_endpoint_arguments.py +54 -0
  119. moonshot/src/cookbooks/__init__.py +0 -0
  120. moonshot/src/cookbooks/cookbook.py +225 -0
  121. moonshot/src/cookbooks/cookbook_arguments.py +34 -0
  122. moonshot/src/datasets/__init__.py +0 -0
  123. moonshot/src/datasets/dataset.py +255 -0
  124. moonshot/src/datasets/dataset_arguments.py +50 -0
  125. moonshot/src/metrics/__init__.py +0 -0
  126. moonshot/src/metrics/metric.py +192 -0
  127. moonshot/src/metrics/metric_interface.py +95 -0
  128. moonshot/src/prompt_templates/__init__.py +0 -0
  129. moonshot/src/prompt_templates/prompt_template.py +103 -0
  130. moonshot/src/recipes/__init__.py +0 -0
  131. moonshot/src/recipes/recipe.py +340 -0
  132. moonshot/src/recipes/recipe_arguments.py +111 -0
  133. moonshot/src/redteaming/__init__.py +0 -0
  134. moonshot/src/redteaming/attack/__init__.py +0 -0
  135. moonshot/src/redteaming/attack/attack_module.py +618 -0
  136. moonshot/src/redteaming/attack/attack_module_arguments.py +44 -0
  137. moonshot/src/redteaming/attack/context_strategy.py +131 -0
  138. moonshot/src/redteaming/context_strategy/__init__.py +0 -0
  139. moonshot/src/redteaming/context_strategy/context_strategy_interface.py +46 -0
  140. moonshot/src/redteaming/session/__init__.py +0 -0
  141. moonshot/src/redteaming/session/chat.py +209 -0
  142. moonshot/src/redteaming/session/red_teaming_progress.py +128 -0
  143. moonshot/src/redteaming/session/red_teaming_type.py +6 -0
  144. moonshot/src/redteaming/session/session.py +775 -0
  145. moonshot/src/results/__init__.py +0 -0
  146. moonshot/src/results/result.py +119 -0
  147. moonshot/src/results/result_arguments.py +44 -0
  148. moonshot/src/runners/__init__.py +0 -0
  149. moonshot/src/runners/runner.py +476 -0
  150. moonshot/src/runners/runner_arguments.py +46 -0
  151. moonshot/src/runners/runner_type.py +6 -0
  152. moonshot/src/runs/__init__.py +0 -0
  153. moonshot/src/runs/run.py +344 -0
  154. moonshot/src/runs/run_arguments.py +162 -0
  155. moonshot/src/runs/run_progress.py +145 -0
  156. moonshot/src/runs/run_status.py +10 -0
  157. moonshot/src/storage/__init__.py +0 -0
  158. moonshot/src/storage/db_interface.py +128 -0
  159. moonshot/src/storage/io_interface.py +31 -0
  160. moonshot/src/storage/storage.py +525 -0
  161. moonshot/src/utils/__init__.py +0 -0
  162. moonshot/src/utils/import_modules.py +96 -0
  163. moonshot/src/utils/timeit.py +25 -0
moonshot/__init__.py ADDED
File without changes
moonshot/__main__.py ADDED
@@ -0,0 +1,198 @@
1
+ import sys
2
+ import warnings
3
+ import argparse
4
+ import platform
5
+ import subprocess
6
+ import os
7
+ import threading
8
+ from dotenv import dotenv_values
9
+ from moonshot.api import api_set_environment_variables
10
+ """
11
+ Run the Moonshot application
12
+ """
13
+ def run_subprocess(*args, **kwargs):
14
+ """
15
+ Run a subprocess with the option to use shell=True on Windows.
16
+ """
17
+ if platform.system() == "Windows":
18
+ kwargs["shell"] = True
19
+ return subprocess.run(*args, **kwargs)
20
+
21
+ def ms_lib_env_file(data_repo_name):
22
+ """
23
+ Writes the env file to be used for moonshot library
24
+ """
25
+ env_content_data = f"""
26
+ # For Data
27
+ ATTACK_MODULES="./{data_repo_name}/attack-modules"
28
+ CONNECTORS="./{data_repo_name}/connectors"
29
+ CONNECTORS_ENDPOINTS="./{data_repo_name}/connectors-endpoints"
30
+ CONTEXT_STRATEGY="./{data_repo_name}/context-strategy"
31
+ COOKBOOKS="./{data_repo_name}/cookbooks"
32
+ DATABASES="./{data_repo_name}/generated-outputs/databases"
33
+ DATABASES_MODULES="./{data_repo_name}/databases-modules"
34
+ DATASETS="./{data_repo_name}/datasets"
35
+ IO_MODULES="./{data_repo_name}/io-modules"
36
+ METRICS="./{data_repo_name}/metrics"
37
+ PROMPT_TEMPLATES="./{data_repo_name}/prompt-templates"
38
+ RECIPES="./{data_repo_name}/recipes"
39
+ RESULTS="./{data_repo_name}/generated-outputs/results"
40
+ RESULTS_MODULES="./{data_repo_name}/results-modules"
41
+ RUNNERS="./{data_repo_name}/generated-outputs/runners"
42
+ RUNNERS_MODULES="./{data_repo_name}/runners-modules"
43
+ TOKENIZERS_PARALLELISM = false
44
+ """
45
+
46
+ env_content_web_api = """
47
+ # For Web API
48
+ HOST_ADDRESS=127.0.0.1 # The interface the server will bind to
49
+ HOST_PORT=5000
50
+
51
+ # Below is the uri of the Web UI webhook.
52
+ # In the next section, if Web UI listens on a different port,
53
+ # update this uri accordingly and restart.
54
+
55
+ MOONSHOT_UI_CALLBACK_URL=http://localhost:3000/api/v1/benchmarks/status
56
+ """
57
+ with open(".env", "w") as env_file:
58
+ combined_content = env_content_data + env_content_web_api
59
+ env_file.write(combined_content.strip())
60
+
61
+ def ms_ui_env_file(ui_repo):
62
+ """
63
+ Write the env file to be used with moonshot ui
64
+ """
65
+ env_content = """
66
+ # This should be the URL of the Moonshot Web Api module which was started in the previous section.
67
+ # Check the startup logs to determine the hostname and port number.
68
+ MOONSHOT_API_URL=http://127.0.0.1:5000
69
+ """
70
+ # Write the .env content to a file
71
+ with open(os.path.join(ui_repo, ".env"), "w") as env_file:
72
+ env_file.write(env_content.strip())
73
+
74
+ def moonshot_data_installation():
75
+ # Code for moonshot-data installation
76
+ print("Installing Moonshot Data from GitHub")
77
+ repo = "https://github.com/aiverify-foundation/moonshot-data.git"
78
+ folder_name = repo.split("/")[-1].replace(".git", "")
79
+
80
+ # Check if the directory already exists
81
+ if not os.path.exists(folder_name):
82
+ print(f"Cloning {repo}")
83
+ # Clone the repository
84
+ run_subprocess(["git", "clone", repo], check=True)
85
+
86
+ # Change directory to the folder
87
+ os.chdir(folder_name)
88
+
89
+ print(f"Installing requirements for {folder_name}")
90
+ # Install the requirements if they exist
91
+ if os.path.exists("requirements.txt"):
92
+ run_subprocess(["pip", "install", "-r", "requirements.txt"], check=True)
93
+ import nltk
94
+ nltk.download('punkt')
95
+ nltk.download('stopwords')
96
+ nltk.download('averaged_perceptron_tagger')
97
+ nltk.download('universal_tagset')
98
+
99
+ # Change back to the base directory
100
+ os.chdir("..")
101
+
102
+ # Create .env to point to installed folder
103
+ ms_lib_env_file(folder_name)
104
+ else:
105
+ print(f"Directory {folder_name} already exists, skipping clone.")
106
+
107
+ def moonshot_ui_installation():
108
+ # Code for moonshot-ui installation
109
+ repo = "https://github.com/aiverify-foundation/moonshot-ui.git"
110
+ folder_name = repo.split("/")[-1].replace(".git", "")
111
+
112
+ # Check if the directory already exists
113
+ if not os.path.exists(folder_name):
114
+ print(f"Cloning {repo}")
115
+ # Clone the repository
116
+ run_subprocess(["git", "clone", repo], check=True)
117
+
118
+ # Change directory to the folder
119
+ os.chdir(folder_name)
120
+
121
+ print(f"Installing requirements for {folder_name}")
122
+ # Install the requirements if they exist
123
+ if os.path.exists("package.json"):
124
+ run_subprocess(["npm", "install"], check=True)
125
+ run_subprocess(["npm", "run", "build"], check=True)
126
+
127
+ # Change back to the base directory
128
+ os.chdir("..")
129
+
130
+ # Create .env for ui
131
+ ms_ui_env_file(folder_name)
132
+ else:
133
+ print(f"Directory {folder_name} already exists, skipping installation.")
134
+
135
+ def run_moonshot_ui_dev():
136
+ """
137
+ To start a thread to run the Moonshot UI
138
+ """
139
+ base_directory = os.getcwd()
140
+ ui_dev_dir = os.path.join(base_directory, "moonshot-ui")
141
+
142
+ if not os.path.exists(ui_dev_dir):
143
+ print("moonshot-ui does not exist. Please run with '-i moonshot-ui' to install moonshot-ui first.")
144
+ sys.exit(1)
145
+ # ms_ui_env_file(ui_dev_dir)
146
+ run_subprocess(['npm', 'start'], cwd=ui_dev_dir)
147
+
148
+ def main():
149
+ parser = argparse.ArgumentParser(description="Run the Moonshot application")
150
+ parser.add_argument('mode', nargs='?', choices=['web-api', 'cli', 'web', 'help'], help='Mode to run Moonshot in', default=help)
151
+ parser.add_argument('cli_command', nargs='?', help='The CLI command to run (e.g., "interactive")')
152
+ parser.add_argument('-i', '--install', action='append', choices=['moonshot-data', 'moonshot-ui'], help='Modules to install', default=[])
153
+ parser.add_argument('-e', '--env', type=str, help='Path to the .env file', default='.env')
154
+
155
+ args = parser.parse_args()
156
+
157
+ # Handle installations based on the -i include arguments
158
+ if 'moonshot-data' in args.install:
159
+ moonshot_data_installation()
160
+
161
+ if 'moonshot-ui' in args.install:
162
+ moonshot_ui_installation()
163
+
164
+ # If mode is not specified, skip running any modes
165
+ if args.mode is None:
166
+ return
167
+
168
+ if args.mode == "help":
169
+ parser.print_help()
170
+ sys.exit(1)
171
+
172
+ api_set_environment_variables(dotenv_values(args.env))
173
+
174
+ if args.mode == "web-api":
175
+ from moonshot.integrations.web_api import __main__ as web_api
176
+ web_api.start_app()
177
+ elif args.mode == "web":
178
+ # Create and start the UI dev server thread
179
+ ui_thread = threading.Thread(target=run_moonshot_ui_dev)
180
+ ui_thread.start()
181
+ ui_thread.join(timeout=0.1) # Wait briefly for the thread to become alive
182
+ if not ui_thread.is_alive():
183
+ sys.exit(1)
184
+ from moonshot.integrations.web_api import __main__ as web_api
185
+ web_api.start_app()
186
+ elif args.mode == "cli":
187
+ from moonshot.integrations.cli import __main__ as cli
188
+ cli.start_app(args.cli_command)
189
+
190
+ # Handle CLI mode here, possibly also with additional arguments
191
+ pass
192
+ else:
193
+ parser.print_help()
194
+ sys.exit(1)
195
+
196
+ if __name__ == "__main__":
197
+ warnings.filterwarnings("ignore")
198
+ main()
moonshot/api.py ADDED
@@ -0,0 +1,155 @@
1
+ from moonshot.src.api.api_connector import (
2
+ api_create_connector_from_endpoint,
3
+ api_create_connectors_from_endpoints,
4
+ api_get_all_connector_type,
5
+ )
6
+ from moonshot.src.api.api_connector_endpoint import (
7
+ api_create_endpoint,
8
+ api_delete_endpoint,
9
+ api_get_all_endpoint,
10
+ api_get_all_endpoint_name,
11
+ api_read_endpoint,
12
+ api_update_endpoint,
13
+ )
14
+ from moonshot.src.api.api_context_strategy import (
15
+ api_delete_context_strategy,
16
+ api_get_all_context_strategies,
17
+ api_get_all_context_strategy_metadata,
18
+ )
19
+ from moonshot.src.api.api_cookbook import (
20
+ api_create_cookbook,
21
+ api_delete_cookbook,
22
+ api_get_all_cookbook,
23
+ api_get_all_cookbook_name,
24
+ api_read_cookbook,
25
+ api_read_cookbooks,
26
+ api_update_cookbook,
27
+ )
28
+ from moonshot.src.api.api_dataset import (
29
+ api_delete_dataset,
30
+ api_get_all_datasets,
31
+ api_get_all_datasets_name,
32
+ )
33
+ from moonshot.src.api.api_environment_variables import api_set_environment_variables
34
+ from moonshot.src.api.api_metrics import (
35
+ api_delete_metric,
36
+ api_get_all_metric,
37
+ api_get_all_metric_name,
38
+ )
39
+ from moonshot.src.api.api_prompt_template import (
40
+ api_delete_prompt_template,
41
+ api_get_all_prompt_template_detail,
42
+ api_get_all_prompt_template_name,
43
+ )
44
+ from moonshot.src.api.api_recipe import (
45
+ api_create_recipe,
46
+ api_delete_recipe,
47
+ api_get_all_recipe,
48
+ api_get_all_recipe_name,
49
+ api_read_recipe,
50
+ api_read_recipes,
51
+ api_update_recipe,
52
+ )
53
+ from moonshot.src.api.api_red_teaming import (
54
+ api_delete_attack_module,
55
+ api_get_all_attack_module_metadata,
56
+ api_get_all_attack_modules,
57
+ )
58
+ from moonshot.src.api.api_result import (
59
+ api_delete_result,
60
+ api_get_all_result,
61
+ api_get_all_result_name,
62
+ api_read_result,
63
+ api_read_results,
64
+ )
65
+ from moonshot.src.api.api_run import api_get_all_run
66
+ from moonshot.src.api.api_runner import (
67
+ api_create_runner,
68
+ api_delete_runner,
69
+ api_get_all_runner,
70
+ api_get_all_runner_name,
71
+ api_load_runner,
72
+ api_read_runner,
73
+ )
74
+ from moonshot.src.api.api_session import (
75
+ api_create_session,
76
+ api_delete_session,
77
+ api_get_all_chats_from_session,
78
+ api_get_all_session_metadata,
79
+ api_get_all_session_names,
80
+ api_get_available_session_info,
81
+ api_load_session,
82
+ api_update_attack_module,
83
+ api_update_context_strategy,
84
+ api_update_cs_num_of_prev_prompts,
85
+ api_update_metric,
86
+ api_update_prompt_template,
87
+ api_update_system_prompt,
88
+ )
89
+
90
+ __all__ = [
91
+ "api_create_connector_from_endpoint",
92
+ "api_create_connectors_from_endpoints",
93
+ "api_get_all_connector_type",
94
+ "api_create_endpoint",
95
+ "api_delete_endpoint",
96
+ "api_get_all_endpoint",
97
+ "api_get_all_endpoint_name",
98
+ "api_read_endpoint",
99
+ "api_update_endpoint",
100
+ "api_delete_context_strategy",
101
+ "api_get_all_context_strategies",
102
+ "api_get_all_context_strategy_metadata",
103
+ "api_create_cookbook",
104
+ "api_delete_cookbook",
105
+ "api_get_all_cookbook",
106
+ "api_get_all_cookbook_name",
107
+ "api_read_cookbook",
108
+ "api_read_cookbooks",
109
+ "api_update_cookbook",
110
+ "api_delete_dataset",
111
+ "api_get_all_datasets",
112
+ "api_get_all_datasets_name",
113
+ "api_set_environment_variables",
114
+ "api_delete_metric",
115
+ "api_get_all_metric",
116
+ "api_get_all_metric_name",
117
+ "api_get_all_prompt_template_detail",
118
+ "api_get_all_prompt_template_name",
119
+ "api_delete_prompt_template",
120
+ "api_create_recipe",
121
+ "api_delete_recipe",
122
+ "api_get_all_recipe",
123
+ "api_get_all_recipe_name",
124
+ "api_read_recipe",
125
+ "api_read_recipes",
126
+ "api_update_recipe",
127
+ "api_get_all_attack_module_metadata",
128
+ "api_get_all_attack_modules",
129
+ "api_delete_attack_module",
130
+ "api_delete_result",
131
+ "api_get_all_result",
132
+ "api_get_all_result_name",
133
+ "api_read_result",
134
+ "api_read_results",
135
+ "api_get_all_run",
136
+ "api_create_runner",
137
+ "api_delete_runner",
138
+ "api_get_all_runner",
139
+ "api_get_all_runner_name",
140
+ "api_load_runner",
141
+ "api_read_runner",
142
+ "api_create_session",
143
+ "api_delete_session",
144
+ "api_get_all_chats_from_session",
145
+ "api_get_all_session_metadata",
146
+ "api_get_all_session_names",
147
+ "api_get_available_session_info",
148
+ "api_load_session",
149
+ "api_update_attack_module",
150
+ "api_update_context_strategy",
151
+ "api_update_cs_num_of_prev_prompts",
152
+ "api_update_metric",
153
+ "api_update_prompt_template",
154
+ "api_update_system_prompt",
155
+ ]
File without changes
File without changes
@@ -0,0 +1,25 @@
1
+ import sys
2
+ import warnings
3
+
4
+ from moonshot.integrations.cli.cli import CommandLineInterface
5
+
6
+
7
+ def start_app(cli_command = None):
8
+ """
9
+ Run the Moonshot application
10
+ """
11
+ # Setting the warnings to be ignored
12
+ warnings.filterwarnings("ignore")
13
+
14
+ cli_instance = CommandLineInterface()
15
+ if cli_command == "interactive":
16
+ # Run in interactive mode
17
+ cli_instance.debug = False
18
+ cli_instance.cmdloop("Starting moonshot interactive prompt...")
19
+ elif cli_command:
20
+ # Run a specific command
21
+ cli_instance.onecmd(cli_command)
22
+ else:
23
+ # Show help if no command is provided
24
+ cli_instance.onecmd("help")
25
+
@@ -0,0 +1 @@
1
+ active_session = {}
File without changes
@@ -0,0 +1,186 @@
1
+ import argparse
2
+
3
+ import cmd2
4
+
5
+ from moonshot.integrations.cli.benchmark.cookbook import (
6
+ add_cookbook,
7
+ add_cookbook_args,
8
+ delete_cookbook,
9
+ delete_cookbook_args,
10
+ list_cookbooks,
11
+ run_cookbook,
12
+ run_cookbook_args,
13
+ update_cookbook,
14
+ update_cookbook_args,
15
+ view_cookbook,
16
+ view_cookbook_args,
17
+ )
18
+ from moonshot.integrations.cli.benchmark.datasets import (
19
+ delete_dataset,
20
+ delete_dataset_args,
21
+ list_datasets,
22
+ view_dataset,
23
+ view_dataset_args,
24
+ )
25
+ from moonshot.integrations.cli.benchmark.metrics import (
26
+ delete_metric,
27
+ delete_metric_args,
28
+ list_metrics,
29
+ view_metric,
30
+ view_metric_args,
31
+ )
32
+ from moonshot.integrations.cli.benchmark.recipe import (
33
+ add_recipe,
34
+ add_recipe_args,
35
+ delete_recipe,
36
+ delete_recipe_args,
37
+ list_recipes,
38
+ run_recipe,
39
+ run_recipe_args,
40
+ update_recipe,
41
+ update_recipe_args,
42
+ view_recipe,
43
+ view_recipe_args,
44
+ )
45
+ from moonshot.integrations.cli.benchmark.result import (
46
+ delete_result,
47
+ delete_result_args,
48
+ list_results,
49
+ view_result,
50
+ view_result_args,
51
+ )
52
+ from moonshot.integrations.cli.benchmark.run import list_runs, view_run, view_run_args
53
+ from moonshot.integrations.cli.benchmark.runner import (
54
+ delete_runner,
55
+ delete_runner_args,
56
+ list_runners,
57
+ view_runner,
58
+ view_runner_args,
59
+ )
60
+
61
+
62
+ @cmd2.with_default_category("Moonshot Benchmarking")
63
+ class BenchmarkCommandSet(cmd2.CommandSet):
64
+ def __init__(self):
65
+ super().__init__()
66
+
67
+ # ------------------------------------------------------------------------------
68
+ # List contents
69
+ # ------------------------------------------------------------------------------
70
+
71
+ def do_list_cookbooks(self, _: cmd2.Statement) -> None:
72
+ list_cookbooks()
73
+
74
+ def do_list_recipes(self, _: cmd2.Statement) -> None:
75
+ list_recipes()
76
+
77
+ def do_list_results(self, _: cmd2.Statement) -> None:
78
+ list_results()
79
+
80
+ def do_list_runners(self, _: cmd2.Statement) -> None:
81
+ list_runners()
82
+
83
+ def do_list_runs(self, _: cmd2.Statement) -> None:
84
+ list_runs()
85
+
86
+ def do_list_metrics(self, _: cmd2.Statement) -> None:
87
+ list_metrics()
88
+
89
+ def do_list_datasets(self, _: cmd2.Statement) -> None:
90
+ list_datasets()
91
+
92
+ # ------------------------------------------------------------------------------
93
+ # Add contents
94
+ # ------------------------------------------------------------------------------
95
+
96
+ @cmd2.with_argparser(add_cookbook_args)
97
+ def do_add_cookbook(self, args: argparse.Namespace) -> None:
98
+ add_cookbook(args)
99
+
100
+ @cmd2.with_argparser(add_recipe_args)
101
+ def do_add_recipe(self, args: argparse.Namespace) -> None:
102
+ add_recipe(args)
103
+
104
+ # ------------------------------------------------------------------------------
105
+ # Delete contents
106
+ # ------------------------------------------------------------------------------
107
+
108
+ @cmd2.with_argparser(delete_cookbook_args)
109
+ def do_delete_cookbook(self, args: argparse.Namespace) -> None:
110
+ delete_cookbook(args)
111
+
112
+ @cmd2.with_argparser(delete_recipe_args)
113
+ def do_delete_recipe(self, args: argparse.Namespace) -> None:
114
+ delete_recipe(args)
115
+
116
+ @cmd2.with_argparser(delete_result_args)
117
+ def do_delete_result(self, args: argparse.Namespace) -> None:
118
+ delete_result(args)
119
+
120
+ @cmd2.with_argparser(delete_runner_args)
121
+ def do_delete_runner(self, args: argparse.Namespace) -> None:
122
+ delete_runner(args)
123
+
124
+ @cmd2.with_argparser(delete_metric_args)
125
+ def do_delete_metric(self, args: argparse.Namespace) -> None:
126
+ delete_metric(args)
127
+
128
+ @cmd2.with_argparser(delete_dataset_args)
129
+ def do_delete_dataset(self, args: argparse.Namespace) -> None:
130
+ delete_dataset(args)
131
+
132
+ # ------------------------------------------------------------------------------
133
+ # Update contents
134
+ # ------------------------------------------------------------------------------
135
+
136
+ @cmd2.with_argparser(update_cookbook_args)
137
+ def do_update_cookbook(self, args: argparse.Namespace) -> None:
138
+ update_cookbook(args)
139
+
140
+ @cmd2.with_argparser(update_recipe_args)
141
+ def do_update_recipe(self, args: argparse.Namespace) -> None:
142
+ update_recipe(args)
143
+
144
+ # ------------------------------------------------------------------------------
145
+ # Run contents
146
+ # ------------------------------------------------------------------------------
147
+
148
+ @cmd2.with_argparser(run_cookbook_args)
149
+ def do_run_cookbook(self, args: argparse.Namespace) -> None:
150
+ run_cookbook(args)
151
+
152
+ @cmd2.with_argparser(run_recipe_args)
153
+ def do_run_recipe(self, args: argparse.Namespace) -> None:
154
+ run_recipe(args)
155
+
156
+ # ------------------------------------------------------------------------------
157
+ # View contents
158
+ # ------------------------------------------------------------------------------
159
+
160
+ @cmd2.with_argparser(view_cookbook_args)
161
+ def do_view_cookbook(self, args: argparse.Namespace) -> None:
162
+ view_cookbook(args)
163
+
164
+ @cmd2.with_argparser(view_recipe_args)
165
+ def do_view_recipe(self, args: argparse.Namespace) -> None:
166
+ view_recipe(args)
167
+
168
+ @cmd2.with_argparser(view_result_args)
169
+ def do_view_result(self, args: argparse.Namespace) -> None:
170
+ view_result(args)
171
+
172
+ @cmd2.with_argparser(view_runner_args)
173
+ def do_view_runner(self, args: argparse.Namespace) -> None:
174
+ view_runner(args)
175
+
176
+ @cmd2.with_argparser(view_run_args)
177
+ def do_view_run(self, args: argparse.Namespace) -> None:
178
+ view_run(args)
179
+
180
+ @cmd2.with_argparser(view_metric_args)
181
+ def do_view_metric(self, args: argparse.Namespace) -> None:
182
+ view_metric(args)
183
+
184
+ @cmd2.with_argparser(view_dataset_args)
185
+ def do_view_dataset(self, args: argparse.Namespace) -> None:
186
+ view_dataset(args)