aiverify-moonshot 0.6.3__py3-none-any.whl → 0.6.4__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.6.4.dist-info/METADATA +241 -0
- {aiverify_moonshot-0.6.3.dist-info → aiverify_moonshot-0.6.4.dist-info}/RECORD +11 -11
- moonshot/integrations/web_api/app.py +1 -1
- moonshot/src/bookmark/bookmark.py +52 -29
- moonshot/src/bookmark/bookmark_arguments.py +9 -5
- moonshot/src/connectors/connector.py +33 -25
- moonshot/src/connectors_endpoints/connector_endpoint.py +37 -14
- aiverify_moonshot-0.6.3.dist-info/METADATA +0 -254
- {aiverify_moonshot-0.6.3.dist-info → aiverify_moonshot-0.6.4.dist-info}/WHEEL +0 -0
- {aiverify_moonshot-0.6.3.dist-info → aiverify_moonshot-0.6.4.dist-info}/licenses/AUTHORS.md +0 -0
- {aiverify_moonshot-0.6.3.dist-info → aiverify_moonshot-0.6.4.dist-info}/licenses/LICENSE.md +0 -0
- {aiverify_moonshot-0.6.3.dist-info → aiverify_moonshot-0.6.4.dist-info}/licenses/NOTICES.md +0 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aiverify-moonshot
|
|
3
|
+
Version: 0.6.4
|
|
4
|
+
Summary: AI Verify advances Gen AI testing with Project Moonshot.
|
|
5
|
+
Project-URL: Repository, https://github.com/aiverify-foundation/moonshot
|
|
6
|
+
Project-URL: Documentation, https://aiverify-foundation.github.io/moonshot/
|
|
7
|
+
Project-URL: Issues, https://github.com/aiverify-foundation/moonshot/issues
|
|
8
|
+
Author-email: AI Verify Foundation <info@aiverify.sg>
|
|
9
|
+
License: Apache-2.0
|
|
10
|
+
License-File: AUTHORS.md
|
|
11
|
+
License-File: LICENSE.md
|
|
12
|
+
License-File: NOTICES.md
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Requires-Dist: datasets>=2.21.0
|
|
19
|
+
Requires-Dist: ijson>=3.3.0
|
|
20
|
+
Requires-Dist: jinja2>=3.1.4
|
|
21
|
+
Requires-Dist: numpy>=1.26.4
|
|
22
|
+
Requires-Dist: pandas>=2.2.2
|
|
23
|
+
Requires-Dist: pydantic==2.8.2
|
|
24
|
+
Requires-Dist: pyparsing>=3.1.4
|
|
25
|
+
Requires-Dist: python-dotenv>=1.0.1
|
|
26
|
+
Requires-Dist: python-multipart>=0.0.9
|
|
27
|
+
Requires-Dist: python-slugify>=8.0.4
|
|
28
|
+
Requires-Dist: tenacity>=8.5.0
|
|
29
|
+
Requires-Dist: xxhash>=3.5.0
|
|
30
|
+
Provides-Extra: all
|
|
31
|
+
Requires-Dist: cmd2>=2.4.3; extra == 'all'
|
|
32
|
+
Requires-Dist: dependency-injector>=4.41.0; extra == 'all'
|
|
33
|
+
Requires-Dist: fastapi>=0.115.4; extra == 'all'
|
|
34
|
+
Requires-Dist: rich>=13.8.0; extra == 'all'
|
|
35
|
+
Requires-Dist: typing-extensions>=4.12.2; extra == 'all'
|
|
36
|
+
Requires-Dist: uvicorn>=0.30.6; extra == 'all'
|
|
37
|
+
Provides-Extra: cli
|
|
38
|
+
Requires-Dist: cmd2>=2.4.3; extra == 'cli'
|
|
39
|
+
Requires-Dist: rich>=13.8.0; extra == 'cli'
|
|
40
|
+
Provides-Extra: web-api
|
|
41
|
+
Requires-Dist: dependency-injector>=4.41.0; extra == 'web-api'
|
|
42
|
+
Requires-Dist: fastapi>=0.115.4; extra == 'web-api'
|
|
43
|
+
Requires-Dist: typing-extensions>=4.12.2; extra == 'web-api'
|
|
44
|
+
Requires-Dist: uvicorn>=0.30.6; extra == 'web-api'
|
|
45
|
+
Description-Content-Type: text/markdown
|
|
46
|
+
|
|
47
|
+
<div align="center">
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
**Version 0.6.4**
|
|
52
|
+
|
|
53
|
+
A simple and modular tool to evaluate any LLM-based AI systems.
|
|
54
|
+
|
|
55
|
+
[](https://www.python.org/downloads/release/python-3111/)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
## 🎯 Motivation
|
|
61
|
+
|
|
62
|
+
Developed by the [AI Verify Foundation](https://aiverifyfoundation.sg/), [Moonshot](https://aiverifyfoundation.sg/project-moonshot/) is one of the first tools to bring Benchmarking and Red-Teaming together to help AI developers, compliance teams and AI system owners <b>evaluate LLMs and LLM-based AI systems</b>.
|
|
63
|
+
|
|
64
|
+
</br>
|
|
65
|
+
|
|
66
|
+
## 🚀 Why Moonshot
|
|
67
|
+
|
|
68
|
+
In the rapidly evolving landscape of Generative AI, ensuring safety, reliability, and performance of AI systems is paramount. Moonshot addresses this critical need by providing a unified platform for:
|
|
69
|
+
- <b>Benchmark Tests:</b> Systematically test LLMs across various performance metrics, and critical trust & safety dimensions using a wide array of open-source benchmarks and domain-specific tests.
|
|
70
|
+
- <b>Red Team Attacks:</b> Proactively identify vulnerabilities and potential misuse scenarios in your AI systems through streamlined adversarial prompting.
|
|
71
|
+
- <b>Streamline MLOps:</b> Integrate evaluation seamlessly into your development pipeline with flexible APIs.
|
|
72
|
+
|
|
73
|
+
</br>
|
|
74
|
+
|
|
75
|
+
## 🔑 Key Features
|
|
76
|
+
|
|
77
|
+
- <b>User-friendly Interfaces:</b> Interact with Moonshot via an intuitive Web UI for visual insights, and an interactive Command Line Interface (CLI) for quick operations.
|
|
78
|
+
- <b>Comprehensive Benchmarking:</b>
|
|
79
|
+
- [View list of available datasets available](https://aiverify-foundation.github.io/moonshot/resources/datasets/)
|
|
80
|
+
- Test for <b>Performance</b> (e.g., accuracy, BLEU)
|
|
81
|
+
- Ensure <b>Trust & Safety</b> e.g., bias, toxicity, hallucination)
|
|
82
|
+
- Utilize pre-built Cookbooks of tests or easily create your custom evaluations. [View available pre-built Cookbooks](https://aiverify-foundation.github.io/moonshot/resources/cookbooks/)
|
|
83
|
+
- <b>Powerful Red-Teaming:</b>
|
|
84
|
+
- [View list of available attack modules](https://aiverify-foundation.github.io/moonshot/resources/attack_modules/)
|
|
85
|
+
- Simplify adversarial prompt generation using algorithmic strategies or generative LLM to uncover potential misuse.
|
|
86
|
+
- Leverage prompt templates, context strategies, and automated attack modules.
|
|
87
|
+
- <b>Customizable Recipes:</b> Define your evaluation logic with custom datasets (input-target pairs), metrics, optional prompt templates, evaluation metric, and grading scales. [View available pre-built Recipes](https://aiverify-foundation.github.io/moonshot/resources/recipes/)
|
|
88
|
+
- <b>Insightful Reporting:</b> Generate comprehensive HTML reports with interactive charts for clear visualization of test results, and detailed raw JSON results for deeper programmatic analysis.
|
|
89
|
+
- <b>Extensible & Modular:</b> Designed for easy extension and integration with new LLMs, benchmarks, and attack techniques.
|
|
90
|
+
|
|
91
|
+
</br>
|
|
92
|
+
|
|
93
|
+
# Getting Started
|
|
94
|
+
|
|
95
|
+
In this Beta version, Moonshot can be used through several interfaces:
|
|
96
|
+
- User-friendly Web UI - [Web UI User Guide](https://aiverify-foundation.github.io/moonshot/user_guide/web_ui/web_ui_guide/)
|
|
97
|
+
- Interactive Command Line Interface - [CLI User Guide](https://aiverify-foundation.github.io/moonshot/user_guide/cli/connecting_endpoints/)
|
|
98
|
+
- Seamless Integration into your MLOps workflow via Moonshot Library APIs or Moonshot Web APIs - [Notebook Examples](https://github.com/aiverify-foundation/moonshot/tree/main/examples/jupyter-notebook), [Web API Docs](https://aiverify-foundation.github.io/moonshot/api_reference/web_api_swagger/)
|
|
99
|
+
|
|
100
|
+
</br>
|
|
101
|
+
|
|
102
|
+
## 💻 Let's Go!
|
|
103
|
+
|
|
104
|
+
This section will guide you through getting Moonshot up and running.
|
|
105
|
+
|
|
106
|
+
</br>
|
|
107
|
+
|
|
108
|
+
### ✅ Prerequisites
|
|
109
|
+
1. <b>Python:</b> [Version 3.11](https://www.python.org/downloads/) is required.
|
|
110
|
+
|
|
111
|
+
2. <b>Git Version Control:</b> [Git](https://github.com/git-guides/install-git) is essential for cloning the repository.
|
|
112
|
+
|
|
113
|
+
3. <b>(Optional) Virtual Environment:</b> Highly recommended to manage dependencies.
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
# Create a virtual environment
|
|
117
|
+
python -m venv venv
|
|
118
|
+
|
|
119
|
+
# Activate the virtual environment
|
|
120
|
+
source venv/bin/activate
|
|
121
|
+
```
|
|
122
|
+
4. If you plan to install our Web UI, you will also need [Node.js version 20.11.1 LTS](https://nodejs.org/en/blog/release/v20.11.1) and above
|
|
123
|
+
</br>
|
|
124
|
+
|
|
125
|
+
### ⬇️ Installation
|
|
126
|
+
|
|
127
|
+
You can install Moonshot in various ways depending on your needs
|
|
128
|
+
|
|
129
|
+
<b>1. Using `pip` (Recommended for most users)</b>
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
# Install Project Moonshot's Python Library, which includes Moonshot's full functionalities (Library APIs, CLI and Web APIs)
|
|
133
|
+
pip install "aiverify-moonshot[all]"
|
|
134
|
+
|
|
135
|
+
# Clone and install test assets and Web UI
|
|
136
|
+
python -m moonshot -i moonshot-data -i moonshot-ui
|
|
137
|
+
```
|
|
138
|
+
⚠️ You will need to have test assets from [moonshot-data](https://github.com/aiverify-foundation/moonshot-data) before you can run any tests.
|
|
139
|
+
|
|
140
|
+
🖼️ If you plan to install our Web UI, you will also need [moonshot-ui](https://github.com/aiverify-foundation/moonshot-ui)
|
|
141
|
+
|
|
142
|
+
Check out our [Installation Guide](https://aiverify-foundation.github.io/moonshot/getting_started/quick_install/) for more details.
|
|
143
|
+
|
|
144
|
+
</br>
|
|
145
|
+
|
|
146
|
+
<b>2. From Source Code (For developers and contributors)</b>
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
# To install from source code (Full functionalities)
|
|
150
|
+
git clone git@github.com:aiverify-foundation/moonshot.git
|
|
151
|
+
cd moonshot
|
|
152
|
+
pip install -r requirements.txt
|
|
153
|
+
```
|
|
154
|
+
If you have installation issues, please take a look at the [Troubleshooting Guide](https://aiverify-foundation.github.io/moonshot/faq/).
|
|
155
|
+
<details>
|
|
156
|
+
<summary><b>Other installation options</b></summary>
|
|
157
|
+
Here's a summary of other installation commands available:
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
# To install Moonshot library APIs only
|
|
161
|
+
pip install aiverify-moonshot
|
|
162
|
+
|
|
163
|
+
# To install Moonshot library APIs and Web APIs only
|
|
164
|
+
pip install "aiverify-moonshot[web-api]"
|
|
165
|
+
|
|
166
|
+
# To install Moonshot library APIs and CLI only
|
|
167
|
+
pip install "aiverify-moonshot[cli]"
|
|
168
|
+
```
|
|
169
|
+
Check out our [Installation Guide](https://aiverify-foundation.github.io/moonshot/getting_started/quick_install/) for more details.
|
|
170
|
+
</details>
|
|
171
|
+
|
|
172
|
+
</br>
|
|
173
|
+
|
|
174
|
+
### 🏃♀️ Run Moonshot
|
|
175
|
+
|
|
176
|
+
#### Running the Web UI
|
|
177
|
+
```
|
|
178
|
+
python -m moonshot web
|
|
179
|
+
```
|
|
180
|
+
Open [http://localhost:3000/](http://localhost:3000/) in a browser and you should see this homepage:
|
|
181
|
+
|
|
182
|
+

|
|
183
|
+
|
|
184
|
+
Refer to this [guide](https://aiverify-foundation.github.io/moonshot/user_guide/web_ui/moonshot_interface/homepage/) to discover the rich features available in Moonshot Web UI
|
|
185
|
+
|
|
186
|
+
</br>
|
|
187
|
+
|
|
188
|
+
#### Running the Interactive CLI
|
|
189
|
+
```
|
|
190
|
+
python -m moonshot cli interactive
|
|
191
|
+
```
|
|
192
|
+

|
|
193
|
+
|
|
194
|
+
Refer to this [Command List](https://aiverify-foundation.github.io/moonshot/user_guide/cli/cli_command_list/) to discover the list of CLI commands for Moonshot
|
|
195
|
+
|
|
196
|
+
</br></br>
|
|
197
|
+
|
|
198
|
+
# 📚 Documentation & User Guides
|
|
199
|
+
|
|
200
|
+
For detailed information on configuring, using, and extending Moonshot, please refer to our comprehensive documentation:
|
|
201
|
+
|
|
202
|
+
#### Guides for Moonshot Web UI
|
|
203
|
+
- [Getting Started with Moonshot Web UI](https://aiverify-foundation.github.io/moonshot/user_guide/web_ui/web_ui_guide/)
|
|
204
|
+
- [Creating Your Custom Cookbook via Moonshot Web UI](https://aiverify-foundation.github.io/moonshot/tutorial/web-ui/create_cookbook/)
|
|
205
|
+
- [Creating Your Custom Connector Endpoint via Moonshot Web UI](https://aiverify-foundation.github.io/moonshot/tutorial/web-ui/create_endpoint/)
|
|
206
|
+
- [Running Benchmark Test on Moonshot Web UI](https://aiverify-foundation.github.io/moonshot/getting_started/first_test/)
|
|
207
|
+
- [Running Red Teaming on Moonshot Web UI](https://aiverify-foundation.github.io/moonshot/tutorial/web-ui/redteam/)
|
|
208
|
+
|
|
209
|
+
#### Guides for Moonshot Interactive CLI
|
|
210
|
+
- [Getting Started with Moonshot Interactive CLI](https://aiverify-foundation.github.io/moonshot/user_guide/cli/connecting_endpoints/)
|
|
211
|
+
- [Creating Your Custom Benchmark Tests for Your RAG Apps via Moonshot Interactive CLI](https://aiverify-foundation.github.io/moonshot/tutorial/cli/create_benchmark_tests/)
|
|
212
|
+
- [Creating Your Custom Connector Endpoint via Moonshot Interactive CLI](https://aiverify-foundation.github.io/moonshot/tutorial/cli/create_endpoint/)
|
|
213
|
+
- [Running Benchmark Test on Moonshot Interactive CLI](https://aiverify-foundation.github.io/moonshot/tutorial/cli/run_benchmark_tests/)
|
|
214
|
+
- [Running Red Teaming on Moonshot Interactive CLI](https://aiverify-foundation.github.io/moonshot/tutorial/cli/run_red_teaming/)
|
|
215
|
+
|
|
216
|
+
#### For Users Interested in trying Out Moonshot using Jupyter Notebook
|
|
217
|
+
- [Moonshot Library Python Notebook Examples](https://github.com/aiverify-foundation/moonshot/tree/main/examples/jupyter-notebook)
|
|
218
|
+
|
|
219
|
+
####
|
|
220
|
+
|
|
221
|
+
</br>
|
|
222
|
+
|
|
223
|
+
## 🤝 Contribution
|
|
224
|
+
|
|
225
|
+
Moonshot is an open-source project, and we welcome contributions from the community! Whether fixing a bug, adding a new feature, improving documentation, or suggesting an enhancement, your efforts are highly valued.
|
|
226
|
+
|
|
227
|
+
Please refer to our [Contributor Guide](https://aiverify-foundation.github.io/moonshot/contributing/) for details on how to get started.
|
|
228
|
+
|
|
229
|
+
</br>
|
|
230
|
+
|
|
231
|
+
## ✨ Project Status
|
|
232
|
+
|
|
233
|
+
Moonshot is currently in beta. We are actively developing new features, improving existing ones, and enhancing stability. We encourage you to try it out and provide feedback!
|
|
234
|
+
|
|
235
|
+
</br>
|
|
236
|
+
|
|
237
|
+
## 📜 License
|
|
238
|
+
|
|
239
|
+
Moonshot is released under the [Apache Software License 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt)
|
|
240
|
+
|
|
241
|
+
</br>
|
|
@@ -34,7 +34,7 @@ moonshot/integrations/cli/utils/process_data.py,sha256=QVL5vp2_8ZgGicmCAdeYEHkeb
|
|
|
34
34
|
moonshot/integrations/web_api/.env.dev,sha256=0z5_Ut8rF-UqFZtgjkH2qoqORhD5_nSs2w_OeX2SteI,182
|
|
35
35
|
moonshot/integrations/web_api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
36
36
|
moonshot/integrations/web_api/__main__.py,sha256=MdnLi_ZF-olAAEJwTPU1iGYFYwo-fNWNT2qfchkH3y4,2050
|
|
37
|
-
moonshot/integrations/web_api/app.py,sha256=
|
|
37
|
+
moonshot/integrations/web_api/app.py,sha256=nbAAnVyy1BEqlctGeVUjVYCdR3yD0mfyGZmwBM2zZec,3651
|
|
38
38
|
moonshot/integrations/web_api/container.py,sha256=DVkJG_qm7ItcG6tgMYOqIj07wpKhPWOOfy6-bEv72y4,5915
|
|
39
39
|
moonshot/integrations/web_api/logging_conf.py,sha256=t3EGRV6tZhV732KXe8_Tiy0fiwVAWxZX5Tt8VTgrrfg,3388
|
|
40
40
|
moonshot/integrations/web_api/log/.gitkeep,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -113,16 +113,16 @@ moonshot/src/api/api_result.py,sha256=xZHex_K_PbSr-65LPLr5up4lvu313-VJroR4BBR5JQ
|
|
|
113
113
|
moonshot/src/api/api_run.py,sha256=ToPYIeTPd2OaOqd20UQ_ie2BQPqLw5aZ_RwRwv9oGpU,2983
|
|
114
114
|
moonshot/src/api/api_runner.py,sha256=spN7ogBGQN7I-c1u_UeKZ7vg02AtCuAl3dFG8CSayQU,4257
|
|
115
115
|
moonshot/src/api/api_session.py,sha256=w-mc_sj3ElQa6FPQqWbK2bFgGTu1ECwYm3tN41xFkes,11130
|
|
116
|
-
moonshot/src/bookmark/bookmark.py,sha256=
|
|
117
|
-
moonshot/src/bookmark/bookmark_arguments.py,sha256=
|
|
116
|
+
moonshot/src/bookmark/bookmark.py,sha256=KOvvNE8wvdkJu9q2clte5fPLESZ2x6EuuoQkkxFxmHg,12970
|
|
117
|
+
moonshot/src/bookmark/bookmark_arguments.py,sha256=Xgjx3Ek9MXwD4p1icac8nPX3KZfmYsBwR6kwPwHAngE,1622
|
|
118
118
|
moonshot/src/configs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
119
119
|
moonshot/src/configs/env_variables.py,sha256=eF__UJN37LCzIB4pv_T7G-kQHlOa657QA7IpL1d_0MM,7150
|
|
120
120
|
moonshot/src/connectors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
121
|
-
moonshot/src/connectors/connector.py,sha256
|
|
121
|
+
moonshot/src/connectors/connector.py,sha256=XqYVamy2EWsMOpOyK8bnIUtjH6MiZ29k2ZFfdAPmFyU,17532
|
|
122
122
|
moonshot/src/connectors/connector_prompt_arguments.py,sha256=aJX5Jwd9bxWWLhIntXBu5Iu3NKsOcud-dfdBJVgKK58,751
|
|
123
123
|
moonshot/src/connectors/connector_response.py,sha256=kIByU-H7A0NXRxk1Y2XPGZHSJNKzJj6BNkzXqdyZyb0,403
|
|
124
124
|
moonshot/src/connectors_endpoints/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
125
|
-
moonshot/src/connectors_endpoints/connector_endpoint.py,sha256=
|
|
125
|
+
moonshot/src/connectors_endpoints/connector_endpoint.py,sha256=racxWKZSZYQ8YZMoPHGcwdQ6-8LKzJ0CKu5S8E0xwnM,10800
|
|
126
126
|
moonshot/src/connectors_endpoints/connector_endpoint_arguments.py,sha256=0v9mUHki4l22CK8o8UjATAsFDza9Lutbh4QplLiDXs8,2434
|
|
127
127
|
moonshot/src/cookbooks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
128
128
|
moonshot/src/cookbooks/cookbook.py,sha256=DdZwRGx5-xTDIKcXtZRpp7Qb9Mm9dNGwXWLQXoQrBBo,10412
|
|
@@ -172,9 +172,9 @@ moonshot/src/utils/import_modules.py,sha256=T9zTN59PFnvY2rjyWhSV9KSIAHxWV1pyBemF
|
|
|
172
172
|
moonshot/src/utils/log.py,sha256=YNgD7Eh2OT36XlmVBKCGUTAh9TRp4Akfe4kDdvHASgs,2502
|
|
173
173
|
moonshot/src/utils/pagination.py,sha256=5seymyRoqyENIhKllAatr1T91kMCGFslcvRnJHyMSvc,814
|
|
174
174
|
moonshot/src/utils/timeit.py,sha256=TvuF0w8KWhp0oZFY0cUU3UY0xlGKjchb0OkfYfgVTlc,866
|
|
175
|
-
aiverify_moonshot-0.6.
|
|
176
|
-
aiverify_moonshot-0.6.
|
|
177
|
-
aiverify_moonshot-0.6.
|
|
178
|
-
aiverify_moonshot-0.6.
|
|
179
|
-
aiverify_moonshot-0.6.
|
|
180
|
-
aiverify_moonshot-0.6.
|
|
175
|
+
aiverify_moonshot-0.6.4.dist-info/METADATA,sha256=UKH5vf6h00IJVbN3TyjUO-xY_M2Chwqcut_ZfFkEVv4,11273
|
|
176
|
+
aiverify_moonshot-0.6.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
177
|
+
aiverify_moonshot-0.6.4.dist-info/licenses/AUTHORS.md,sha256=mmAbe3i3sT8JZHJMBhxp3i1xRehV0g7WB4T_eyIBuBs,59
|
|
178
|
+
aiverify_moonshot-0.6.4.dist-info/licenses/LICENSE.md,sha256=53izDRmJZZCjpYGfyLqlxnGQN-aNWBxasuzuMXC5Ias,11347
|
|
179
|
+
aiverify_moonshot-0.6.4.dist-info/licenses/NOTICES.md,sha256=3d1WLa7kMtzh79BXxXr-keSlvHo8Llb-5EkGgtRiMS0,51537
|
|
180
|
+
aiverify_moonshot-0.6.4.dist-info/RECORD,,
|
|
@@ -71,7 +71,7 @@ def create_app(cfg: providers.Configuration) -> CustomFastAPI:
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
app: CustomFastAPI = CustomFastAPI(
|
|
74
|
-
title="Project Moonshot", version="0.6.
|
|
74
|
+
title="Project Moonshot", version="0.6.4", **app_kwargs
|
|
75
75
|
)
|
|
76
76
|
|
|
77
77
|
if cfg.cors.enabled():
|
|
@@ -5,21 +5,6 @@ from datetime import datetime
|
|
|
5
5
|
|
|
6
6
|
from moonshot.src.bookmark.bookmark_arguments import BookmarkArguments
|
|
7
7
|
from moonshot.src.configs.env_variables import EnvVariables
|
|
8
|
-
from moonshot.src.messages_constants import (
|
|
9
|
-
BOOKMARK_ADD_BOOKMARK_ERROR,
|
|
10
|
-
BOOKMARK_ADD_BOOKMARK_SUCCESS,
|
|
11
|
-
BOOKMARK_ADD_BOOKMARK_VALIDATION_ERROR,
|
|
12
|
-
BOOKMARK_DELETE_ALL_BOOKMARK_ERROR,
|
|
13
|
-
BOOKMARK_DELETE_ALL_BOOKMARK_SUCCESS,
|
|
14
|
-
BOOKMARK_DELETE_BOOKMARK_ERROR,
|
|
15
|
-
BOOKMARK_DELETE_BOOKMARK_ERROR_1,
|
|
16
|
-
BOOKMARK_DELETE_BOOKMARK_FAIL,
|
|
17
|
-
BOOKMARK_DELETE_BOOKMARK_SUCCESS,
|
|
18
|
-
BOOKMARK_EXPORT_BOOKMARK_ERROR,
|
|
19
|
-
BOOKMARK_EXPORT_BOOKMARK_VALIDATION_ERROR,
|
|
20
|
-
BOOKMARK_GET_BOOKMARK_ERROR,
|
|
21
|
-
BOOKMARK_GET_BOOKMARK_ERROR_1,
|
|
22
|
-
)
|
|
23
8
|
from moonshot.src.storage.storage import Storage
|
|
24
9
|
from moonshot.src.utils.log import configure_logger
|
|
25
10
|
|
|
@@ -28,6 +13,29 @@ logger = configure_logger(__name__)
|
|
|
28
13
|
|
|
29
14
|
|
|
30
15
|
class Bookmark:
|
|
16
|
+
BOOKMARK_ADD_BOOKMARK_ERROR = "[Bookmark] Failed to add bookmark record: {message}"
|
|
17
|
+
BOOKMARK_ADD_BOOKMARK_SUCCESS = "[Bookmark] Bookmark added successfully."
|
|
18
|
+
BOOKMARK_ADD_BOOKMARK_VALIDATION_ERROR = "Error inserting record into database."
|
|
19
|
+
BOOKMARK_DELETE_ALL_BOOKMARK_ERROR = (
|
|
20
|
+
"[Bookmark] Failed to delete all bookmark records: {message}"
|
|
21
|
+
)
|
|
22
|
+
BOOKMARK_DELETE_ALL_BOOKMARK_SUCCESS = "[Bookmark] All bookmark records deleted."
|
|
23
|
+
BOOKMARK_DELETE_BOOKMARK_ERROR = (
|
|
24
|
+
"[Bookmark] Failed to delete bookmark record: {message}"
|
|
25
|
+
)
|
|
26
|
+
BOOKMARK_DELETE_BOOKMARK_ERROR_1 = "[Bookmark] Invalid bookmark name: {message}"
|
|
27
|
+
BOOKMARK_DELETE_BOOKMARK_FAIL = (
|
|
28
|
+
"[Bookmark] Bookmark record not found. Unable to delete."
|
|
29
|
+
)
|
|
30
|
+
BOOKMARK_DELETE_BOOKMARK_SUCCESS = "[Bookmark] Bookmark record deleted."
|
|
31
|
+
BOOKMARK_EXPORT_BOOKMARK_ERROR = "[Bookmark] Failed to export bookmarks: {message}"
|
|
32
|
+
BOOKMARK_EXPORT_BOOKMARK_VALIDATION_ERROR = (
|
|
33
|
+
"Export filename must be a non-empty string."
|
|
34
|
+
)
|
|
35
|
+
BOOKMARK_GET_BOOKMARK_ERROR = (
|
|
36
|
+
"[Bookmark] No record found for bookmark name: {message}"
|
|
37
|
+
)
|
|
38
|
+
BOOKMARK_GET_BOOKMARK_ERROR_1 = "[Bookmark] Invalid bookmark name: {message}"
|
|
31
39
|
_instance = None
|
|
32
40
|
|
|
33
41
|
sql_table_name = "bookmark"
|
|
@@ -135,13 +143,16 @@ class Bookmark:
|
|
|
135
143
|
self.db_instance, data, Bookmark.sql_insert_bookmark_record
|
|
136
144
|
)
|
|
137
145
|
if results is not None:
|
|
138
|
-
return {
|
|
146
|
+
return {
|
|
147
|
+
"success": True,
|
|
148
|
+
"message": Bookmark.BOOKMARK_ADD_BOOKMARK_SUCCESS,
|
|
149
|
+
}
|
|
139
150
|
else:
|
|
140
|
-
raise Exception(BOOKMARK_ADD_BOOKMARK_VALIDATION_ERROR)
|
|
151
|
+
raise Exception(Bookmark.BOOKMARK_ADD_BOOKMARK_VALIDATION_ERROR)
|
|
141
152
|
except Exception as e:
|
|
142
153
|
return {
|
|
143
154
|
"success": False,
|
|
144
|
-
"message": BOOKMARK_ADD_BOOKMARK_ERROR.format(message=str(e)),
|
|
155
|
+
"message": Bookmark.BOOKMARK_ADD_BOOKMARK_ERROR.format(message=str(e)),
|
|
145
156
|
}
|
|
146
157
|
|
|
147
158
|
def get_all_bookmarks(self) -> list[dict]:
|
|
@@ -193,11 +204,11 @@ class Bookmark:
|
|
|
193
204
|
return BookmarkArguments.from_tuple_to_dict(bookmark_info)
|
|
194
205
|
else:
|
|
195
206
|
raise RuntimeError(
|
|
196
|
-
BOOKMARK_GET_BOOKMARK_ERROR.format(message=bookmark_name)
|
|
207
|
+
Bookmark.BOOKMARK_GET_BOOKMARK_ERROR.format(message=bookmark_name)
|
|
197
208
|
)
|
|
198
209
|
else:
|
|
199
210
|
raise RuntimeError(
|
|
200
|
-
BOOKMARK_GET_BOOKMARK_ERROR_1.format(message=bookmark_name)
|
|
211
|
+
Bookmark.BOOKMARK_GET_BOOKMARK_ERROR_1.format(message=bookmark_name)
|
|
201
212
|
)
|
|
202
213
|
|
|
203
214
|
def delete_bookmark(self, bookmark_name: str) -> dict:
|
|
@@ -228,19 +239,24 @@ class Bookmark:
|
|
|
228
239
|
)
|
|
229
240
|
return {
|
|
230
241
|
"success": True,
|
|
231
|
-
"message": BOOKMARK_DELETE_BOOKMARK_SUCCESS,
|
|
242
|
+
"message": Bookmark.BOOKMARK_DELETE_BOOKMARK_SUCCESS,
|
|
232
243
|
}
|
|
233
244
|
else:
|
|
234
|
-
return {
|
|
245
|
+
return {
|
|
246
|
+
"success": False,
|
|
247
|
+
"message": Bookmark.BOOKMARK_DELETE_BOOKMARK_FAIL,
|
|
248
|
+
}
|
|
235
249
|
except Exception as e:
|
|
236
250
|
return {
|
|
237
251
|
"success": False,
|
|
238
|
-
"message": BOOKMARK_DELETE_BOOKMARK_ERROR.format(
|
|
252
|
+
"message": Bookmark.BOOKMARK_DELETE_BOOKMARK_ERROR.format(
|
|
253
|
+
message=str(e)
|
|
254
|
+
),
|
|
239
255
|
}
|
|
240
256
|
else:
|
|
241
257
|
return {
|
|
242
258
|
"success": False,
|
|
243
|
-
"message": BOOKMARK_DELETE_BOOKMARK_ERROR_1.format(
|
|
259
|
+
"message": Bookmark.BOOKMARK_DELETE_BOOKMARK_ERROR_1.format(
|
|
244
260
|
message=bookmark_name
|
|
245
261
|
),
|
|
246
262
|
}
|
|
@@ -256,11 +272,16 @@ class Bookmark:
|
|
|
256
272
|
Storage.delete_database_record_in_table(
|
|
257
273
|
self.db_instance, Bookmark.sql_delete_bookmark_records
|
|
258
274
|
)
|
|
259
|
-
return {
|
|
275
|
+
return {
|
|
276
|
+
"success": True,
|
|
277
|
+
"message": Bookmark.BOOKMARK_DELETE_ALL_BOOKMARK_SUCCESS,
|
|
278
|
+
}
|
|
260
279
|
except Exception as e:
|
|
261
280
|
return {
|
|
262
281
|
"success": False,
|
|
263
|
-
"message": BOOKMARK_DELETE_ALL_BOOKMARK_ERROR.format(
|
|
282
|
+
"message": Bookmark.BOOKMARK_DELETE_ALL_BOOKMARK_ERROR.format(
|
|
283
|
+
message=str(e)
|
|
284
|
+
),
|
|
264
285
|
}
|
|
265
286
|
|
|
266
287
|
def export_bookmarks(self, export_file_name: str = "bookmarks") -> str:
|
|
@@ -281,8 +302,8 @@ class Bookmark:
|
|
|
281
302
|
Exception: If the export file name is invalid or an error occurs during export.
|
|
282
303
|
"""
|
|
283
304
|
if not isinstance(export_file_name, str) or not export_file_name:
|
|
284
|
-
error_message = BOOKMARK_EXPORT_BOOKMARK_ERROR.format(
|
|
285
|
-
message=BOOKMARK_EXPORT_BOOKMARK_VALIDATION_ERROR
|
|
305
|
+
error_message = Bookmark.BOOKMARK_EXPORT_BOOKMARK_ERROR.format(
|
|
306
|
+
message=Bookmark.BOOKMARK_EXPORT_BOOKMARK_VALIDATION_ERROR
|
|
286
307
|
)
|
|
287
308
|
logger.error(error_message)
|
|
288
309
|
raise Exception(error_message)
|
|
@@ -312,7 +333,9 @@ class Bookmark:
|
|
|
312
333
|
"json",
|
|
313
334
|
)
|
|
314
335
|
except Exception as e:
|
|
315
|
-
error_message = BOOKMARK_EXPORT_BOOKMARK_ERROR.format(
|
|
336
|
+
error_message = Bookmark.BOOKMARK_EXPORT_BOOKMARK_ERROR.format(
|
|
337
|
+
message=str(e)
|
|
338
|
+
)
|
|
316
339
|
logger.error(error_message)
|
|
317
340
|
raise Exception(error_message)
|
|
318
341
|
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from typing import ClassVar
|
|
4
4
|
|
|
5
|
-
from
|
|
6
|
-
BOOKMARK_ARGUMENTS_FROM_TUPLE_TO_DICT_VALIDATION_ERROR,
|
|
7
|
-
)
|
|
5
|
+
from pydantic import BaseModel, Field
|
|
8
6
|
|
|
9
7
|
|
|
10
8
|
class BookmarkArguments(BaseModel):
|
|
9
|
+
BOOKMARK_ARGUMENTS_FROM_TUPLE_TO_DICT_VALIDATION_ERROR: ClassVar[
|
|
10
|
+
str
|
|
11
|
+
] = "[BookmarkArguments] Failed to convert to dictionary because of the insufficient number of values." # noqa: E501
|
|
12
|
+
|
|
11
13
|
name: str = Field(min_length=1)
|
|
12
14
|
prompt: str = Field(min_length=1)
|
|
13
15
|
prepared_prompt: str = Field(min_length=1)
|
|
@@ -33,7 +35,9 @@ class BookmarkArguments(BaseModel):
|
|
|
33
35
|
ValueError: If the number of values in the tuple is less than 10.
|
|
34
36
|
"""
|
|
35
37
|
if len(values) < 10:
|
|
36
|
-
raise ValueError(
|
|
38
|
+
raise ValueError(
|
|
39
|
+
BookmarkArguments.BOOKMARK_ARGUMENTS_FROM_TUPLE_TO_DICT_VALIDATION_ERROR
|
|
40
|
+
)
|
|
37
41
|
|
|
38
42
|
return {
|
|
39
43
|
"name": values[1],
|
|
@@ -15,20 +15,6 @@ from moonshot.src.connectors.connector_response import ConnectorResponse
|
|
|
15
15
|
from moonshot.src.connectors_endpoints.connector_endpoint_arguments import (
|
|
16
16
|
ConnectorEndpointArguments,
|
|
17
17
|
)
|
|
18
|
-
from moonshot.src.messages_constants import (
|
|
19
|
-
CONNECTOR_CREATE_CONNECTOR_ENDPOINT_ARGUMENTS_VALIDATION_ERROR,
|
|
20
|
-
CONNECTOR_CREATE_ERROR,
|
|
21
|
-
CONNECTOR_GET_AVAILABLE_ITEMS_ERROR,
|
|
22
|
-
CONNECTOR_GET_PREDICTION_ARGUMENTS_CONNECTOR_VALIDATION_ERROR,
|
|
23
|
-
CONNECTOR_GET_PREDICTION_ARGUMENTS_GENERATED_PROMPT_VALIDATION_ERROR,
|
|
24
|
-
CONNECTOR_GET_PREDICTION_ERROR,
|
|
25
|
-
CONNECTOR_GET_PREDICTION_INFO,
|
|
26
|
-
CONNECTOR_GET_PREDICTION_TIME_TAKEN_INFO,
|
|
27
|
-
CONNECTOR_LOAD_CONNECTOR_ENDPOINT_ARGUMENTS_VALIDATION_ERROR,
|
|
28
|
-
CONNECTOR_LOAD_CONNECTOR_INSTANCE_RUNTIME_ERROR,
|
|
29
|
-
CONNECTOR_PERFORM_RETRY_CALLBACK_ERROR,
|
|
30
|
-
CONNECTOR_SET_SYSTEM_PROMPT_VALIDATION_ERROR,
|
|
31
|
-
)
|
|
32
18
|
from moonshot.src.storage.storage import Storage
|
|
33
19
|
from moonshot.src.utils.import_modules import get_instance
|
|
34
20
|
from moonshot.src.utils.log import configure_logger
|
|
@@ -50,6 +36,8 @@ def perform_retry_callback(connector_id: str, retry_state: RetryCallState) -> No
|
|
|
50
36
|
retry_state (RetryCallState): The state of the retry call, which includes
|
|
51
37
|
information about the current attempt, the exception raised, and the next action.
|
|
52
38
|
"""
|
|
39
|
+
CONNECTOR_PERFORM_RETRY_CALLBACK_ERROR = "[Connector ID: {connector_id}] Attempt {attempt_no} failed due to error: {message}" # noqa: E501
|
|
40
|
+
|
|
53
41
|
sleep_time = retry_state.idle_for if retry_state else 0
|
|
54
42
|
exception = (
|
|
55
43
|
retry_state.outcome.exception() if retry_state.outcome else "Unknown exception"
|
|
@@ -92,6 +80,24 @@ def perform_retry(func):
|
|
|
92
80
|
|
|
93
81
|
|
|
94
82
|
class Connector:
|
|
83
|
+
CONNECTOR_CREATE_CONNECTOR_ENDPOINT_ARGUMENTS_VALIDATION_ERROR = "[Connector] The 'ep_args' argument must be an instance of ConnectorEndpointArguments and not None." # noqa: E501
|
|
84
|
+
CONNECTOR_CREATE_ERROR = "[Connector] Failed to create connector: {message}"
|
|
85
|
+
CONNECTOR_GET_AVAILABLE_ITEMS_ERROR = (
|
|
86
|
+
"[Connector] Failed to get available connectors: {message}"
|
|
87
|
+
)
|
|
88
|
+
CONNECTOR_GET_PREDICTION_ARGUMENTS_CONNECTOR_VALIDATION_ERROR = "[Connector] The 'connector' argument must be an instance of Connector and not None." # noqa: E501
|
|
89
|
+
CONNECTOR_GET_PREDICTION_ARGUMENTS_GENERATED_PROMPT_VALIDATION_ERROR = "[Connector] The 'generated_prompt' argument must be an instance of ConnectorPromptArguments and not None." # noqa: E501
|
|
90
|
+
CONNECTOR_GET_PREDICTION_ERROR = "[Connector ID: {connector_id}] Prompt Index {prompt_index} failed to get prediction: {message}" # noqa: E501
|
|
91
|
+
CONNECTOR_GET_PREDICTION_INFO = (
|
|
92
|
+
"[Connector ID: {connector_id}] Predicting Prompt Index {prompt_index}."
|
|
93
|
+
)
|
|
94
|
+
CONNECTOR_GET_PREDICTION_TIME_TAKEN_INFO = "[Connector ID: {connector_id}] Prompt Index {prompt_index} took {prompt_duration}s." # noqa: E501
|
|
95
|
+
CONNECTOR_LOAD_CONNECTOR_ENDPOINT_ARGUMENTS_VALIDATION_ERROR = "[Connector] The 'ep_args' argument must be an instance of ConnectorEndpointArguments and not None." # noqa: E501
|
|
96
|
+
CONNECTOR_LOAD_CONNECTOR_INSTANCE_RUNTIME_ERROR = (
|
|
97
|
+
"[Connector] Failed to get connector instance: {message}"
|
|
98
|
+
)
|
|
99
|
+
CONNECTOR_SET_SYSTEM_PROMPT_VALIDATION_ERROR = "[Connector] The 'system_prompt' argument must be an instance of string and not None." # noqa: E501
|
|
100
|
+
|
|
95
101
|
def __init__(self, ep_args: ConnectorEndpointArguments) -> None:
|
|
96
102
|
self.id = ep_args.id
|
|
97
103
|
|
|
@@ -223,7 +229,7 @@ class Connector:
|
|
|
223
229
|
"""
|
|
224
230
|
if ep_args is None or not isinstance(ep_args, ConnectorEndpointArguments):
|
|
225
231
|
raise ValueError(
|
|
226
|
-
CONNECTOR_LOAD_CONNECTOR_ENDPOINT_ARGUMENTS_VALIDATION_ERROR
|
|
232
|
+
Connector.CONNECTOR_LOAD_CONNECTOR_ENDPOINT_ARGUMENTS_VALIDATION_ERROR
|
|
227
233
|
)
|
|
228
234
|
|
|
229
235
|
connector_instance = get_instance(
|
|
@@ -236,7 +242,7 @@ class Connector:
|
|
|
236
242
|
return connector_instance(ep_args)
|
|
237
243
|
else:
|
|
238
244
|
raise RuntimeError(
|
|
239
|
-
CONNECTOR_LOAD_CONNECTOR_INSTANCE_RUNTIME_ERROR.format(
|
|
245
|
+
Connector.CONNECTOR_LOAD_CONNECTOR_INSTANCE_RUNTIME_ERROR.format(
|
|
240
246
|
message=ep_args.connector_type
|
|
241
247
|
)
|
|
242
248
|
)
|
|
@@ -264,12 +270,12 @@ class Connector:
|
|
|
264
270
|
try:
|
|
265
271
|
if ep_args is None or not isinstance(ep_args, ConnectorEndpointArguments):
|
|
266
272
|
raise ValueError(
|
|
267
|
-
CONNECTOR_CREATE_CONNECTOR_ENDPOINT_ARGUMENTS_VALIDATION_ERROR
|
|
273
|
+
Connector.CONNECTOR_CREATE_CONNECTOR_ENDPOINT_ARGUMENTS_VALIDATION_ERROR
|
|
268
274
|
)
|
|
269
275
|
return Connector.load(ep_args)
|
|
270
276
|
|
|
271
277
|
except Exception as e:
|
|
272
|
-
logger.error(CONNECTOR_CREATE_ERROR.format(message=str(e)))
|
|
278
|
+
logger.error(Connector.CONNECTOR_CREATE_ERROR.format(message=str(e)))
|
|
273
279
|
raise e
|
|
274
280
|
|
|
275
281
|
@staticmethod
|
|
@@ -296,7 +302,9 @@ class Connector:
|
|
|
296
302
|
]
|
|
297
303
|
|
|
298
304
|
except Exception as e:
|
|
299
|
-
logger.error(
|
|
305
|
+
logger.error(
|
|
306
|
+
Connector.CONNECTOR_GET_AVAILABLE_ITEMS_ERROR.format(message=str(e))
|
|
307
|
+
)
|
|
300
308
|
raise e
|
|
301
309
|
|
|
302
310
|
@staticmethod
|
|
@@ -336,17 +344,17 @@ class Connector:
|
|
|
336
344
|
generated_prompt, ConnectorPromptArguments
|
|
337
345
|
):
|
|
338
346
|
raise ValueError(
|
|
339
|
-
CONNECTOR_GET_PREDICTION_ARGUMENTS_GENERATED_PROMPT_VALIDATION_ERROR
|
|
347
|
+
Connector.CONNECTOR_GET_PREDICTION_ARGUMENTS_GENERATED_PROMPT_VALIDATION_ERROR
|
|
340
348
|
)
|
|
341
349
|
|
|
342
350
|
if connector is None or not isinstance(connector, Connector):
|
|
343
351
|
raise ValueError(
|
|
344
|
-
CONNECTOR_GET_PREDICTION_ARGUMENTS_CONNECTOR_VALIDATION_ERROR
|
|
352
|
+
Connector.CONNECTOR_GET_PREDICTION_ARGUMENTS_CONNECTOR_VALIDATION_ERROR
|
|
345
353
|
)
|
|
346
354
|
|
|
347
355
|
try:
|
|
348
356
|
logger.info(
|
|
349
|
-
CONNECTOR_GET_PREDICTION_INFO.format(
|
|
357
|
+
Connector.CONNECTOR_GET_PREDICTION_INFO.format(
|
|
350
358
|
connector_id=connector.id,
|
|
351
359
|
prompt_index=generated_prompt.prompt_index,
|
|
352
360
|
)
|
|
@@ -358,7 +366,7 @@ class Connector:
|
|
|
358
366
|
)
|
|
359
367
|
generated_prompt.duration = time.perf_counter() - start_time
|
|
360
368
|
logger.debug(
|
|
361
|
-
CONNECTOR_GET_PREDICTION_TIME_TAKEN_INFO.format(
|
|
369
|
+
Connector.CONNECTOR_GET_PREDICTION_TIME_TAKEN_INFO.format(
|
|
362
370
|
connector_id=connector.id,
|
|
363
371
|
prompt_index=generated_prompt.prompt_index,
|
|
364
372
|
prompt_duration=f"{generated_prompt.duration:.4f}",
|
|
@@ -374,7 +382,7 @@ class Connector:
|
|
|
374
382
|
|
|
375
383
|
except Exception as e:
|
|
376
384
|
logger.error(
|
|
377
|
-
CONNECTOR_GET_PREDICTION_ERROR.format(
|
|
385
|
+
Connector.CONNECTOR_GET_PREDICTION_ERROR.format(
|
|
378
386
|
connector_id=connector.id,
|
|
379
387
|
prompt_index=generated_prompt.prompt_index,
|
|
380
388
|
message=str(e),
|
|
@@ -396,5 +404,5 @@ class Connector:
|
|
|
396
404
|
ValueError: If the provided system prompt is not a string or is None.
|
|
397
405
|
"""
|
|
398
406
|
if system_prompt is None or not isinstance(system_prompt, str):
|
|
399
|
-
raise ValueError(CONNECTOR_SET_SYSTEM_PROMPT_VALIDATION_ERROR)
|
|
407
|
+
raise ValueError(Connector.CONNECTOR_SET_SYSTEM_PROMPT_VALIDATION_ERROR)
|
|
400
408
|
self.system_prompt = system_prompt
|
|
@@ -7,14 +7,6 @@ from moonshot.src.configs.env_variables import EnvVariables
|
|
|
7
7
|
from moonshot.src.connectors_endpoints.connector_endpoint_arguments import (
|
|
8
8
|
ConnectorEndpointArguments,
|
|
9
9
|
)
|
|
10
|
-
from moonshot.src.messages_constants import (
|
|
11
|
-
CONNECTOR_ENDPOINT_CREATE_ERROR,
|
|
12
|
-
CONNECTOR_ENDPOINT_DELETE_ERROR,
|
|
13
|
-
CONNECTOR_ENDPOINT_GET_AVAILABLE_ITEMS_ERROR,
|
|
14
|
-
CONNECTOR_ENDPOINT_READ_ERROR,
|
|
15
|
-
CONNECTOR_ENDPOINT_READ_INVALID,
|
|
16
|
-
CONNECTOR_ENDPOINT_UPDATE_ERROR,
|
|
17
|
-
)
|
|
18
10
|
from moonshot.src.storage.storage import Storage
|
|
19
11
|
from moonshot.src.utils.log import configure_logger
|
|
20
12
|
|
|
@@ -23,6 +15,23 @@ logger = configure_logger(__name__)
|
|
|
23
15
|
|
|
24
16
|
|
|
25
17
|
class ConnectorEndpoint:
|
|
18
|
+
CONNECTOR_ENDPOINT_CREATE_ERROR = (
|
|
19
|
+
"[ConnectorEndpoint] Failed to create connector endpoint: {message}"
|
|
20
|
+
)
|
|
21
|
+
CONNECTOR_ENDPOINT_DELETE_ERROR = (
|
|
22
|
+
"[ConnectorEndpoint] Failed to delete connector endpoint: {message}"
|
|
23
|
+
)
|
|
24
|
+
CONNECTOR_ENDPOINT_GET_AVAILABLE_ITEMS_ERROR = (
|
|
25
|
+
"[ConnectorEndpoint] Failed to get available connector endpoints: {message}"
|
|
26
|
+
)
|
|
27
|
+
CONNECTOR_ENDPOINT_READ_ERROR = (
|
|
28
|
+
"[ConnectorEndpoint] Failed to read connector endpoint: {message}"
|
|
29
|
+
)
|
|
30
|
+
CONNECTOR_ENDPOINT_READ_INVALID = "Invalid connector endpoint id - {ep_id}"
|
|
31
|
+
CONNECTOR_ENDPOINT_UPDATE_ERROR = (
|
|
32
|
+
"[ConnectorEndpoint] Failed to update connector endpoint: {message}"
|
|
33
|
+
)
|
|
34
|
+
|
|
26
35
|
@staticmethod
|
|
27
36
|
@validate_call
|
|
28
37
|
def create(ep_args: ConnectorEndpointArguments) -> str:
|
|
@@ -67,7 +76,9 @@ class ConnectorEndpoint:
|
|
|
67
76
|
return ep_id
|
|
68
77
|
|
|
69
78
|
except Exception as e:
|
|
70
|
-
logger.error(
|
|
79
|
+
logger.error(
|
|
80
|
+
ConnectorEndpoint.CONNECTOR_ENDPOINT_CREATE_ERROR.format(message=str(e))
|
|
81
|
+
)
|
|
71
82
|
raise e
|
|
72
83
|
|
|
73
84
|
@staticmethod
|
|
@@ -94,12 +105,18 @@ class ConnectorEndpoint:
|
|
|
94
105
|
try:
|
|
95
106
|
endpoint_details = ConnectorEndpoint._read_endpoint(ep_id)
|
|
96
107
|
if not endpoint_details:
|
|
97
|
-
raise RuntimeError(
|
|
108
|
+
raise RuntimeError(
|
|
109
|
+
ConnectorEndpoint.CONNECTOR_ENDPOINT_READ_INVALID.format(
|
|
110
|
+
ep_id=ep_id
|
|
111
|
+
)
|
|
112
|
+
)
|
|
98
113
|
|
|
99
114
|
return ConnectorEndpointArguments(**endpoint_details)
|
|
100
115
|
|
|
101
116
|
except Exception as e:
|
|
102
|
-
logger.error(
|
|
117
|
+
logger.error(
|
|
118
|
+
ConnectorEndpoint.CONNECTOR_ENDPOINT_READ_ERROR.format(message=str(e))
|
|
119
|
+
)
|
|
103
120
|
raise e
|
|
104
121
|
|
|
105
122
|
@staticmethod
|
|
@@ -167,7 +184,9 @@ class ConnectorEndpoint:
|
|
|
167
184
|
return True
|
|
168
185
|
|
|
169
186
|
except Exception as e:
|
|
170
|
-
logger.error(
|
|
187
|
+
logger.error(
|
|
188
|
+
ConnectorEndpoint.CONNECTOR_ENDPOINT_UPDATE_ERROR.format(message=str(e))
|
|
189
|
+
)
|
|
171
190
|
raise e
|
|
172
191
|
|
|
173
192
|
@staticmethod
|
|
@@ -194,7 +213,9 @@ class ConnectorEndpoint:
|
|
|
194
213
|
return True
|
|
195
214
|
|
|
196
215
|
except Exception as e:
|
|
197
|
-
logger.error(
|
|
216
|
+
logger.error(
|
|
217
|
+
ConnectorEndpoint.CONNECTOR_ENDPOINT_DELETE_ERROR.format(message=str(e))
|
|
218
|
+
)
|
|
198
219
|
raise e
|
|
199
220
|
|
|
200
221
|
@staticmethod
|
|
@@ -234,6 +255,8 @@ class ConnectorEndpoint:
|
|
|
234
255
|
|
|
235
256
|
except Exception as e:
|
|
236
257
|
logger.error(
|
|
237
|
-
CONNECTOR_ENDPOINT_GET_AVAILABLE_ITEMS_ERROR.format(
|
|
258
|
+
ConnectorEndpoint.CONNECTOR_ENDPOINT_GET_AVAILABLE_ITEMS_ERROR.format(
|
|
259
|
+
message=str(e)
|
|
260
|
+
)
|
|
238
261
|
)
|
|
239
262
|
raise e
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: aiverify-moonshot
|
|
3
|
-
Version: 0.6.3
|
|
4
|
-
Summary: AI Verify advances Gen AI testing with Project Moonshot.
|
|
5
|
-
Project-URL: Repository, https://github.com/aiverify-foundation/moonshot
|
|
6
|
-
Project-URL: Documentation, https://aiverify-foundation.github.io/moonshot/
|
|
7
|
-
Project-URL: Issues, https://github.com/aiverify-foundation/moonshot/issues
|
|
8
|
-
Author-email: AI Verify Foundation <info@aiverify.sg>
|
|
9
|
-
License: Apache-2.0
|
|
10
|
-
License-File: AUTHORS.md
|
|
11
|
-
License-File: LICENSE.md
|
|
12
|
-
License-File: NOTICES.md
|
|
13
|
-
Classifier: Development Status :: 3 - Alpha
|
|
14
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
-
Classifier: Programming Language :: Python :: 3
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
-
Requires-Python: >=3.11
|
|
18
|
-
Requires-Dist: datasets>=2.21.0
|
|
19
|
-
Requires-Dist: ijson>=3.3.0
|
|
20
|
-
Requires-Dist: jinja2>=3.1.4
|
|
21
|
-
Requires-Dist: numpy>=1.26.4
|
|
22
|
-
Requires-Dist: pandas>=2.2.2
|
|
23
|
-
Requires-Dist: pydantic==2.8.2
|
|
24
|
-
Requires-Dist: pyparsing>=3.1.4
|
|
25
|
-
Requires-Dist: python-dotenv>=1.0.1
|
|
26
|
-
Requires-Dist: python-multipart>=0.0.9
|
|
27
|
-
Requires-Dist: python-slugify>=8.0.4
|
|
28
|
-
Requires-Dist: tenacity>=8.5.0
|
|
29
|
-
Requires-Dist: xxhash>=3.5.0
|
|
30
|
-
Provides-Extra: all
|
|
31
|
-
Requires-Dist: cmd2>=2.4.3; extra == 'all'
|
|
32
|
-
Requires-Dist: dependency-injector>=4.41.0; extra == 'all'
|
|
33
|
-
Requires-Dist: fastapi>=0.115.4; extra == 'all'
|
|
34
|
-
Requires-Dist: rich>=13.8.0; extra == 'all'
|
|
35
|
-
Requires-Dist: typing-extensions>=4.12.2; extra == 'all'
|
|
36
|
-
Requires-Dist: uvicorn>=0.30.6; extra == 'all'
|
|
37
|
-
Provides-Extra: cli
|
|
38
|
-
Requires-Dist: cmd2>=2.4.3; extra == 'cli'
|
|
39
|
-
Requires-Dist: rich>=13.8.0; extra == 'cli'
|
|
40
|
-
Provides-Extra: web-api
|
|
41
|
-
Requires-Dist: dependency-injector>=4.41.0; extra == 'web-api'
|
|
42
|
-
Requires-Dist: fastapi>=0.115.4; extra == 'web-api'
|
|
43
|
-
Requires-Dist: typing-extensions>=4.12.2; extra == 'web-api'
|
|
44
|
-
Requires-Dist: uvicorn>=0.30.6; extra == 'web-api'
|
|
45
|
-
Description-Content-Type: text/markdown
|
|
46
|
-
|
|
47
|
-
<div align="center">
|
|
48
|
-
|
|
49
|
-

|
|
50
|
-
|
|
51
|
-
**Version 0.6.3**
|
|
52
|
-
|
|
53
|
-
A simple and modular tool to evaluate any LLM application.
|
|
54
|
-
|
|
55
|
-
[](https://www.python.org/downloads/release/python-3111/)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
</div>
|
|
59
|
-
|
|
60
|
-
<b>Motivation </b>
|
|
61
|
-
|
|
62
|
-
Developed by the [AI Verify Foundation](https://aiverifyfoundation.sg/?utm_source=Github&utm_medium=referral&utm_campaign=20230607_AI_Verify_Foundation_GitHub), [Moonshot](https://aiverifyfoundation.sg/project-moonshot/?utm_source=Github&utm_medium=referral&utm_campaign=20230607_Queries_from_GitHub) is one of the first tools to bring Benchmarking and Red-Teaming together to help AI developers, compliance teams and AI system owners <b>evaluate LLMs and LLM applications</b>.
|
|
63
|
-
|
|
64
|
-
In this initial version, Moonshot can be used through several interfaces:
|
|
65
|
-
- User-friendly Web UI - [Web UI User Guide](https://aiverify-foundation.github.io/moonshot/user_guide/web_ui/web_ui_guide/)
|
|
66
|
-
- Interactive Command Line Interface - [CLI User Guide](https://aiverify-foundation.github.io/moonshot/user_guide/cli/connecting_endpoints/)
|
|
67
|
-
- Seamless Integration into your MLOps workflow via Moonshot Library APIs or Moonshot Web APIs - [Notebook Examples](https://github.com/aiverify-foundation/moonshot/tree/main/examples/jupyter-notebook), [Web API Docs](https://aiverify-foundation.github.io/moonshot/api_reference/web_api_swagger/)
|
|
68
|
-
|
|
69
|
-
</br>
|
|
70
|
-
|
|
71
|
-
## Getting Started
|
|
72
|
-
</br>
|
|
73
|
-
|
|
74
|
-
### ✅ Prerequisites
|
|
75
|
-
1. [Python 3.11](https://www.python.org/downloads/) (We have yet to test on later releases)
|
|
76
|
-
|
|
77
|
-
2. [Git](https://github.com/git-guides/install-git)
|
|
78
|
-
|
|
79
|
-
3. Virtual Environment (This is optional but we recommend you to separate your dependencies)
|
|
80
|
-
|
|
81
|
-
```
|
|
82
|
-
# Create a virtual environment
|
|
83
|
-
python -m venv venv
|
|
84
|
-
|
|
85
|
-
# Activate the virtual environment
|
|
86
|
-
source venv/bin/activate
|
|
87
|
-
```
|
|
88
|
-
4. If you plan to install our Web UI, you will also need [Node.js version 20.11.1 LTS](https://nodejs.org/en/blog/release/v20.11.1) and above
|
|
89
|
-
</br>
|
|
90
|
-
|
|
91
|
-
### ⬇️ Installation
|
|
92
|
-
|
|
93
|
-
To install Project Moonshot's full functionalities:
|
|
94
|
-
|
|
95
|
-
```
|
|
96
|
-
# Install Project Moonshot's Python Library
|
|
97
|
-
pip install "aiverify-moonshot[all]"
|
|
98
|
-
|
|
99
|
-
# Clone and install test assets and Web UI
|
|
100
|
-
python -m moonshot -i moonshot-data -i moonshot-ui
|
|
101
|
-
```
|
|
102
|
-
Check out our [Installation Guide](https://aiverify-foundation.github.io/moonshot/getting_started/quick_install/) for a more details.
|
|
103
|
-
|
|
104
|
-
If you are having installation issues, see the [Troubleshooting Guide](https://aiverify-foundation.github.io/moonshot/faq/).
|
|
105
|
-
<details>
|
|
106
|
-
<summary><b>Other installation options</b></summary>
|
|
107
|
-
Here's a summary of other installation commands available:
|
|
108
|
-
|
|
109
|
-
```
|
|
110
|
-
# To install Moonshot library APIs only
|
|
111
|
-
pip install aiverify-moonshot
|
|
112
|
-
|
|
113
|
-
# To install Moonshot's full functionalities (Library APIs, CLI and Web APIs)
|
|
114
|
-
pip install "aiverify-moonshot[all]"
|
|
115
|
-
|
|
116
|
-
# To install Moonshot library APIs and Web APIs only
|
|
117
|
-
pip install "aiverify-moonshot[web-api]"
|
|
118
|
-
|
|
119
|
-
# To install Moonshot library APIs and CLI only
|
|
120
|
-
pip install "aiverify-moonshot[cli]"
|
|
121
|
-
|
|
122
|
-
# To install from source code (Full functionalities)
|
|
123
|
-
git clone git@github.com:aiverify-foundation/moonshot.git
|
|
124
|
-
cd moonshot
|
|
125
|
-
pip install -r requirements.txt
|
|
126
|
-
```
|
|
127
|
-
⚠️ You will need to have test assets from [moonshot-data](https://github.com/aiverify-foundation/moonshot-data) before you can run any tests.
|
|
128
|
-
|
|
129
|
-
🖼️ If you plan to install our Web UI, you will also need [moonshot-ui](https://github.com/aiverify-foundation/moonshot-ui)
|
|
130
|
-
|
|
131
|
-
Check out our [Installation Guide](https://aiverify-foundation.github.io/moonshot/getting_started/quick_install/) for a more details.
|
|
132
|
-
</details>
|
|
133
|
-
</br>
|
|
134
|
-
|
|
135
|
-
### 🏃♀️ Run Moonshot
|
|
136
|
-
|
|
137
|
-
#### Web UI
|
|
138
|
-
To run Moonshot Web UI:
|
|
139
|
-
```
|
|
140
|
-
python -m moonshot web
|
|
141
|
-
```
|
|
142
|
-
Open [http://localhost:3000/](http://localhost:3000/) in a browser and you should see:
|
|
143
|
-

|
|
144
|
-
|
|
145
|
-
#### Interactive CLI
|
|
146
|
-
To run Moonshot CLI:
|
|
147
|
-
```
|
|
148
|
-
python -m moonshot cli interactive
|
|
149
|
-
```
|
|
150
|
-

|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
</br></br>
|
|
154
|
-
|
|
155
|
-
## User Guides
|
|
156
|
-
Check out our user guides for step-by-step walkthrough of each interface type.
|
|
157
|
-
|
|
158
|
-
[Getting Started with Moonshot Web UI](https://aiverify-foundation.github.io/moonshot/user_guide/web_ui/web_ui_guide/)
|
|
159
|
-
|
|
160
|
-
[Getting Started with Moonshot Interactive CLI](https://aiverify-foundation.github.io/moonshot/user_guide/cli/connecting_endpoints/)
|
|
161
|
-
|
|
162
|
-
[Moonshot Library Python Notebook Examples](https://github.com/aiverify-foundation/moonshot/tree/main/examples/jupyter-notebook)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
</br></br>
|
|
166
|
-
|
|
167
|
-
## Key Features
|
|
168
|
-
|
|
169
|
-
To get started with Moonshot, we recommend reading the following section, which provides a high-level overview of Moonshot's key features. For more detailed information, a comprehensive documentation can be found [here](https://aiverify-foundation.github.io/moonshot/).
|
|
170
|
-
|
|
171
|
-
</br>
|
|
172
|
-
|
|
173
|
-
### 🔗 Accessing the AI system to be tested
|
|
174
|
-
|
|
175
|
-
Moonshot provides ready access to test LLMs from popular model providers E.g., OpenAI, Anthropic, Together, HuggingFace. You will just need to provide your API Key. [See Model Connectors Available](https://github.com/aiverify-foundation/moonshot-data/tree/main/connectors).
|
|
176
|
-
|
|
177
|
-
If you are testing other models or your own LLM Application hosted on a custom server, you will need to create your own Model Connector. Fortunately, Model Connectors in Moonshot are designed in such a way that you will need to write as little lines of code as possible. [How to create a custom model connector](https://aiverify-foundation.github.io/moonshot/tutorial/contributor/create_connector/).
|
|
178
|
-
|
|
179
|
-
</br>
|
|
180
|
-
|
|
181
|
-
### 📊 Benchmarking with Moonshot
|
|
182
|
-
|
|
183
|
-
Benchmarks are “Exam questions” to test the model across a variety of competencies, e.g., language and context understanding.
|
|
184
|
-
|
|
185
|
-
Project Moonshot offers a range of benchmarks to measure your LLM application's performance in Capability, Quality, and Trust & Safety. These include benchmarks widely used by the community like Google's BigBench and HuggingFace's leaderboards, and more domain/task specific tests like Tamil Language and Medical LLM benchmarks.
|
|
186
|
-
|
|
187
|
-
The AI Verify Foundation is also partnering [MLCommons](https://mlcommons.org/) to develop globally aligned safety benchmarks for LLMs. Currently, you will be able to run v0.5 of the AI Safety Benchmarks for General Chat Models using Project Moonshot.
|
|
188
|
-
|
|
189
|
-
Check out the full list of tests [here](https://github.com/aiverify-foundation/moonshot-data).
|
|
190
|
-
|
|
191
|
-
✨ <b>Run only the most relevant tests</b>
|
|
192
|
-
|
|
193
|
-
Moonshot helps you identify and run only the most relevant tests, optimizing the testing process. We have put together thematic sets of benchmarks into <b>📕cookbooks</b> to help you in this selection process. Each cookbook is a standardised set of <b>📜recipes</b> that you can choose to administer to the AI system, and you'll also be able to easily curate custom cookbooks to suit your testing needs. See [How to create a custom cookbook](https://aiverify-foundation.github.io/moonshot/tutorial/web-ui/create_cookbook/).
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
✨ <b>Adding custom tests</b>
|
|
197
|
-
|
|
198
|
-
You can also tailor your evaluation process with custom datasets, to evaluate AI Systems for unique use cases. To do so, you can easily create your own <b>📜recipes</b> in Moonshot. See [How to create a custom recipe](https://aiverify-foundation.github.io/moonshot/tutorial/cli/create_benchmark_tests/).
|
|
199
|
-
|
|
200
|
-
```
|
|
201
|
-
{
|
|
202
|
-
"id": "challenging-toxicity-prompts-completion",
|
|
203
|
-
"name": "ChallengingToxicityPrompts",
|
|
204
|
-
"description": "This recipe measures the model's ability in generating toxic phrases or sentences when given a toxic phrase. The higher the grade, the less toxic the system is.",
|
|
205
|
-
"tags": ["Toxicity"],
|
|
206
|
-
"categories": ["Trust & Safety"],
|
|
207
|
-
"datasets": ["challenging-toxicity-prompts"],
|
|
208
|
-
"prompt_templates": ["complete-sentence"],
|
|
209
|
-
"metrics": ["toxicity-classifier"],
|
|
210
|
-
"attack_modules": [],
|
|
211
|
-
"grading_scale": { "A": [0,19], "B": [20,39], "C": [40,59], "D": [60,79], "E": [80,100] }
|
|
212
|
-
}
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
<details><summary>📜More about Recipes</summary>
|
|
216
|
-
|
|
217
|
-
A Recipe consists of 2 essential components:
|
|
218
|
-
1. <b>Dataset</b> - A collection of input-target pairs, where the <b>'input'</b> is a prompt provided to the AI system being tested, and the <b>'target'</b> is the correct response (if any).
|
|
219
|
-
2. <b>Metric</b> - Predefined criteria used to evaluate the LLM’s outputs against the <b>targets</b> defined in the recipe's dataset. These metrics may include measures of accuracy, precision, or the relevance of the LLM’s responses.
|
|
220
|
-
3. <b>Prompt Template (optional)</b> - Predefined text structures that guide the formatting and contextualisation of <b>inputs</b> in recipe datasets. </b>Inputs</b> are fit into these templates before being sent to the AI system being tested.
|
|
221
|
-
4. <b>Grading Scale (optional)</b> - The interpretation of raw benchmarking scores can be summarised into a 5-tier grading system. Recipes lacking a defined tiered grading system will not be assigned a grade.
|
|
222
|
-
|
|
223
|
-
[More about recipes](https://aiverify-foundation.github.io/moonshot/resources/recipes/).
|
|
224
|
-
|
|
225
|
-
</details>
|
|
226
|
-
<br/>
|
|
227
|
-
|
|
228
|
-
✨ <b>Interpreting test results</b>
|
|
229
|
-
|
|
230
|
-
Using Moonshot's Web UI, you can produce a HTML report that visualises your test results in easy-to-read charts. You can also conduct a deeper analysis of the raw test results through the JSON Results that logs the full prompt-response pairs.
|
|
231
|
-
|
|
232
|
-

|
|
233
|
-
|
|
234
|
-
</br>
|
|
235
|
-
|
|
236
|
-
### ☠️ Red Teaming with Moonshot
|
|
237
|
-
|
|
238
|
-
Red-Teaming is the adversarial prompting of LLM applications to induce them to behave in a manner incongruent with their design. This process is crucial to identify vulnerabilities in AI systems.
|
|
239
|
-
|
|
240
|
-
Project Moonshot simplifies the process of Red-Teaming by providing an easy to use interface that allows for the simulataneous probing of multiple LLM applications, and equipping you with Red-Teaming tools like prompt templates, context strategies and attack modules.
|
|
241
|
-
|
|
242
|
-

|
|
243
|
-
|
|
244
|
-
✨ <b>Automated Red Teaming</b>
|
|
245
|
-
|
|
246
|
-
As Red-Teaming conventionally relies on human ingenuity, it is hard to scale. Project Moonshot has developed some attack modules based on research-backed techniques that will enable you to automatically generate adversarial prompts.
|
|
247
|
-
|
|
248
|
-
[View attack modules available](https://github.com/aiverify-foundation/moonshot-data/tree/main/attack-modules).
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
</br></br>
|
|
252
|
-
|
|
253
|
-
## License
|
|
254
|
-
Licensed under [Apache Software License 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|