aiverify-moonshot 0.4.11__py3-none-any.whl → 0.5.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.
- {aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.0.dist-info}/METADATA +3 -5
- {aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.0.dist-info}/RECORD +34 -34
- {aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.0.dist-info}/WHEEL +1 -1
- moonshot/integrations/cli/benchmark/cookbook.py +1 -5
- moonshot/integrations/cli/benchmark/recipe.py +1 -5
- moonshot/integrations/cli/cli_errors.py +3 -0
- moonshot/integrations/cli/common/connectors.py +22 -10
- moonshot/integrations/web_api/app.py +1 -1
- moonshot/integrations/web_api/schemas/endpoint_create_dto.py +1 -0
- moonshot/integrations/web_api/services/endpoint_service.py +1 -0
- moonshot/src/api/api_bookmark.py +16 -5
- moonshot/src/api/api_connector.py +3 -3
- moonshot/src/api/api_connector_endpoint.py +6 -3
- moonshot/src/api/api_context_strategy.py +2 -2
- moonshot/src/api/api_cookbook.py +6 -6
- moonshot/src/api/api_dataset.py +5 -5
- moonshot/src/api/api_environment_variables.py +3 -0
- moonshot/src/api/api_metrics.py +1 -1
- moonshot/src/api/api_prompt_template.py +9 -0
- moonshot/src/api/api_recipe.py +3 -3
- moonshot/src/api/api_red_teaming.py +4 -8
- moonshot/src/api/api_result.py +10 -6
- moonshot/src/api/api_run.py +3 -3
- moonshot/src/api/api_runner.py +7 -6
- moonshot/src/api/api_session.py +11 -7
- moonshot/src/connectors/connector.py +121 -58
- moonshot/src/connectors/connector_prompt_arguments.py +7 -4
- moonshot/src/connectors/connector_response.py +5 -10
- moonshot/src/connectors_endpoints/connector_endpoint.py +32 -20
- moonshot/src/connectors_endpoints/connector_endpoint_arguments.py +4 -1
- moonshot/src/messages_constants.py +85 -3
- {aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.0.dist-info}/licenses/AUTHORS.md +0 -0
- {aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.0.dist-info}/licenses/LICENSE.md +0 -0
- {aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.0.dist-info}/licenses/NOTICES.md +0 -0
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
|
|
3
|
-
from pydantic import validate_call
|
|
3
|
+
from pydantic import constr, validate_call
|
|
4
4
|
from slugify import slugify
|
|
5
5
|
|
|
6
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
|
+
)
|
|
10
18
|
from moonshot.src.storage.storage import Storage
|
|
11
19
|
from moonshot.src.utils.log import configure_logger
|
|
12
20
|
|
|
@@ -16,6 +24,7 @@ logger = configure_logger(__name__)
|
|
|
16
24
|
|
|
17
25
|
class ConnectorEndpoint:
|
|
18
26
|
@staticmethod
|
|
27
|
+
@validate_call
|
|
19
28
|
def create(ep_args: ConnectorEndpointArguments) -> str:
|
|
20
29
|
"""
|
|
21
30
|
Creates a new connector endpoint and stores its details as a JSON object.
|
|
@@ -47,6 +56,7 @@ class ConnectorEndpoint:
|
|
|
47
56
|
"token": ep_args.token,
|
|
48
57
|
"max_calls_per_second": ep_args.max_calls_per_second,
|
|
49
58
|
"max_concurrency": ep_args.max_concurrency,
|
|
59
|
+
"model": ep_args.model,
|
|
50
60
|
"params": ep_args.params,
|
|
51
61
|
}
|
|
52
62
|
|
|
@@ -57,12 +67,12 @@ class ConnectorEndpoint:
|
|
|
57
67
|
return ep_id
|
|
58
68
|
|
|
59
69
|
except Exception as e:
|
|
60
|
-
logger.error(
|
|
70
|
+
logger.error(CONNECTOR_ENDPOINT_CREATE_ERROR.format(message=str(e)))
|
|
61
71
|
raise e
|
|
62
72
|
|
|
63
73
|
@staticmethod
|
|
64
74
|
@validate_call
|
|
65
|
-
def read(ep_id:
|
|
75
|
+
def read(ep_id: constr(min_length=1)) -> ConnectorEndpointArguments:
|
|
66
76
|
"""
|
|
67
77
|
Retrieves the details of a specified endpoint by its ID.
|
|
68
78
|
|
|
@@ -72,27 +82,24 @@ class ConnectorEndpoint:
|
|
|
72
82
|
any other error occurs, an exception is raised with an appropriate error message.
|
|
73
83
|
|
|
74
84
|
Args:
|
|
75
|
-
ep_id (
|
|
85
|
+
ep_id (constr(min_length=1)): The unique identifier of the endpoint whose details are to be retrieved.
|
|
76
86
|
|
|
77
87
|
Returns:
|
|
78
88
|
ConnectorEndpointArguments: An instance filled with the endpoint's details.
|
|
79
89
|
|
|
80
90
|
Raises:
|
|
81
|
-
RuntimeError: If the
|
|
91
|
+
RuntimeError: If the specified endpoint does not exist.
|
|
82
92
|
Exception: For any issues encountered during the file reading or data parsing process.
|
|
83
93
|
"""
|
|
84
94
|
try:
|
|
85
|
-
if not ep_id:
|
|
86
|
-
raise RuntimeError("Connector Endpoint ID is empty.")
|
|
87
|
-
|
|
88
95
|
endpoint_details = ConnectorEndpoint._read_endpoint(ep_id)
|
|
89
96
|
if not endpoint_details:
|
|
90
|
-
raise RuntimeError(
|
|
97
|
+
raise RuntimeError(CONNECTOR_ENDPOINT_READ_INVALID.format(ep_id=ep_id))
|
|
91
98
|
|
|
92
99
|
return ConnectorEndpointArguments(**endpoint_details)
|
|
93
100
|
|
|
94
101
|
except Exception as e:
|
|
95
|
-
logger.error(
|
|
102
|
+
logger.error(CONNECTOR_ENDPOINT_READ_ERROR.format(message=str(e)))
|
|
96
103
|
raise e
|
|
97
104
|
|
|
98
105
|
@staticmethod
|
|
@@ -124,6 +131,7 @@ class ConnectorEndpoint:
|
|
|
124
131
|
return connector_endpoint_info
|
|
125
132
|
|
|
126
133
|
@staticmethod
|
|
134
|
+
@validate_call
|
|
127
135
|
def update(ep_args: ConnectorEndpointArguments) -> bool:
|
|
128
136
|
"""
|
|
129
137
|
Updates the endpoint information in the storage based on the provided ConnectorEndpointArguments object.
|
|
@@ -138,11 +146,10 @@ class ConnectorEndpoint:
|
|
|
138
146
|
ep_args (ConnectorEndpointArguments): The object encapsulating the updated attributes of the endpoint.
|
|
139
147
|
|
|
140
148
|
Returns:
|
|
141
|
-
bool:
|
|
142
|
-
persisted to the storage; otherwise, an exception is raised.
|
|
149
|
+
bool: True if the update was successfully persisted to the storage; otherwise, an exception is raised.
|
|
143
150
|
|
|
144
151
|
Raises:
|
|
145
|
-
Exception:
|
|
152
|
+
Exception: If the update process encounters an error, potentially due to issues with data serialization or
|
|
146
153
|
storage access.
|
|
147
154
|
"""
|
|
148
155
|
try:
|
|
@@ -160,24 +167,24 @@ class ConnectorEndpoint:
|
|
|
160
167
|
return True
|
|
161
168
|
|
|
162
169
|
except Exception as e:
|
|
163
|
-
logger.error(
|
|
170
|
+
logger.error(CONNECTOR_ENDPOINT_UPDATE_ERROR.format(message=str(e)))
|
|
164
171
|
raise e
|
|
165
172
|
|
|
166
173
|
@staticmethod
|
|
167
174
|
@validate_call
|
|
168
|
-
def delete(ep_id:
|
|
175
|
+
def delete(ep_id: constr(min_length=1)) -> bool:
|
|
169
176
|
"""
|
|
170
177
|
Deletes the endpoint with the specified ID.
|
|
171
178
|
|
|
172
179
|
This method attempts to delete the endpoint corresponding to the given ID from the storage.
|
|
173
|
-
If the deletion is successful, it returns True. If an error occurs, it
|
|
180
|
+
If the deletion is successful, it returns True. If an error occurs, it logs an error message
|
|
174
181
|
and re-raises the exception.
|
|
175
182
|
|
|
176
183
|
Args:
|
|
177
|
-
ep_id (
|
|
184
|
+
ep_id (constr(min_length=1)): The unique identifier of the endpoint to be deleted
|
|
178
185
|
|
|
179
186
|
Returns:
|
|
180
|
-
bool: True if the endpoint was successfully deleted.
|
|
187
|
+
bool: True if the endpoint was successfully deleted; otherwise, an exception is raised.
|
|
181
188
|
|
|
182
189
|
Raises:
|
|
183
190
|
Exception: If the deletion process encounters an error.
|
|
@@ -187,7 +194,7 @@ class ConnectorEndpoint:
|
|
|
187
194
|
return True
|
|
188
195
|
|
|
189
196
|
except Exception as e:
|
|
190
|
-
logger.error(
|
|
197
|
+
logger.error(CONNECTOR_ENDPOINT_DELETE_ERROR.format(message=str(e)))
|
|
191
198
|
raise e
|
|
192
199
|
|
|
193
200
|
@staticmethod
|
|
@@ -204,6 +211,9 @@ class ConnectorEndpoint:
|
|
|
204
211
|
Returns:
|
|
205
212
|
tuple[list[str], list[ConnectorEndpointArguments]]: A tuple containing a list of endpoint IDs and a list of
|
|
206
213
|
ConnectorEndpointArguments objects with endpoint details.
|
|
214
|
+
|
|
215
|
+
Raises:
|
|
216
|
+
Exception: If the process of fetching available items encounters an error.
|
|
207
217
|
"""
|
|
208
218
|
try:
|
|
209
219
|
retn_eps = []
|
|
@@ -223,5 +233,7 @@ class ConnectorEndpoint:
|
|
|
223
233
|
return retn_eps_ids, retn_eps
|
|
224
234
|
|
|
225
235
|
except Exception as e:
|
|
226
|
-
logger.error(
|
|
236
|
+
logger.error(
|
|
237
|
+
CONNECTOR_ENDPOINT_GET_AVAILABLE_ITEMS_ERROR.format(message=str(e))
|
|
238
|
+
)
|
|
227
239
|
raise e
|
|
@@ -22,6 +22,8 @@ class ConnectorEndpointArguments(BaseModel):
|
|
|
22
22
|
gt=0
|
|
23
23
|
) # max_concurrency (int): The number of concurrent api calls
|
|
24
24
|
|
|
25
|
+
model: str # model (str): The model identifier for the LLM connector.
|
|
26
|
+
|
|
25
27
|
params: dict # params (dict): A dictionary that contains connection specified parameters
|
|
26
28
|
|
|
27
29
|
# created_date (str): The date and time the endpoint was created in isoformat without 'T'.
|
|
@@ -34,7 +36,7 @@ class ConnectorEndpointArguments(BaseModel):
|
|
|
34
36
|
|
|
35
37
|
This method takes all the attributes of the ConnectorEndpointArguments instance and constructs a dictionary
|
|
36
38
|
with attribute names as keys and their corresponding values. This includes the id, name, connector_type, uri,
|
|
37
|
-
token, max_calls_per_second, max_concurrency, params, and created_date. This dictionary can be used for
|
|
39
|
+
token, max_calls_per_second, max_concurrency, model, params, and created_date. This dictionary can be used for
|
|
38
40
|
serialization purposes, such as storing the endpoint information in a JSON file or sending it over a network.
|
|
39
41
|
|
|
40
42
|
Returns:
|
|
@@ -49,6 +51,7 @@ class ConnectorEndpointArguments(BaseModel):
|
|
|
49
51
|
"token": self.token,
|
|
50
52
|
"max_calls_per_second": self.max_calls_per_second,
|
|
51
53
|
"max_concurrency": self.max_concurrency,
|
|
54
|
+
"model": self.model,
|
|
52
55
|
"params": self.params,
|
|
53
56
|
"created_date": self.created_date,
|
|
54
57
|
}
|
|
@@ -15,7 +15,9 @@ BOOKMARK_GET_BOOKMARK_ERROR_1 = "[Bookmark] Invalid bookmark name: {message}"
|
|
|
15
15
|
# BOOKMARK - delete_bookmark
|
|
16
16
|
# ------------------------------------------------------------------------------
|
|
17
17
|
BOOKMARK_DELETE_BOOKMARK_SUCCESS = "[Bookmark] Bookmark record deleted."
|
|
18
|
-
BOOKMARK_DELETE_BOOKMARK_FAIL =
|
|
18
|
+
BOOKMARK_DELETE_BOOKMARK_FAIL = (
|
|
19
|
+
"[Bookmark] Bookmark record not found. Unable to delete."
|
|
20
|
+
)
|
|
19
21
|
BOOKMARK_DELETE_BOOKMARK_ERROR = (
|
|
20
22
|
"[Bookmark] Failed to delete bookmark record: {message}"
|
|
21
23
|
)
|
|
@@ -33,9 +35,89 @@ BOOKMARK_DELETE_ALL_BOOKMARK_ERROR = (
|
|
|
33
35
|
# BOOKMARK - export_bookmarks
|
|
34
36
|
# ------------------------------------------------------------------------------
|
|
35
37
|
BOOKMARK_EXPORT_BOOKMARK_ERROR = "[Bookmark] Failed to export bookmarks: {message}"
|
|
36
|
-
BOOKMARK_EXPORT_BOOKMARK_VALIDATION_ERROR =
|
|
38
|
+
BOOKMARK_EXPORT_BOOKMARK_VALIDATION_ERROR = (
|
|
39
|
+
"Export filename must be a non-empty string."
|
|
40
|
+
)
|
|
37
41
|
|
|
38
42
|
# ------------------------------------------------------------------------------
|
|
39
43
|
# BOOKMARK ARGUMENTS - from_tuple_to_dict
|
|
40
44
|
# ------------------------------------------------------------------------------
|
|
41
|
-
BOOKMARK_ARGUMENTS_FROM_TUPLE_TO_DICT_VALIDATION_ERROR = "[BookmarkArguments] Failed to convert to dictionary because of the insufficient number of values" # noqa: E501
|
|
45
|
+
BOOKMARK_ARGUMENTS_FROM_TUPLE_TO_DICT_VALIDATION_ERROR = "[BookmarkArguments] Failed to convert to dictionary because of the insufficient number of values." # noqa: E501
|
|
46
|
+
|
|
47
|
+
# ------------------------------------------------------------------------------
|
|
48
|
+
# CONNECTOR - perform_retry_callback
|
|
49
|
+
# ------------------------------------------------------------------------------
|
|
50
|
+
CONNECTOR_PERFORM_RETRY_CALLBACK_ERROR = "[Connector ID: {connector_id}] Attempt {attempt_no} failed due to error: {message}" # noqa: E501
|
|
51
|
+
|
|
52
|
+
# ------------------------------------------------------------------------------
|
|
53
|
+
# CONNECTOR - load
|
|
54
|
+
# ------------------------------------------------------------------------------
|
|
55
|
+
CONNECTOR_LOAD_CONNECTOR_ENDPOINT_ARGUMENTS_VALIDATION_ERROR = "[Connector] The 'ep_args' argument must be an instance of ConnectorEndpointArguments and not None." # noqa: E501
|
|
56
|
+
CONNECTOR_LOAD_CONNECTOR_INSTANCE_RUNTIME_ERROR = (
|
|
57
|
+
"[Connector] Failed to get connector instance: {message}"
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
# ------------------------------------------------------------------------------
|
|
61
|
+
# CONNECTOR - create
|
|
62
|
+
# ------------------------------------------------------------------------------
|
|
63
|
+
CONNECTOR_CREATE_CONNECTOR_ENDPOINT_ARGUMENTS_VALIDATION_ERROR = "[Connector] The 'ep_args' argument must be an instance of ConnectorEndpointArguments and not None." # noqa: E501
|
|
64
|
+
CONNECTOR_CREATE_ERROR = "[Connector] Failed to create connector: {message}"
|
|
65
|
+
|
|
66
|
+
# ------------------------------------------------------------------------------
|
|
67
|
+
# CONNECTOR - get_available_items
|
|
68
|
+
# ------------------------------------------------------------------------------
|
|
69
|
+
CONNECTOR_GET_AVAILABLE_ITEMS_ERROR = (
|
|
70
|
+
"[Connector] Failed to get available connectors: {message}"
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# ------------------------------------------------------------------------------
|
|
74
|
+
# CONNECTOR - get_prediction
|
|
75
|
+
# ------------------------------------------------------------------------------
|
|
76
|
+
CONNECTOR_GET_PREDICTION_ARGUMENTS_GENERATED_PROMPT_VALIDATION_ERROR = "[Connector] The 'generated_prompt' argument must be an instance of ConnectorPromptArguments and not None." # noqa: E501
|
|
77
|
+
CONNECTOR_GET_PREDICTION_ARGUMENTS_CONNECTOR_VALIDATION_ERROR = "[Connector] The 'connector' argument must be an instance of Connector and not None." # noqa: E501
|
|
78
|
+
CONNECTOR_GET_PREDICTION_INFO = (
|
|
79
|
+
"[Connector ID: {connector_id}] Predicting Prompt Index {prompt_index}."
|
|
80
|
+
)
|
|
81
|
+
CONNECTOR_GET_PREDICTION_TIME_TAKEN_INFO = "[Connector ID: {connector_id}] Prompt Index {prompt_index} took {prompt_duration}s." # noqa: E501
|
|
82
|
+
CONNECTOR_GET_PREDICTION_ERROR = "[Connector ID: {connector_id}] Prompt Index {prompt_index} failed to get prediction: {message}" # noqa: E501
|
|
83
|
+
|
|
84
|
+
# ------------------------------------------------------------------------------
|
|
85
|
+
# CONNECTOR - set_system_prompt
|
|
86
|
+
# ------------------------------------------------------------------------------
|
|
87
|
+
CONNECTOR_SET_SYSTEM_PROMPT_VALIDATION_ERROR = "[Connector] The 'system_prompt' argument must be an instance of string and not None." # noqa: E501
|
|
88
|
+
|
|
89
|
+
# ------------------------------------------------------------------------------
|
|
90
|
+
# CONNECTOR ENDPOINT - create
|
|
91
|
+
# ------------------------------------------------------------------------------
|
|
92
|
+
CONNECTOR_ENDPOINT_CREATE_ERROR = (
|
|
93
|
+
"[ConnectorEndpoint] Failed to create connector endpoint: {message}"
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# ------------------------------------------------------------------------------
|
|
97
|
+
# CONNECTOR ENDPOINT - read
|
|
98
|
+
# ------------------------------------------------------------------------------
|
|
99
|
+
CONNECTOR_ENDPOINT_READ_INVALID = "Invalid connector endpoint id - {ep_id}"
|
|
100
|
+
CONNECTOR_ENDPOINT_READ_ERROR = (
|
|
101
|
+
"[ConnectorEndpoint] Failed to read connector endpoint: {message}"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# ------------------------------------------------------------------------------
|
|
105
|
+
# CONNECTOR ENDPOINT - update
|
|
106
|
+
# ------------------------------------------------------------------------------
|
|
107
|
+
CONNECTOR_ENDPOINT_UPDATE_ERROR = (
|
|
108
|
+
"[ConnectorEndpoint] Failed to update connector endpoint: {message}"
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
# ------------------------------------------------------------------------------
|
|
112
|
+
# CONNECTOR ENDPOINT - delete
|
|
113
|
+
# ------------------------------------------------------------------------------
|
|
114
|
+
CONNECTOR_ENDPOINT_DELETE_ERROR = (
|
|
115
|
+
"[ConnectorEndpoint] Failed to delete connector endpoint: {message}"
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# ------------------------------------------------------------------------------
|
|
119
|
+
# CONNECTOR ENDPOINT - get_available_items
|
|
120
|
+
# ------------------------------------------------------------------------------
|
|
121
|
+
CONNECTOR_ENDPOINT_GET_AVAILABLE_ITEMS_ERROR = (
|
|
122
|
+
"[ConnectorEndpoint] Failed to get available connector endpoints: {message}"
|
|
123
|
+
)
|
{aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.0.dist-info}/licenses/AUTHORS.md
RENAMED
|
File without changes
|
{aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.0.dist-info}/licenses/LICENSE.md
RENAMED
|
File without changes
|
{aiverify_moonshot-0.4.11.dist-info → aiverify_moonshot-0.5.0.dist-info}/licenses/NOTICES.md
RENAMED
|
File without changes
|