mostlyai 0.4.3__tar.gz → 0.4.4__tar.gz
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.
- {mostlyai-0.4.3 → mostlyai-0.4.4}/PKG-INFO +7 -1
- {mostlyai-0.4.3 → mostlyai-0.4.4}/README.md +4 -0
- {mostlyai-0.4.3 → mostlyai-0.4.4}/mostlyai/__init__.py +1 -1
- {mostlyai-0.4.3 → mostlyai-0.4.4}/mostlyai/base.py +15 -6
- {mostlyai-0.4.3 → mostlyai-0.4.4}/mostlyai/generators.py +9 -0
- {mostlyai-0.4.3 → mostlyai-0.4.4}/mostlyai/model.py +16 -2
- mostlyai-0.4.4/mostlyai/naming_conventions.py +39 -0
- {mostlyai-0.4.3 → mostlyai-0.4.4}/mostlyai/shares.py +2 -2
- {mostlyai-0.4.3 → mostlyai-0.4.4}/mostlyai/utils.py +28 -23
- {mostlyai-0.4.3 → mostlyai-0.4.4}/pyproject.toml +6 -1
- {mostlyai-0.4.3 → mostlyai-0.4.4}/LICENSE +0 -0
- {mostlyai-0.4.3 → mostlyai-0.4.4}/mostlyai/api.py +0 -0
- {mostlyai-0.4.3 → mostlyai-0.4.4}/mostlyai/connectors.py +0 -0
- {mostlyai-0.4.3 → mostlyai-0.4.4}/mostlyai/exceptions.py +0 -0
- {mostlyai-0.4.3 → mostlyai-0.4.4}/mostlyai/synthetic_datasets.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mostlyai
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: The official Python client for the MOSTLY AI platform.
|
|
5
5
|
Home-page: https://app.mostly.ai/
|
|
6
6
|
License: Proprietary
|
|
@@ -18,6 +18,8 @@ Requires-Dist: pandas (>=1.5.3,<3.0.0)
|
|
|
18
18
|
Requires-Dist: pyarrow (>=14.0.0)
|
|
19
19
|
Requires-Dist: pydantic (>=2.4.2,<3.0.0)
|
|
20
20
|
Requires-Dist: rich (>=13.7.0)
|
|
21
|
+
Project-URL: Documentation, https://mostly-ai.github.io/mostly-python/
|
|
22
|
+
Project-URL: Source, https://github.com/mostly-ai/mostly-python
|
|
21
23
|
Description-Content-Type: text/markdown
|
|
22
24
|
|
|
23
25
|
# MOSTLY AI - GenAI for Tabular Data
|
|
@@ -97,6 +99,10 @@ g.training.wait()
|
|
|
97
99
|
# import / export
|
|
98
100
|
g.export_to_file(file_path)
|
|
99
101
|
mostly.generators.import_from_file(file_path)
|
|
102
|
+
|
|
103
|
+
# clone
|
|
104
|
+
cloned_g = g.clone(training_status="NEW") # clone the generator for new training
|
|
105
|
+
cloned_g = g.clone(training_status="CONTINUE") # clone the generator and reuse its weights for continued training
|
|
100
106
|
```
|
|
101
107
|
|
|
102
108
|
### Synthetic Datasets
|
|
@@ -75,6 +75,10 @@ g.training.wait()
|
|
|
75
75
|
# import / export
|
|
76
76
|
g.export_to_file(file_path)
|
|
77
77
|
mostly.generators.import_from_file(file_path)
|
|
78
|
+
|
|
79
|
+
# clone
|
|
80
|
+
cloned_g = g.clone(training_status="NEW") # clone the generator for new training
|
|
81
|
+
cloned_g = g.clone(training_status="CONTINUE") # clone the generator and reuse its weights for continued training
|
|
78
82
|
```
|
|
79
83
|
|
|
80
84
|
### Synthetic Datasets
|
|
@@ -20,6 +20,11 @@ from pydantic import BaseModel, ConfigDict, Field
|
|
|
20
20
|
from rich.console import Console
|
|
21
21
|
|
|
22
22
|
from mostlyai.exceptions import APIError, APIStatusError
|
|
23
|
+
from mostlyai.naming_conventions import (
|
|
24
|
+
snake_to_camel,
|
|
25
|
+
map_snake_to_camel_case,
|
|
26
|
+
map_camel_to_snake_case,
|
|
27
|
+
)
|
|
23
28
|
|
|
24
29
|
GET = "GET"
|
|
25
30
|
POST = "POST"
|
|
@@ -73,6 +78,8 @@ class _MostlyBaseClient:
|
|
|
73
78
|
response_type: type = dict,
|
|
74
79
|
raw_response: bool = False,
|
|
75
80
|
is_api_call: bool = True,
|
|
81
|
+
do_json_camel_case: bool = True,
|
|
82
|
+
do_response_dict_snake_case: bool = True,
|
|
76
83
|
do_include_client: bool = True,
|
|
77
84
|
extra_key_values: Optional[dict] = None,
|
|
78
85
|
**kwargs,
|
|
@@ -88,6 +95,8 @@ class _MostlyBaseClient:
|
|
|
88
95
|
:param response_type: a specific type to return (e.g. Pydantic class)
|
|
89
96
|
:param raw_response: whether to just return a raw response (e.g. content)
|
|
90
97
|
:param is_api_call: True by default; if False, API_SECTION and SECTION won't be prefixed
|
|
98
|
+
:param do_json_camel_case: ensure a provided json follows camelCase conventions
|
|
99
|
+
:param do_response_dict_snake_case: ensure the returned dict follows snake_case conventions
|
|
91
100
|
:param do_include_client: True by default; if True, client property will be included in the returned instance
|
|
92
101
|
:param extra_key_values: Any extra information storage to include in the returned object
|
|
93
102
|
:param kwargs: httpx's request function's kwargs
|
|
@@ -105,6 +114,9 @@ class _MostlyBaseClient:
|
|
|
105
114
|
f"The overall {request_size=} exceeds {MAX_REQUEST_SIZE}.", UserWarning
|
|
106
115
|
)
|
|
107
116
|
|
|
117
|
+
if "json" in kwargs and do_json_camel_case:
|
|
118
|
+
kwargs["json"] = map_snake_to_camel_case(kwargs["json"])
|
|
119
|
+
|
|
108
120
|
try:
|
|
109
121
|
with httpx.Client(timeout=self.timeout, verify=self.ssl_verify) as client:
|
|
110
122
|
response = client.request(method=verb, url=full_url, **kwargs)
|
|
@@ -135,6 +147,8 @@ class _MostlyBaseClient:
|
|
|
135
147
|
response_json["client"] = self
|
|
136
148
|
if isinstance(extra_key_values, dict):
|
|
137
149
|
response_json["extra_key_values"] = extra_key_values
|
|
150
|
+
elif response_type == dict and do_response_dict_snake_case:
|
|
151
|
+
response_json = map_camel_to_snake_case(response_json)
|
|
138
152
|
return (
|
|
139
153
|
response_type(**response_json)
|
|
140
154
|
if isinstance(response_json, dict)
|
|
@@ -157,7 +171,7 @@ class Paginator(Generic[T]):
|
|
|
157
171
|
self.object_class = object_class
|
|
158
172
|
self.offset = kwargs.pop("offset", 0)
|
|
159
173
|
self.limit = kwargs.pop("limit", 50)
|
|
160
|
-
self.params = {
|
|
174
|
+
self.params = {snake_to_camel(k): v for k, v in kwargs.items()}
|
|
161
175
|
self.current_items = []
|
|
162
176
|
self.current_index = 0
|
|
163
177
|
self.is_last_page = False
|
|
@@ -233,11 +247,6 @@ class CustomBaseModel(BaseModel):
|
|
|
233
247
|
setattr(self, key, value)
|
|
234
248
|
|
|
235
249
|
|
|
236
|
-
def _snake_to_camel(snake_str: str) -> str:
|
|
237
|
-
components = snake_str.split("_")
|
|
238
|
-
return components[0] + "".join(x.title() for x in components[1:])
|
|
239
|
-
|
|
240
|
-
|
|
241
250
|
def _get_total_size(obj, seen=None):
|
|
242
251
|
"""Recursively finds size of objects in bytes."""
|
|
243
252
|
size = sys.getsizeof(obj)
|
|
@@ -143,6 +143,15 @@ class _MostlyGeneratorsClient(_MostlyBaseClient, _MostlySharesMixin):
|
|
|
143
143
|
response = self.request(verb=DELETE, path=[generator_id])
|
|
144
144
|
return response
|
|
145
145
|
|
|
146
|
+
def _clone(self, generator_id: str, training_status: str) -> Generator:
|
|
147
|
+
response = self.request(
|
|
148
|
+
verb=POST,
|
|
149
|
+
path=[generator_id, "clone"],
|
|
150
|
+
json={"trainingStatus": training_status},
|
|
151
|
+
response_type=Generator,
|
|
152
|
+
)
|
|
153
|
+
return response
|
|
154
|
+
|
|
146
155
|
def _config(self, generator_id: str) -> Generator:
|
|
147
156
|
response = self.request(verb=GET, path=[generator_id, "config"])
|
|
148
157
|
return response
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# generated by datamodel-codegen:
|
|
2
|
-
# timestamp: 2024-10-
|
|
2
|
+
# timestamp: 2024-10-21T10:19:52+00:00
|
|
3
3
|
|
|
4
4
|
from __future__ import annotations
|
|
5
5
|
|
|
@@ -617,6 +617,7 @@ class ProgressStatus(str, Enum):
|
|
|
617
617
|
"""
|
|
618
618
|
The status of a job or a step.
|
|
619
619
|
NEW: The job/step is being configured, and has not started yet
|
|
620
|
+
CONTINUE: The job/step is being configured, but has existing artefacts
|
|
620
621
|
ON_HOLD: The job/step has been started, but is kept on hold
|
|
621
622
|
QUEUED: The job/step has been started, and is awaiting for resources to execute
|
|
622
623
|
IN_PROGRESS: The job/step is currently running
|
|
@@ -627,6 +628,7 @@ class ProgressStatus(str, Enum):
|
|
|
627
628
|
"""
|
|
628
629
|
|
|
629
630
|
new = "NEW"
|
|
631
|
+
continue_ = "CONTINUE"
|
|
630
632
|
on_hold = "ON_HOLD"
|
|
631
633
|
queued = "QUEUED"
|
|
632
634
|
in_progress = "IN_PROGRESS"
|
|
@@ -1163,7 +1165,6 @@ class ModelConfiguration(CustomBaseModel):
|
|
|
1163
1165
|
"MOSTLY_AI/Large",
|
|
1164
1166
|
"MOSTLY_AI/LSTMFromScratch-3m",
|
|
1165
1167
|
"microsoft/phi-1_5",
|
|
1166
|
-
"Locutusque/TinyMistral-248M",
|
|
1167
1168
|
]
|
|
1168
1169
|
],
|
|
1169
1170
|
),
|
|
@@ -1794,6 +1795,19 @@ class Generator(CustomBaseModel):
|
|
|
1794
1795
|
file_path.write_bytes(bytes)
|
|
1795
1796
|
return file_path
|
|
1796
1797
|
|
|
1798
|
+
def clone(self, training_status: Literal["NEW", "CONTINUE"] = "NEW") -> "Generator":
|
|
1799
|
+
"""
|
|
1800
|
+
Create a new generator, re-using existing data and model configurations. By setting trainingStatus
|
|
1801
|
+
to CONTINUE, the model weights are copied as well, and training will continue from there. Note, that
|
|
1802
|
+
in that case, only the training parameters (maxSampleSize, maxEpochs, batchSize, compute, etc.) of
|
|
1803
|
+
the model configuration can still be modified. Other configurations, like columns, model, and
|
|
1804
|
+
valueProtection cannot be changed anymore, as these would break compatibility with the existing model
|
|
1805
|
+
weights.
|
|
1806
|
+
|
|
1807
|
+
:param training_status: The training status of the new generator.
|
|
1808
|
+
"""
|
|
1809
|
+
return self.client._clone(generator_id=self.id, training_status=training_status)
|
|
1810
|
+
|
|
1797
1811
|
class Training:
|
|
1798
1812
|
def __init__(self, _generator: "Generator"):
|
|
1799
1813
|
self.generator = _generator
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from typing import Callable
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def snake_to_camel(snake_str: str) -> str:
|
|
6
|
+
components = snake_str.split("_")
|
|
7
|
+
return components[0] + "".join(x.title() for x in components[1:])
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def camel_to_snake(camel_str: str) -> str:
|
|
11
|
+
return re.sub(r"(?<!^)(?=[A-Z])", "_", camel_str).lower()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def convert_case(input_data: dict, conv_func: Callable[[str], str]) -> dict:
|
|
15
|
+
if not isinstance(input_data, dict):
|
|
16
|
+
return input_data
|
|
17
|
+
|
|
18
|
+
new_dict = {}
|
|
19
|
+
for key, value in input_data.items():
|
|
20
|
+
new_key = conv_func(key)
|
|
21
|
+
# recursively convert nested dictionaries or lists
|
|
22
|
+
if isinstance(value, dict):
|
|
23
|
+
new_dict[new_key] = convert_case(value, conv_func)
|
|
24
|
+
elif isinstance(value, list):
|
|
25
|
+
new_dict[new_key] = [
|
|
26
|
+
convert_case(item, conv_func) if isinstance(item, dict) else item
|
|
27
|
+
for item in value
|
|
28
|
+
]
|
|
29
|
+
else:
|
|
30
|
+
new_dict[new_key] = value
|
|
31
|
+
return new_dict
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def map_snake_to_camel_case(input_dict: dict) -> dict:
|
|
35
|
+
return convert_case(input_dict, snake_to_camel)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def map_camel_to_snake_case(input_dict: dict) -> dict:
|
|
39
|
+
return convert_case(input_dict, camel_to_snake)
|
|
@@ -31,12 +31,12 @@ class _MostlySharesClient(_MostlyBaseClient):
|
|
|
31
31
|
user_email: str,
|
|
32
32
|
permission_level: PermissionLevel,
|
|
33
33
|
):
|
|
34
|
-
config = {"
|
|
34
|
+
config = {"user_email": user_email, "permission_level": permission_level}
|
|
35
35
|
resource_type = self.RESOURCE_TYPE.get(type(resource))
|
|
36
36
|
self.request(verb=POST, path=[resource_type, resource.id], json=config)
|
|
37
37
|
|
|
38
38
|
def _unshare(self, resource: ShareableResource, user_email: str):
|
|
39
|
-
config = {"
|
|
39
|
+
config = {"user_email": user_email}
|
|
40
40
|
resource_type = self.RESOURCE_TYPE.get(type(resource))
|
|
41
41
|
self.request(verb=DELETE, path=[resource_type, resource.id], json=config)
|
|
42
42
|
|
|
@@ -23,6 +23,7 @@ from mostlyai.model import (
|
|
|
23
23
|
StepCode,
|
|
24
24
|
SyntheticDataset,
|
|
25
25
|
)
|
|
26
|
+
from mostlyai.naming_conventions import map_camel_to_snake_case
|
|
26
27
|
|
|
27
28
|
warnings.simplefilter("always", DeprecationWarning)
|
|
28
29
|
|
|
@@ -173,13 +174,15 @@ def _harmonize_sd_config(
|
|
|
173
174
|
size = size if size is not None else {}
|
|
174
175
|
seed = seed if seed is not None else {}
|
|
175
176
|
|
|
177
|
+
config = map_camel_to_snake_case(config)
|
|
178
|
+
|
|
176
179
|
if isinstance(generator, Generator):
|
|
177
180
|
generator_id = str(generator.id)
|
|
178
181
|
elif generator is not None:
|
|
179
182
|
generator_id = str(generator)
|
|
180
|
-
elif "
|
|
183
|
+
elif "generator_id" not in config:
|
|
181
184
|
raise ValueError(
|
|
182
|
-
"Either a generator or a configuration with a
|
|
185
|
+
"Either a generator or a configuration with a generator_id must be provided."
|
|
183
186
|
)
|
|
184
187
|
|
|
185
188
|
if (
|
|
@@ -193,8 +196,8 @@ def _harmonize_sd_config(
|
|
|
193
196
|
else:
|
|
194
197
|
subject_tables = []
|
|
195
198
|
|
|
196
|
-
# insert
|
|
197
|
-
config["
|
|
199
|
+
# insert generator_id into config
|
|
200
|
+
config["generator_id"] = generator_id
|
|
198
201
|
|
|
199
202
|
# normalize size
|
|
200
203
|
if not isinstance(size, dict):
|
|
@@ -213,18 +216,18 @@ def _harmonize_sd_config(
|
|
|
213
216
|
config["tables"] = []
|
|
214
217
|
for table in generator.tables:
|
|
215
218
|
configuration = {
|
|
216
|
-
"
|
|
217
|
-
"
|
|
218
|
-
"
|
|
219
|
+
"sample_size": None,
|
|
220
|
+
"sample_seed_data": None,
|
|
221
|
+
"sample_seed_dict": None,
|
|
219
222
|
}
|
|
220
223
|
if table.name in subject_tables:
|
|
221
|
-
configuration["
|
|
222
|
-
configuration["
|
|
224
|
+
configuration["sample_size"] = size.get(table.name)
|
|
225
|
+
configuration["sample_seed_data"] = (
|
|
223
226
|
seed.get(table.name)
|
|
224
227
|
if not isinstance(seed.get(table.name), list)
|
|
225
228
|
else None
|
|
226
229
|
)
|
|
227
|
-
configuration["
|
|
230
|
+
configuration["sample_seed_dict"] = (
|
|
228
231
|
seed.get(table.name)
|
|
229
232
|
if isinstance(seed.get(table.name), list)
|
|
230
233
|
else None
|
|
@@ -238,25 +241,27 @@ def _harmonize_sd_config(
|
|
|
238
241
|
tables = config["tables"] if "tables" in config else []
|
|
239
242
|
for table in tables:
|
|
240
243
|
if (
|
|
241
|
-
"
|
|
242
|
-
and table["configuration"]["
|
|
244
|
+
"sample_seed_data" in table["configuration"]
|
|
245
|
+
and table["configuration"]["sample_seed_data"] is not None
|
|
243
246
|
):
|
|
244
|
-
if isinstance(table["configuration"]["
|
|
245
|
-
table["configuration"]["
|
|
246
|
-
table["configuration"]["
|
|
247
|
+
if isinstance(table["configuration"]["sample_seed_data"], pd.DataFrame):
|
|
248
|
+
table["configuration"]["sample_seed_data"] = _convert_to_base64(
|
|
249
|
+
table["configuration"]["sample_seed_data"]
|
|
250
|
+
)
|
|
251
|
+
elif isinstance(table["configuration"]["sample_seed_data"], (Path, str)):
|
|
252
|
+
_, df = _read_table_from_path(
|
|
253
|
+
table["configuration"]["sample_seed_data"]
|
|
247
254
|
)
|
|
248
|
-
|
|
249
|
-
_, df = _read_table_from_path(table["configuration"]["sampleSeedData"])
|
|
250
|
-
table["configuration"]["sampleSeedData"] = _convert_to_base64(df)
|
|
255
|
+
table["configuration"]["sample_seed_data"] = _convert_to_base64(df)
|
|
251
256
|
del df
|
|
252
257
|
else:
|
|
253
|
-
raise ValueError("
|
|
258
|
+
raise ValueError("sample_seed_data must be a DataFrame or a file path")
|
|
254
259
|
if (
|
|
255
|
-
"
|
|
256
|
-
and table["configuration"]["
|
|
260
|
+
"sample_seed_dict" in table["configuration"]
|
|
261
|
+
and table["configuration"]["sample_seed_dict"] is not None
|
|
257
262
|
):
|
|
258
|
-
table["configuration"]["
|
|
259
|
-
table["configuration"]["
|
|
263
|
+
table["configuration"]["sample_seed_dict"] = _convert_to_base64(
|
|
264
|
+
table["configuration"]["sample_seed_dict"], format="jsonl"
|
|
260
265
|
)
|
|
261
266
|
|
|
262
267
|
return config
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "mostlyai"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.4"
|
|
4
4
|
description = "The official Python client for the MOSTLY AI platform."
|
|
5
5
|
homepage = "https://app.mostly.ai/"
|
|
6
6
|
authors = ["MOSTLY AI <office@mostly.ai>"]
|
|
@@ -11,6 +11,11 @@ packages = [
|
|
|
11
11
|
]
|
|
12
12
|
exclude = ["tools/", "tools/**/*"]
|
|
13
13
|
|
|
14
|
+
[tool.poetry.urls]
|
|
15
|
+
"Homepage" = "https://app.mostly.ai/"
|
|
16
|
+
"Documentation" = "https://mostly-ai.github.io/mostly-python/"
|
|
17
|
+
"Source" = "https://github.com/mostly-ai/mostly-python"
|
|
18
|
+
|
|
14
19
|
[tool.poetry.dependencies]
|
|
15
20
|
python = "^3.9"
|
|
16
21
|
pydantic = "^2.4.2"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|