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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: aiverify-moonshot
3
- Version: 0.4.4
3
+ Version: 0.4.6
4
4
  Summary: AI Verify advances Gen AI testing with Project Moonshot.
5
5
  Project-URL: Repository, https://github.com/aiverify-foundation/moonshot
6
6
  Project-URL: Documentation, https://aiverify-foundation.github.io/moonshot/
@@ -18,6 +18,7 @@ Requires-Python: >=3.11
18
18
  Requires-Dist: datasets==2.20.0
19
19
  Requires-Dist: ijson==3.3.0
20
20
  Requires-Dist: jinja2==3.1.4
21
+ Requires-Dist: numpy==1.26.4
21
22
  Requires-Dist: pandas==2.2.2
22
23
  Requires-Dist: pydantic==2.8.2
23
24
  Requires-Dist: pyparsing==3.1.2
@@ -45,7 +46,7 @@ Description-Content-Type: text/markdown
45
46
 
46
47
  ![Moonshot Logo](https://github.com/aiverify-foundation/moonshot/raw/main/misc/aiverify-moonshot-logo.png)
47
48
 
48
- **Version 0.4.4**
49
+ **Version 0.4.6**
49
50
 
50
51
  A simple and modular tool to evaluate any LLM application.
51
52
 
@@ -1,26 +1,27 @@
1
1
  moonshot/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- moonshot/__main__.py,sha256=NB_sWjPRcwr8BbFXtih2y3fbVYPZ1YS5dI_bNNaTD3U,7551
2
+ moonshot/__main__.py,sha256=owir7ug4VzfPwG7hSYTrN03SRpHMiLUifoEe_-IaeYw,9908
3
3
  moonshot/api.py,sha256=f7vIMlpC-1ZQsbqipe2cTlP5dwgoVujQKYNxzEKcWlg,4822
4
4
  moonshot/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  moonshot/integrations/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  moonshot/integrations/cli/__main__.py,sha256=0VnYSj2AayvDCZ3uXpldPcjMHt2Yd7BWojWzFOGSSl4,679
7
7
  moonshot/integrations/cli/active_session_cfg.py,sha256=n8hOFxFjvz26qbEFY4q7iPUZYrGLoeCmXJxmOb_xWUE,20
8
8
  moonshot/integrations/cli/cli.py,sha256=9tnzcxcSOjblxCUpyh3pK0ke0bLs3s-63OxXtYoZI2g,2769
9
+ moonshot/integrations/cli/cli_errors.py,sha256=BhA7k7leuPe3ms2W25iip_yqjrhWKmTaZ2iz1OSjBvE,22981
9
10
  moonshot/integrations/cli/benchmark/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
11
  moonshot/integrations/cli/benchmark/benchmark.py,sha256=QUxr6DU11-XeH6Y3j1uPsZsotshgy64G_cWNf0Rn2_U,6303
11
- moonshot/integrations/cli/benchmark/cookbook.py,sha256=9mNuqsaVFCfXnLgVxJQ-fzwSgH8j082NR2gE-GPQbG8,22183
12
- moonshot/integrations/cli/benchmark/datasets.py,sha256=E-kreuXkrNU39sFuVWGhutFHfoEhsVjFK4tmq7YQwxs,7193
13
- moonshot/integrations/cli/benchmark/metrics.py,sha256=6wLn3WyqgUJKCRvblxiyx8X4nQ7gA1sKGcC_DNBIWBo,6351
14
- moonshot/integrations/cli/benchmark/recipe.py,sha256=EYv94Qjq2hqn1zz9NzWaINEY9DNdY7TkSS57xHv6ymQ,22698
15
- moonshot/integrations/cli/benchmark/result.py,sha256=U0SsjJYNQJYP_EZ3pAil4VaOQLMZHchfzq982nXU-jE,9486
16
- moonshot/integrations/cli/benchmark/run.py,sha256=Rqdb_FspgQQhkLORjgdiyaijk7HTxM39giOzXpBXA1k,6161
17
- moonshot/integrations/cli/benchmark/runner.py,sha256=nAnNKihQD0AScl6vPFiFH_9MZU4ppeMG34QaLRidqvU,6602
12
+ moonshot/integrations/cli/benchmark/cookbook.py,sha256=h9exPhLKLRa9a1qWB2WptZ35gcVov332tjHDO9ECs0o,29639
13
+ moonshot/integrations/cli/benchmark/datasets.py,sha256=Uq5XMNWUp775sz9jCZUZHHmkumPFI7cHVRueHgWm70Q,8965
14
+ moonshot/integrations/cli/benchmark/metrics.py,sha256=ATZtVOj3kjGuyxOgfAO1QzTDeAOEjbSeQYr3NOCmTCQ,8070
15
+ moonshot/integrations/cli/benchmark/recipe.py,sha256=yVFX3pwNzDL0a95rjlQd4cek06M9blv5jIeYB26jOKk,32481
16
+ moonshot/integrations/cli/benchmark/result.py,sha256=TGlIuDkPB1Cfu1u2uyDsWtgQxTOoNdGDzc0vCnGC1zk,11152
17
+ moonshot/integrations/cli/benchmark/run.py,sha256=HBztvG_Zkg1ZAWsFv0QDE43FaEmx92vTWc4h1U3VesU,7438
18
+ moonshot/integrations/cli/benchmark/runner.py,sha256=Y4Vt6Qqn9QzsM6eLUM9m2_XKkW3ctu-2jMTSei_TDPU,7098
18
19
  moonshot/integrations/cli/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
20
  moonshot/integrations/cli/common/common.py,sha256=hSvxj-T91nhKfJtQqxrIPgYdS8P_g7wbOwpFpqBg90I,3090
20
- moonshot/integrations/cli/common/connectors.py,sha256=8_U7KJzfsS9L13dMbouk5JKOy_ow4UhrILICCw27Q5c,13909
21
- moonshot/integrations/cli/common/dataset.py,sha256=KZuwSV4Di7C378Aa2bRxIKCd03oo6HdMTEZpBZSQb5w,3113
21
+ moonshot/integrations/cli/common/connectors.py,sha256=0KoCji-a6AJ0GLqpDdgm4mcfj-FzNW2DOsuQ0Fi_gwc,19445
22
+ moonshot/integrations/cli/common/dataset.py,sha256=6v5qXgWBGhT4Rl5uuqPMwLeFF0c5m7ECzyGe1IFXNW0,4743
22
23
  moonshot/integrations/cli/common/display_helper.py,sha256=8rVowW33XK0j0C_X_H1jUbFlFk1Y2WpzxmIUE3Ca5Co,1459
23
- moonshot/integrations/cli/common/prompt_template.py,sha256=KzawF2VaiWUKzRIrXX_TaHboiPVllSiqz5I_o2TqGiA,4812
24
+ moonshot/integrations/cli/common/prompt_template.py,sha256=2cXWeHh16EUvzYFre7juMxT2R0x3kqDJVucH0bKLmCU,6351
24
25
  moonshot/integrations/cli/initialisation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
26
  moonshot/integrations/cli/initialisation/initialisation.py,sha256=zMjklhoBlYLPshe7Q16vBBbOfhbPjZc4_ooywAFp2XY,387
26
27
  moonshot/integrations/cli/redteam/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -28,12 +29,12 @@ moonshot/integrations/cli/redteam/attack_module.py,sha256=sjjQdBno7rXNfrXqns55ER
28
29
  moonshot/integrations/cli/redteam/context_strategy.py,sha256=gLNgnd1oHWD1X93BQoKlR7G8b5g9P6AcKFLlE3WvETk,7065
29
30
  moonshot/integrations/cli/redteam/prompt_template.py,sha256=rWINvMFLax8ynIFJoX93xsB1cWJ8-dQ1nRyqgdri2yQ,2079
30
31
  moonshot/integrations/cli/redteam/redteam.py,sha256=144tVuiSWBLseC0EvvIuevHYJhqn39xvg36-1cLgGWQ,4257
31
- moonshot/integrations/cli/redteam/session.py,sha256=auZ73LfMAGmT1jLJUjqY6oAsMWoSzHstiRGA8DKF6A4,33652
32
+ moonshot/integrations/cli/redteam/session.py,sha256=lucUS8Ejcg9PQKVhVj1VUZECe2pvFwbwoSbsVl0BazI,37672
32
33
  moonshot/integrations/cli/utils/process_data.py,sha256=QVL5vp2_8ZgGicmCAdeYEHkeb6f-NC775-JCzWziNiU,1901
33
34
  moonshot/integrations/web_api/.env.dev,sha256=0z5_Ut8rF-UqFZtgjkH2qoqORhD5_nSs2w_OeX2SteI,182
34
35
  moonshot/integrations/web_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
36
  moonshot/integrations/web_api/__main__.py,sha256=MdnLi_ZF-olAAEJwTPU1iGYFYwo-fNWNT2qfchkH3y4,2050
36
- moonshot/integrations/web_api/app.py,sha256=rrL-N4cVO1qBQ5v6y039jfMqUdSC9jyqsgCudmyfZx0,3651
37
+ moonshot/integrations/web_api/app.py,sha256=x9QTqkHy4zfnQTA0UJVFHht0vSuDs1BZphjLfhFjsVY,3651
37
38
  moonshot/integrations/web_api/container.py,sha256=DVkJG_qm7ItcG6tgMYOqIj07wpKhPWOOfy6-bEv72y4,5915
38
39
  moonshot/integrations/web_api/logging_conf.py,sha256=t3EGRV6tZhV732KXe8_Tiy0fiwVAWxZX5Tt8VTgrrfg,3388
39
40
  moonshot/integrations/web_api/log/.gitkeep,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -41,7 +42,7 @@ moonshot/integrations/web_api/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeu
41
42
  moonshot/integrations/web_api/routes/attack_modules.py,sha256=m0mGGTEHyaVld8WYHXxQ5Gm0sKdTqy_rJUrNVFcgVgw,2413
42
43
  moonshot/integrations/web_api/routes/benchmark.py,sha256=RRzouKcoVNYXm7o1LadsZTgzfmUsaYdQTC0AfsLdiC4,4163
43
44
  moonshot/integrations/web_api/routes/benchmark_result.py,sha256=WZ_dI8qT4dli9hKPNkhSwhdfz2VfW5BshirpEVEUci4,6351
44
- moonshot/integrations/web_api/routes/bookmark.py,sha256=K-1jL0IwOYvmYpgJvU65-lRfQlQhMzJk_n-Zf92IeR0,6135
45
+ moonshot/integrations/web_api/routes/bookmark.py,sha256=aHUT86Llbzqo1CT3Dy7ciIhxVEzu1YgZk_VkxVeOZ3s,6304
45
46
  moonshot/integrations/web_api/routes/context_strategy.py,sha256=kJTpjrwxfYGyBLY_hAgpHOMZMtjV5Z6vpu7RIdHDylg,4828
46
47
  moonshot/integrations/web_api/routes/cookbook.py,sha256=oddmcdfhgH3qZb4_ThfUk8SBKmHOt51dFlAHubQh2fQ,8648
47
48
  moonshot/integrations/web_api/routes/dataset.py,sha256=qtxflHRDr31W3u6voOFE5iRHsCVr0MQ35H94Pw5M1YU,6114
@@ -95,8 +96,9 @@ moonshot/integrations/web_api/status_updater/interface/redteam_progress_callback
95
96
  moonshot/integrations/web_api/temp/.gitkeep,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
96
97
  moonshot/integrations/web_api/types/types.py,sha256=AN0Xf61lx2c5AFAYoXA8mVL5iufVBpwYlIPdo8gv-ls,2395
97
98
  moonshot/src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
99
+ moonshot/src/messages_constants.py,sha256=pFhm7c2UkdX-XPr62bj6mArf5xrRmktuh_ZiUICJHd0,2352
98
100
  moonshot/src/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
99
- moonshot/src/api/api_bookmark.py,sha256=Nr0B3S6UUnNbuvXyL-dz8IMyFxCywU1u4UL2D8TjHik,3004
101
+ moonshot/src/api/api_bookmark.py,sha256=FhtSojdw8wfzJXQnH9VnkwsuqRf_c_y6LH0oOQA48Dc,2926
100
102
  moonshot/src/api/api_connector.py,sha256=JpwLFd7Vh1LRz6oB8fhO2iufMbSTt5RmrMe7nt56bPM,2257
101
103
  moonshot/src/api/api_connector_endpoint.py,sha256=UUuHzrgoj0bWcbOXPUJh7FEg-pzBOSo6DLgwqCZnLmw,5503
102
104
  moonshot/src/api/api_context_strategy.py,sha256=WqzUEw3f7gROJlc_G7bsGkuP3nO1HycFzn3dfcxzaoc,2153
@@ -111,10 +113,10 @@ moonshot/src/api/api_result.py,sha256=M5zKF7ytKp237UZusLSYJ7QVfui85Ys0WEaYySGcAK
111
113
  moonshot/src/api/api_run.py,sha256=3PrETAVcFnJ09R0-xhWiFkEfqL6eYj4B2voEGJDPznU,2936
112
114
  moonshot/src/api/api_runner.py,sha256=cH0rxWREjc2qKmt4Tuwr-fEMrYDBE_TKRw0jOohNEgU,4179
113
115
  moonshot/src/api/api_session.py,sha256=OGH05ZxAwo_hKI-RNaJ-jCp_v-zcTm-9bHUclpq2z4Q,10978
114
- moonshot/src/bookmark/bookmark.py,sha256=KZoKOyJseW02IS5KqfCIMusFiNwESBxOAvOZTwO7YUw,8867
115
- moonshot/src/bookmark/bookmark_arguments.py,sha256=rwgUPMXmDLNaHfJvRTR4GaZ8vwRilchzOg9bZJQoe_8,1130
116
+ moonshot/src/bookmark/bookmark.py,sha256=5TJ-q7mGpULqaH5osdB2kThP4bKMIO6nWqrXhvjAy4U,11270
117
+ moonshot/src/bookmark/bookmark_arguments.py,sha256=cB5m2zB8255WVdacmC2-ZYNyaoK4-gOM_Qwb_JDR-34,1449
116
118
  moonshot/src/configs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
117
- moonshot/src/configs/env_variables.py,sha256=leemw8TNM6GI_6iaajFb49zv1K3hWB0EpZfO0p9CWZQ,7100
119
+ moonshot/src/configs/env_variables.py,sha256=eF__UJN37LCzIB4pv_T7G-kQHlOa657QA7IpL1d_0MM,7150
118
120
  moonshot/src/connectors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
119
121
  moonshot/src/connectors/connector.py,sha256=e0ZCX9m83ezjMiY5H8gbWE64IStsNQqxzVwGtMwShPY,13396
120
122
  moonshot/src/connectors/connector_prompt_arguments.py,sha256=cIlAgbFk2g_XUZ0stVM904Ng2g4GYP2LyiAjktmhEQM,470
@@ -151,11 +153,11 @@ moonshot/src/results/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
151
153
  moonshot/src/results/result.py,sha256=o56SdhYH-XVfpeeKhN495dJPkU035MmTjRUx48q53lo,4527
152
154
  moonshot/src/results/result_arguments.py,sha256=mTR7yajY72PFglfAaa1ajJfvYNV4IBGLXS4VaD53-8c,1334
153
155
  moonshot/src/runners/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
154
- moonshot/src/runners/runner.py,sha256=Wsvdzcw4KOa-ppgGVRGSK2YxLfXK-daHDw3k5jETv-4,21197
156
+ moonshot/src/runners/runner.py,sha256=nnYiMHZUSu35jzHoeiEqADhc7iHLKnViyUbd_Qg8WZs,21203
155
157
  moonshot/src/runners/runner_arguments.py,sha256=Bg4OPSmgr9jZKNAwPH0T3epEHw-6qGrflszFc6oMyEU,1640
156
158
  moonshot/src/runners/runner_type.py,sha256=jOfnAnaCYp-rPTRJXhM8hin_dinlR0sMwmimQXvLcJ0,100
157
159
  moonshot/src/runs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
158
- moonshot/src/runs/run.py,sha256=QFdvWwCnqSjLrsTk3jJ1ccs3R1ZAZNvz5ls9Q_iRxO0,14132
160
+ moonshot/src/runs/run.py,sha256=3Y_256IfOv5zpeujVPsA5YdX7uZjGMRvg0VencUwgLw,14339
159
161
  moonshot/src/runs/run_arguments.py,sha256=G043ERvHIU_dd0JghboZgxDWCcjYOaDwue1ieDunDKA,6443
160
162
  moonshot/src/runs/run_progress.py,sha256=d1BcNo6Kp4vA165TDx_xebl8JDo92aV-YutPxsgCOxE,6495
161
163
  moonshot/src/runs/run_status.py,sha256=TRtizcDzPxf6aQ2c3OovM6IQKJ0VCBhqDWvn7UBw5Zg,251
@@ -169,9 +171,9 @@ moonshot/src/utils/import_modules.py,sha256=T9zTN59PFnvY2rjyWhSV9KSIAHxWV1pyBemF
169
171
  moonshot/src/utils/log.py,sha256=YNgD7Eh2OT36XlmVBKCGUTAh9TRp4Akfe4kDdvHASgs,2502
170
172
  moonshot/src/utils/pagination.py,sha256=5seymyRoqyENIhKllAatr1T91kMCGFslcvRnJHyMSvc,814
171
173
  moonshot/src/utils/timeit.py,sha256=TvuF0w8KWhp0oZFY0cUU3UY0xlGKjchb0OkfYfgVTlc,866
172
- aiverify_moonshot-0.4.4.dist-info/METADATA,sha256=zQ4rKRFVE_p6uB6dgGBcKhIB4KXRn8ZzdBymh3d2y6g,12368
173
- aiverify_moonshot-0.4.4.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
174
- aiverify_moonshot-0.4.4.dist-info/licenses/AUTHORS.md,sha256=mmAbe3i3sT8JZHJMBhxp3i1xRehV0g7WB4T_eyIBuBs,59
175
- aiverify_moonshot-0.4.4.dist-info/licenses/LICENSE.md,sha256=mDOKOkWFbJmUORaAchXByEVGC1jw37QRn-zS14wY_wM,11347
176
- aiverify_moonshot-0.4.4.dist-info/licenses/NOTICES.md,sha256=0Ikx6IBGGQEOJeNb2MkRoXxTXwrtlMz6EDgLBFIz6v0,179593
177
- aiverify_moonshot-0.4.4.dist-info/RECORD,,
174
+ aiverify_moonshot-0.4.6.dist-info/METADATA,sha256=PM15lwqxY3nBr-fbxQp44E_wMZyxKBOCq0r_hYiSFTI,12397
175
+ aiverify_moonshot-0.4.6.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
176
+ aiverify_moonshot-0.4.6.dist-info/licenses/AUTHORS.md,sha256=mmAbe3i3sT8JZHJMBhxp3i1xRehV0g7WB4T_eyIBuBs,59
177
+ aiverify_moonshot-0.4.6.dist-info/licenses/LICENSE.md,sha256=mDOKOkWFbJmUORaAchXByEVGC1jw37QRn-zS14wY_wM,11347
178
+ aiverify_moonshot-0.4.6.dist-info/licenses/NOTICES.md,sha256=0Ikx6IBGGQEOJeNb2MkRoXxTXwrtlMz6EDgLBFIz6v0,179593
179
+ aiverify_moonshot-0.4.6.dist-info/RECORD,,
moonshot/__main__.py CHANGED
@@ -1,10 +1,12 @@
1
1
  import argparse
2
2
  import os
3
3
  import platform
4
+ import shutil
4
5
  import subprocess
5
6
  import sys
6
7
  import threading
7
8
  import warnings
9
+ from typing import Any
8
10
 
9
11
  from dotenv import dotenv_values
10
12
 
@@ -19,7 +21,7 @@ Run the Moonshot application
19
21
  """
20
22
 
21
23
 
22
- def run_subprocess(*args, **kwargs):
24
+ def run_subprocess(*args: Any, **kwargs: Any) -> subprocess.CompletedProcess:
23
25
  """
24
26
  Run a subprocess with the option to use shell=True on Windows.
25
27
  """
@@ -28,7 +30,7 @@ def run_subprocess(*args, **kwargs):
28
30
  return subprocess.run(*args, **kwargs)
29
31
 
30
32
 
31
- def ms_lib_env_file(data_repo_name):
33
+ def ms_lib_env_file(data_repo_name: str) -> None:
32
34
  """
33
35
  Writes the env file to be used for moonshot library
34
36
  """
@@ -70,7 +72,7 @@ def ms_lib_env_file(data_repo_name):
70
72
  env_file.write(combined_content.strip())
71
73
 
72
74
 
73
- def ms_ui_env_file(ui_repo):
75
+ def ms_ui_env_file(ui_repo: str) -> None:
74
76
  """
75
77
  Write the env file to be used with moonshot ui
76
78
  """
@@ -84,90 +86,160 @@ def ms_ui_env_file(ui_repo):
84
86
  env_file.write(env_content.strip())
85
87
 
86
88
 
87
- def moonshot_data_installation():
89
+ def download_nltk_resources() -> None:
90
+ """
91
+ Download and verify necessary NLTK resources.
92
+
93
+ This function downloads a predefined list of NLTK resources and verifies their availability.
94
+ If a resource fails to download or verify, a warning is logged and an exception is raised.
95
+ """
96
+ import nltk
97
+
98
+ resources = [
99
+ "punkt",
100
+ "stopwords",
101
+ ]
102
+
103
+ for resource in resources:
104
+ try:
105
+ nltk.download(resource)
106
+ # Check if the resource is available
107
+ nltk.data.find(
108
+ f"tokenizers/{resource}"
109
+ ) if resource == "punkt" else nltk.data.find(f"corpora/{resource}")
110
+ logger.info(f"Successfully downloaded and verified {resource}")
111
+ except LookupError:
112
+ logger.warning(f"Failed to download {resource}")
113
+ raise
114
+ except Exception as e:
115
+ logger.warning(f"An error occurred while downloading {resource}: {e}")
116
+ raise
117
+
118
+
119
+ def moonshot_data_installation() -> None:
88
120
  # Code for moonshot-data installation
89
121
  logger.info("Installing Moonshot Data from GitHub")
90
122
  repo = "https://github.com/aiverify-foundation/moonshot-data.git"
91
123
  folder_name = repo.split("/")[-1].replace(".git", "")
92
124
 
93
125
  # Check if the directory already exists
94
- if not os.path.exists(folder_name):
95
- logger.info(f"Cloning {repo}")
96
- # Clone the repository
97
- run_subprocess(["git", "clone", repo], check=True)
126
+ if os.path.exists(folder_name):
127
+ logger.warning(f"Directory {folder_name} already exists.")
128
+ user_input = (
129
+ input(
130
+ f"Directory {folder_name} already exists. Do you want to remove it and reinstall? (Y/n): "
131
+ )
132
+ .strip()
133
+ .lower()
134
+ )
135
+ if user_input == "y":
136
+ logger.info(f"Removing directory {folder_name}.")
137
+ # Remove the existing directory
138
+ shutil.rmtree(folder_name)
139
+ else:
140
+ logger.info("Exiting function without removing the directory.")
141
+ return
98
142
 
99
- # Create .env to point to installed folder
100
- ms_lib_env_file(folder_name)
143
+ logger.info(f"Cloning {repo}")
144
+ # Clone the repository
145
+ run_subprocess(["git", "clone", repo], check=True)
101
146
 
102
- # Change directory to the folder
103
- os.chdir(folder_name)
147
+ # Create .env to point to installed folder
148
+ ms_lib_env_file(folder_name)
104
149
 
105
- logger.info(f"Installing requirements for {folder_name}")
106
- # Install the requirements if they exist
107
- if os.path.exists("requirements.txt"):
108
- run_subprocess(["pip", "install", "-r", "requirements.txt"], check=True)
109
- import nltk
150
+ # Change directory to the folder
151
+ os.chdir(folder_name)
110
152
 
111
- nltk.download("punkt")
112
- nltk.download("stopwords")
113
- nltk.download("averaged_perceptron_tagger")
114
- nltk.download("universal_tagset")
153
+ logger.info(f"Installing requirements for {folder_name}")
154
+ # Install the requirements if they exist
155
+ if os.path.exists("requirements.txt"):
156
+ run_subprocess(["pip", "install", "-r", "requirements.txt"], check=True)
157
+ download_nltk_resources()
115
158
 
116
- # Change back to the base directory
117
- os.chdir("..")
159
+ # Change back to the base directory
160
+ os.chdir("..")
118
161
 
119
- else:
120
- logger.warning(f"Directory {folder_name} already exists, skipping clone.")
162
+
163
+ def check_node() -> bool:
164
+ """
165
+ Check if Node.js is installed on the user's machine.
166
+ """
167
+ try:
168
+ result = subprocess.run(
169
+ ["node", "--version"], capture_output=True, text=True, check=True
170
+ )
171
+ node_version = result.stdout.strip()
172
+ logger.info(f"Node.js is installed. Version: {node_version}")
173
+ return True
174
+ except (subprocess.CalledProcessError, FileNotFoundError):
175
+ logger.error("Node.js is not installed. Please install Node.js to proceed.")
176
+ return False
121
177
 
122
178
 
123
- def moonshot_ui_installation():
179
+ def moonshot_ui_installation() -> None:
180
+ if not check_node():
181
+ logger.error("Node.js is not installed. Please install Node.js to proceed.")
182
+ return
183
+
124
184
  # Code for moonshot-ui installation
125
185
  repo = "https://github.com/aiverify-foundation/moonshot-ui.git"
126
186
  folder_name = repo.split("/")[-1].replace(".git", "")
127
187
 
128
188
  # Check if the directory already exists
129
- if not os.path.exists(folder_name):
130
- logger.info(f"Cloning {repo}")
131
- # Clone the repository
132
- run_subprocess(["git", "clone", repo], check=True)
189
+ if os.path.exists(folder_name):
190
+ logger.warning(f"Directory {folder_name} already exists.")
191
+ user_input = (
192
+ input(
193
+ f"Directory {folder_name} already exists. Do you want to remove it and reinstall? (Y/n): "
194
+ )
195
+ .strip()
196
+ .lower()
197
+ )
198
+ if user_input == "y":
199
+ logger.info(f"Removing directory {folder_name}.")
200
+ # Remove the existing directory
201
+ shutil.rmtree(folder_name)
202
+ else:
203
+ logger.info("Exiting function without removing the directory.")
204
+ return
133
205
 
134
- # Change directory to the folder
135
- os.chdir(folder_name)
206
+ logger.info(f"Cloning {repo}")
207
+ # Clone the repository
208
+ run_subprocess(["git", "clone", repo], check=True)
136
209
 
137
- logger.info(f"Installing requirements for {folder_name}")
138
- # Install the requirements if they exist
139
- if os.path.exists("package.json"):
140
- run_subprocess(["npm", "install"], check=True)
141
- run_subprocess(["npm", "run", "build"], check=True)
210
+ # Change directory to the folder
211
+ os.chdir(folder_name)
142
212
 
143
- # Change back to the base directory
144
- os.chdir("..")
213
+ logger.info(f"Installing requirements for {folder_name}")
214
+ # Install the requirements if they exist
215
+ if os.path.exists("package.json"):
216
+ run_subprocess(["npm", "install"], check=True)
217
+ run_subprocess(["npm", "run", "build"], check=True)
145
218
 
146
- # Create .env for ui
147
- ms_ui_env_file(folder_name)
148
- else:
149
- logger.warning(
150
- f"Directory {folder_name} already exists, skipping installation."
151
- )
219
+ # Change back to the base directory
220
+ os.chdir("..")
152
221
 
222
+ # Create .env for ui
223
+ ms_ui_env_file(folder_name)
153
224
 
154
- def run_moonshot_ui_dev():
225
+
226
+ def run_moonshot_ui() -> None:
155
227
  """
156
228
  To start a thread to run the Moonshot UI
157
229
  """
158
230
  base_directory = os.getcwd()
159
- ui_dev_dir = os.path.join(base_directory, "moonshot-ui")
231
+ ui_dir = os.path.join(base_directory, "moonshot-ui")
160
232
 
161
- if not os.path.exists(ui_dev_dir):
233
+ if not os.path.exists(ui_dir):
162
234
  logger.error(
163
235
  "moonshot-ui does not exist. Please run with '-i moonshot-ui' to install moonshot-ui first."
164
236
  )
165
237
  sys.exit(1)
166
238
  # ms_ui_env_file(ui_dev_dir)
167
- run_subprocess(["npm", "start"], cwd=ui_dev_dir)
239
+ run_subprocess(["npm", "start"], cwd=ui_dir)
168
240
 
169
241
 
170
- def main():
242
+ def main() -> None:
171
243
  parser = argparse.ArgumentParser(description="Run the Moonshot application")
172
244
  parser.add_argument(
173
245
  "mode",
@@ -206,7 +278,7 @@ def main():
206
278
 
207
279
  if args.mode == "help":
208
280
  parser.print_help()
209
- sys.exit(1)
281
+ sys.exit(0)
210
282
 
211
283
  api_set_environment_variables(dotenv_values(args.env))
212
284
 
@@ -216,7 +288,7 @@ def main():
216
288
  web_api.start_app()
217
289
  elif args.mode == "web":
218
290
  # Create and start the UI dev server thread
219
- ui_thread = threading.Thread(target=run_moonshot_ui_dev)
291
+ ui_thread = threading.Thread(target=run_moonshot_ui)
220
292
  ui_thread.start()
221
293
  ui_thread.join(timeout=0.1) # Wait briefly for the thread to become alive
222
294
  if not ui_thread.is_alive():
@@ -232,8 +304,7 @@ def main():
232
304
  # Handle CLI mode here, possibly also with additional arguments
233
305
  pass
234
306
  else:
235
- parser.print_help()
236
- sys.exit(1)
307
+ sys.exit(0)
237
308
 
238
309
 
239
310
  if __name__ == "__main__":