aiverify-moonshot 0.4.8__py3-none-any.whl → 0.4.9__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.8.dist-info → aiverify_moonshot-0.4.9.dist-info}/METADATA +3 -3
- {aiverify_moonshot-0.4.8.dist-info → aiverify_moonshot-0.4.9.dist-info}/RECORD +29 -29
- {aiverify_moonshot-0.4.8.dist-info → aiverify_moonshot-0.4.9.dist-info}/licenses/LICENSE.md +1 -1
- moonshot/__main__.py +93 -49
- moonshot/api.py +12 -10
- moonshot/integrations/cli/benchmark/metrics.py +8 -2
- moonshot/integrations/cli/cli_errors.py +14 -0
- moonshot/integrations/cli/common/common.py +14 -8
- moonshot/integrations/cli/common/dataset.py +303 -65
- moonshot/integrations/cli/redteam/attack_module.py +30 -1
- moonshot/integrations/web_api/app.py +1 -1
- moonshot/integrations/web_api/routes/dataset.py +52 -18
- moonshot/integrations/web_api/schemas/cookbook_response_model.py +2 -0
- moonshot/integrations/web_api/schemas/dataset_create_dto.py +14 -4
- moonshot/integrations/web_api/schemas/recipe_response_model.py +1 -0
- moonshot/integrations/web_api/services/cookbook_service.py +36 -9
- moonshot/integrations/web_api/services/dataset_service.py +34 -9
- moonshot/integrations/web_api/services/recipe_service.py +33 -3
- moonshot/src/api/api_dataset.py +43 -11
- moonshot/src/bookmark/bookmark.py +16 -9
- moonshot/src/datasets/dataset.py +37 -45
- moonshot/src/datasets/dataset_arguments.py +2 -1
- moonshot/src/messages_constants.py +1 -0
- moonshot/src/redteaming/attack/attack_module.py +40 -0
- moonshot/src/storage/io_interface.py +18 -1
- moonshot/src/storage/storage.py +57 -1
- {aiverify_moonshot-0.4.8.dist-info → aiverify_moonshot-0.4.9.dist-info}/WHEEL +0 -0
- {aiverify_moonshot-0.4.8.dist-info → aiverify_moonshot-0.4.9.dist-info}/licenses/AUTHORS.md +0 -0
- {aiverify_moonshot-0.4.8.dist-info → aiverify_moonshot-0.4.9.dist-info}/licenses/NOTICES.md +0 -0
moonshot/src/storage/storage.py
CHANGED
|
@@ -6,13 +6,17 @@ from pathlib import Path
|
|
|
6
6
|
from typing import Iterator
|
|
7
7
|
|
|
8
8
|
import xxhash
|
|
9
|
-
from pydantic import validate_call
|
|
9
|
+
from pydantic import ConfigDict, validate_call
|
|
10
10
|
|
|
11
11
|
from moonshot.src.configs.env_variables import EnvironmentVars, EnvVariables
|
|
12
12
|
from moonshot.src.storage.db_interface import DBInterface
|
|
13
13
|
from moonshot.src.utils.import_modules import get_instance
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
class Config:
|
|
17
|
+
config_dict = ConfigDict(arbitrary_types_allowed=True)
|
|
18
|
+
|
|
19
|
+
|
|
16
20
|
class Storage:
|
|
17
21
|
@staticmethod
|
|
18
22
|
@validate_call
|
|
@@ -60,6 +64,58 @@ class Storage:
|
|
|
60
64
|
else:
|
|
61
65
|
raise RuntimeError("Unable to create object.")
|
|
62
66
|
|
|
67
|
+
@staticmethod
|
|
68
|
+
@validate_call(config=Config.config_dict)
|
|
69
|
+
def create_object_with_iterator(
|
|
70
|
+
obj_type: str,
|
|
71
|
+
obj_id: str,
|
|
72
|
+
obj_info: dict,
|
|
73
|
+
obj_extension: str,
|
|
74
|
+
obj_mod_type: str = "jsonio",
|
|
75
|
+
iterator_keys: list[str] | None = None,
|
|
76
|
+
iterator_data: Iterator[dict] | None = None,
|
|
77
|
+
) -> str:
|
|
78
|
+
"""
|
|
79
|
+
Writes the object information to a file using iterators for specified keys.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
obj_type (str): The type of the object (e.g., 'recipe', 'cookbook').
|
|
83
|
+
obj_id (str): The ID of the object.
|
|
84
|
+
obj_info (dict): A dictionary containing the object information.
|
|
85
|
+
obj_extension (str): The file extension (e.g., 'json', 'py').
|
|
86
|
+
obj_mod_type (str, optional): The module type for object serialization. Defaults to 'jsonio'.
|
|
87
|
+
iterator_keys (list[str] | None): A list of keys for which the values will be written using iterators.
|
|
88
|
+
iterator_data (Iterator[dict] | None): An iterator for the data to be written for the specified keys.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
str: A filepath string of the object that has just been created.
|
|
92
|
+
"""
|
|
93
|
+
if not hasattr(EnvironmentVars, obj_type):
|
|
94
|
+
raise RuntimeError(
|
|
95
|
+
f"'{obj_type}' is not a recognized EnvironmentVar value."
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
obj_filepath = Storage.get_filepath(obj_type, obj_id, obj_extension, True)
|
|
99
|
+
if not obj_filepath or not isinstance(obj_filepath, str):
|
|
100
|
+
raise RuntimeError("Unable to create object.")
|
|
101
|
+
|
|
102
|
+
obj_mod_instance = get_instance(
|
|
103
|
+
obj_mod_type,
|
|
104
|
+
Storage.get_filepath(EnvVariables.IO_MODULES.name, obj_mod_type, "py"),
|
|
105
|
+
)
|
|
106
|
+
if not obj_mod_instance or not callable(obj_mod_instance):
|
|
107
|
+
raise RuntimeError(
|
|
108
|
+
f"Unable to get defined object module instance - {obj_mod_instance}"
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
try:
|
|
112
|
+
obj_mod_instance(obj_filepath).create_file_with_iterator(
|
|
113
|
+
obj_info, iterator_keys, iterator_data
|
|
114
|
+
)
|
|
115
|
+
return obj_filepath
|
|
116
|
+
except Exception as e:
|
|
117
|
+
raise e
|
|
118
|
+
|
|
63
119
|
@staticmethod
|
|
64
120
|
@validate_call
|
|
65
121
|
def read_object_with_iterator(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|