mostlyai 4.8.2__tar.gz → 4.8.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-4.8.2 → mostlyai-4.8.4}/PKG-INFO +4 -4
- {mostlyai-4.8.2 → mostlyai-4.8.4}/README.md +1 -1
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/__init__.py +1 -1
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/base.py +8 -3
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/pull.py +1 -2
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/pull_context.py +2 -2
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/pull_utils.py +1 -10
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_finalize_generation.py +3 -1
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/routes.py +96 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/storage.py +12 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/client/_base_utils.py +1 -1
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/client/api.py +2 -0
- mostlyai-4.8.4/mostlyai/sdk/client/datasets.py +236 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/client/generators.py +3 -3
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/client/synthetic_datasets.py +5 -3
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/domain.py +160 -6
- {mostlyai-4.8.2 → mostlyai-4.8.4}/pyproject.toml +3 -3
- {mostlyai-4.8.2 → mostlyai-4.8.4}/.gitignore +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/LICENSE +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/__init__.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/auto_detect.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/context.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/conversions.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/db/__init__.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/db/base.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/db/bigquery.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/db/databricks.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/db/hive.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/db/mssql.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/db/mysql.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/db/oracle.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/db/postgresql.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/db/snowflake.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/db/sqlite.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/db/types_coercion.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/dtype.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/exceptions.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/__init__.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/base.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/container/__init__.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/container/aws.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/container/azure.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/container/bucket_based.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/container/gcs.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/container/minio.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/table/__init__.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/table/csv.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/table/feather.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/table/json.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/table/parquet.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/file/utils.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/language_model.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/metadata_objects.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/non_context.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/progress_callback.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/push.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/util/__init__.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/util/common.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_data/util/kerberos.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/__init__.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/cli.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/connectors.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/__init__.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/jobs.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/migration.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/plan.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_analyze_training_data.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_create_data_report.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_create_model_report.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_deliver_data.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_encode_training_data.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_finalize_training.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_generate_data.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_generate_model_report_data.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_pull_training_data.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_train_model.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/generators.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/progress.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/server.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/synthetic_datasets.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/client/__init__.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/client/_naming_conventions.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/client/_utils.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/client/base.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/client/connectors.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/client/exceptions.py +0 -0
- {mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mostlyai
|
|
3
|
-
Version: 4.8.
|
|
3
|
+
Version: 4.8.4
|
|
4
4
|
Summary: Synthetic Data SDK
|
|
5
5
|
Project-URL: homepage, https://app.mostly.ai/
|
|
6
6
|
Project-URL: repository, https://github.com/mostly-ai/mostlyai
|
|
@@ -59,7 +59,7 @@ Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local'
|
|
|
59
59
|
Requires-Dist: filelock>=3.16.1; extra == 'local'
|
|
60
60
|
Requires-Dist: gcsfs>=2023.1.0; extra == 'local'
|
|
61
61
|
Requires-Dist: joblib>=1.4.2; extra == 'local'
|
|
62
|
-
Requires-Dist: mostlyai-engine==1.4.
|
|
62
|
+
Requires-Dist: mostlyai-engine==1.4.8; extra == 'local'
|
|
63
63
|
Requires-Dist: mostlyai-qa==1.9.8; extra == 'local'
|
|
64
64
|
Requires-Dist: networkx<4,>=3.0; extra == 'local'
|
|
65
65
|
Requires-Dist: openpyxl>=3.1.5; extra == 'local'
|
|
@@ -81,7 +81,7 @@ Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-gpu'
|
|
|
81
81
|
Requires-Dist: filelock>=3.16.1; extra == 'local-gpu'
|
|
82
82
|
Requires-Dist: gcsfs>=2023.1.0; extra == 'local-gpu'
|
|
83
83
|
Requires-Dist: joblib>=1.4.2; extra == 'local-gpu'
|
|
84
|
-
Requires-Dist: mostlyai-engine[gpu]==1.4.
|
|
84
|
+
Requires-Dist: mostlyai-engine[gpu]==1.4.8; extra == 'local-gpu'
|
|
85
85
|
Requires-Dist: mostlyai-qa==1.9.8; extra == 'local-gpu'
|
|
86
86
|
Requires-Dist: networkx<4,>=3.0; extra == 'local-gpu'
|
|
87
87
|
Requires-Dist: openpyxl>=3.1.5; extra == 'local-gpu'
|
|
@@ -193,7 +193,7 @@ df = mostly.probe(g, size=1000)
|
|
|
193
193
|
df
|
|
194
194
|
```
|
|
195
195
|
|
|
196
|
-
Generate synthetic
|
|
196
|
+
Generate synthetic samples based on fixed column values:
|
|
197
197
|
|
|
198
198
|
```python
|
|
199
199
|
# create 10k records of 24y male respondents
|
|
@@ -258,7 +258,7 @@ class Schema:
|
|
|
258
258
|
relations = [rel for rel in relations if isinstance(rel, ContextRelation)]
|
|
259
259
|
return relations
|
|
260
260
|
|
|
261
|
-
def
|
|
261
|
+
def _update_key_encoding_types(self) -> None:
|
|
262
262
|
for tbl_name, tbl_table in self.tables.items():
|
|
263
263
|
if tbl_table.primary_key is not None:
|
|
264
264
|
if tbl_table.primary_key in tbl_table.encoding_types:
|
|
@@ -268,7 +268,7 @@ class Schema:
|
|
|
268
268
|
del tbl_table.encoding_types[rel.child.column]
|
|
269
269
|
self.tables[tbl_name] = tbl_table
|
|
270
270
|
|
|
271
|
-
def
|
|
271
|
+
def _resolve_auto_encoding_types(self) -> None:
|
|
272
272
|
for tbl_name, tbl_table in self.tables.items():
|
|
273
273
|
for col_name, encoding_type in tbl_table.encoding_types.items():
|
|
274
274
|
if encoding_type == ModelEncodingType.auto:
|
|
@@ -279,7 +279,7 @@ class Schema:
|
|
|
279
279
|
f"{promoted_enctype.value} for {tbl_name}.{col_name}"
|
|
280
280
|
)
|
|
281
281
|
|
|
282
|
-
def
|
|
282
|
+
def _remove_cascading_keys_relations(self):
|
|
283
283
|
tables_with_cascading_keys = set()
|
|
284
284
|
for table_name, table in self.tables.items():
|
|
285
285
|
primary_key = table.primary_key
|
|
@@ -297,6 +297,11 @@ class Schema:
|
|
|
297
297
|
if tables_with_cascading_keys:
|
|
298
298
|
_LOG.info(f"Removed cascading keys relations for tables: {tables_with_cascading_keys}")
|
|
299
299
|
|
|
300
|
+
def preprocess_schema_before_pull(self):
|
|
301
|
+
self._remove_cascading_keys_relations()
|
|
302
|
+
self._update_key_encoding_types()
|
|
303
|
+
self._resolve_auto_encoding_types()
|
|
304
|
+
|
|
300
305
|
@property
|
|
301
306
|
@functools.cache
|
|
302
307
|
def graph(self):
|
|
@@ -21,7 +21,6 @@ from mostlyai.sdk._data.base import Schema
|
|
|
21
21
|
from mostlyai.sdk._data.progress_callback import ProgressCallback, ProgressCallbackWrapper
|
|
22
22
|
from mostlyai.sdk._data.pull_utils import (
|
|
23
23
|
handle_workspace_dir,
|
|
24
|
-
prepare_schema,
|
|
25
24
|
pull_fetch,
|
|
26
25
|
pull_keys,
|
|
27
26
|
pull_split,
|
|
@@ -48,7 +47,7 @@ def pull(
|
|
|
48
47
|
model_type = ModelType(model_type)
|
|
49
48
|
if tgt not in schema.tables:
|
|
50
49
|
raise ValueError(f"table '{tgt}' not defined in schema")
|
|
51
|
-
|
|
50
|
+
schema.preprocess_schema_before_pull()
|
|
52
51
|
# gather context_tables
|
|
53
52
|
context_tables = schema.get_context_tables(tgt)
|
|
54
53
|
_LOG.info(f"context_tables (size: {len(context_tables)}): {context_tables}")
|
|
@@ -19,7 +19,7 @@ from typing import Any
|
|
|
19
19
|
|
|
20
20
|
from mostlyai.sdk._data.base import Schema
|
|
21
21
|
from mostlyai.sdk._data.progress_callback import ProgressCallbackWrapper
|
|
22
|
-
from mostlyai.sdk._data.pull_utils import handle_workspace_dir,
|
|
22
|
+
from mostlyai.sdk._data.pull_utils import handle_workspace_dir, pull_split
|
|
23
23
|
from mostlyai.sdk.domain import ModelType
|
|
24
24
|
|
|
25
25
|
_LOG = logging.getLogger(__name__)
|
|
@@ -38,7 +38,7 @@ def pull_context(
|
|
|
38
38
|
model_type = ModelType(model_type)
|
|
39
39
|
if tgt not in schema.tables:
|
|
40
40
|
raise ValueError(f"table '{tgt}' not defined in schema")
|
|
41
|
-
|
|
41
|
+
schema.preprocess_schema_before_pull()
|
|
42
42
|
# gather context_tables
|
|
43
43
|
context_tables = schema.get_context_tables(tgt)
|
|
44
44
|
_LOG.info(f"context_tables (size: {len(context_tables)}): {context_tables}")
|
|
@@ -642,7 +642,7 @@ def remake_schema_after_pull_fetch(tgt: str, schema: Schema, workspace_dir: Path
|
|
|
642
642
|
fs_table.encoding_types = table.encoding_types
|
|
643
643
|
tables[table_name] = fs_table
|
|
644
644
|
schema = Schema(tables=tables)
|
|
645
|
-
|
|
645
|
+
schema.preprocess_schema_before_pull()
|
|
646
646
|
return schema
|
|
647
647
|
|
|
648
648
|
|
|
@@ -1052,12 +1052,3 @@ def pull_split(
|
|
|
1052
1052
|
)
|
|
1053
1053
|
_LOG.info(f"meta exported in {time.time() - t0:.2f}s")
|
|
1054
1054
|
_LOG.info(f"BYE FROM PULL_SPLIT (total time: {time.time() - t00:.2f}s)")
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
def prepare_schema(schema: Schema):
|
|
1058
|
-
# update schema's relations to exclude unsupported cascading keys
|
|
1059
|
-
schema.remove_cascading_keys_relations()
|
|
1060
|
-
# update encoding_types for key columns, based on provided Schema
|
|
1061
|
-
schema.update_key_encoding_types()
|
|
1062
|
-
# resolve AUTO encoding types
|
|
1063
|
-
schema.resolve_auto_encoding_types()
|
|
@@ -37,10 +37,12 @@ from mostlyai.sdk._local.storage import (
|
|
|
37
37
|
create_zip_in_memory,
|
|
38
38
|
get_model_label,
|
|
39
39
|
read_connector_from_json,
|
|
40
|
+
read_dataset_from_json,
|
|
40
41
|
read_generator_from_json,
|
|
41
42
|
read_job_progress_from_json,
|
|
42
43
|
read_synthetic_dataset_from_json,
|
|
43
44
|
write_connector_to_json,
|
|
45
|
+
write_dataset_to_json,
|
|
44
46
|
write_generator_to_json,
|
|
45
47
|
write_synthetic_dataset_to_json,
|
|
46
48
|
)
|
|
@@ -56,6 +58,10 @@ from mostlyai.sdk.domain import (
|
|
|
56
58
|
ConnectorType,
|
|
57
59
|
ConnectorWriteDataConfig,
|
|
58
60
|
CurrentUser,
|
|
61
|
+
Dataset,
|
|
62
|
+
DatasetConfig,
|
|
63
|
+
DatasetListItem,
|
|
64
|
+
DatasetPatchConfig,
|
|
59
65
|
Generator,
|
|
60
66
|
GeneratorCloneConfig,
|
|
61
67
|
GeneratorCloneTrainingStatus,
|
|
@@ -289,6 +295,96 @@ class Routes:
|
|
|
289
295
|
background=BackgroundTask(Path(tmp_path).unlink, missing_ok=True),
|
|
290
296
|
)
|
|
291
297
|
|
|
298
|
+
## DATASETS
|
|
299
|
+
|
|
300
|
+
@self.router.get("/datasets")
|
|
301
|
+
async def list_datasets(
|
|
302
|
+
offset: int = 0,
|
|
303
|
+
limit: int = 50,
|
|
304
|
+
searchTerm: str | None = None,
|
|
305
|
+
) -> JSONResponse:
|
|
306
|
+
dataset_dirs = [p for p in (self.home_dir / "datasets").glob("*") if p.is_dir()]
|
|
307
|
+
dataset_list_items = []
|
|
308
|
+
for dataset_dir in dataset_dirs:
|
|
309
|
+
dataset = read_dataset_from_json(dataset_dir)
|
|
310
|
+
dataset_string = " ".join([dataset.name or "", dataset.description or ""]).lower()
|
|
311
|
+
if searchTerm and searchTerm.lower() not in dataset_string:
|
|
312
|
+
continue
|
|
313
|
+
# use model_construct to skip validation and warnings of extra fields
|
|
314
|
+
dataset_list_items.append(DatasetListItem.model_construct(**dataset.model_dump()))
|
|
315
|
+
|
|
316
|
+
return JSONResponse(
|
|
317
|
+
status_code=200,
|
|
318
|
+
content=jsonable_encoder(
|
|
319
|
+
{
|
|
320
|
+
"totalCount": len(dataset_list_items),
|
|
321
|
+
"results": dataset_list_items[int(offset) : int(offset) + int(limit)],
|
|
322
|
+
}
|
|
323
|
+
),
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
@self.router.post("/datasets", response_model=Dataset)
|
|
327
|
+
async def create_dataset(config: DatasetConfig = Body(...)) -> Dataset:
|
|
328
|
+
dataset = Dataset(**config.model_dump())
|
|
329
|
+
dataset_dir = self.home_dir / "datasets" / dataset.id
|
|
330
|
+
write_dataset_to_json(dataset_dir, dataset)
|
|
331
|
+
return dataset
|
|
332
|
+
|
|
333
|
+
@self.router.get("/datasets/{id}", response_model=Dataset)
|
|
334
|
+
async def get_dataset(id: str) -> Dataset:
|
|
335
|
+
dataset_dir = self.home_dir / "datasets" / id
|
|
336
|
+
if not dataset_dir.exists():
|
|
337
|
+
raise HTTPException(status_code=404, detail=f"Dataset `{id}` not found")
|
|
338
|
+
dataset = read_dataset_from_json(dataset_dir)
|
|
339
|
+
return dataset
|
|
340
|
+
|
|
341
|
+
@self.router.patch("/datasets/{id}", response_model=Dataset)
|
|
342
|
+
async def patch_dataset(id: str, config: DatasetPatchConfig = Body(...)) -> Dataset:
|
|
343
|
+
dataset_dir = self.home_dir / "datasets" / id
|
|
344
|
+
dataset = read_dataset_from_json(dataset_dir)
|
|
345
|
+
for key, value in config.model_dump().items():
|
|
346
|
+
if value is not None:
|
|
347
|
+
setattr(dataset, key, value)
|
|
348
|
+
write_dataset_to_json(dataset_dir, dataset)
|
|
349
|
+
return dataset
|
|
350
|
+
|
|
351
|
+
@self.router.delete("/datasets/{id}")
|
|
352
|
+
async def delete_dataset(id: str):
|
|
353
|
+
dataset_dir = self.home_dir / "datasets" / id
|
|
354
|
+
shutil.rmtree(dataset_dir, ignore_errors=True)
|
|
355
|
+
|
|
356
|
+
@self.router.get("/datasets/{id}/file")
|
|
357
|
+
async def download_dataset_file(id: str, filepath: str) -> FileResponse:
|
|
358
|
+
dataset_dir = self.home_dir / "datasets" / id
|
|
359
|
+
filename = Path(filepath).name
|
|
360
|
+
return StreamingResponse(
|
|
361
|
+
open(dataset_dir / filepath, "rb"),
|
|
362
|
+
media_type="application/octet-stream",
|
|
363
|
+
headers={"Content-Disposition": f"attachment; filename={filename}"},
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
@self.router.post("/datasets/{id}/file")
|
|
367
|
+
async def upload_dataset_file(id: str, file: UploadFile = File(...)) -> None:
|
|
368
|
+
dataset_dir = self.home_dir / "datasets" / id
|
|
369
|
+
dataset = read_dataset_from_json(dataset_dir)
|
|
370
|
+
try:
|
|
371
|
+
file_content = await file.read()
|
|
372
|
+
with open(dataset_dir / file.filename, "wb") as f:
|
|
373
|
+
f.write(file_content)
|
|
374
|
+
dataset.files.append(file.filename)
|
|
375
|
+
write_dataset_to_json(dataset_dir, dataset)
|
|
376
|
+
except Exception as e:
|
|
377
|
+
raise HTTPException(status_code=500, detail=f"Error uploading file `{file.filename}`: {e}")
|
|
378
|
+
|
|
379
|
+
@self.router.delete("/datasets/{id}/file")
|
|
380
|
+
async def delete_dataset_file(id: str, filepath: str) -> None:
|
|
381
|
+
dataset_dir = self.home_dir / "datasets" / id
|
|
382
|
+
dataset = read_dataset_from_json(dataset_dir)
|
|
383
|
+
if os.path.exists(dataset_dir / filepath):
|
|
384
|
+
os.remove(dataset_dir / filepath)
|
|
385
|
+
dataset.files = [f for f in dataset.files if f != filepath]
|
|
386
|
+
write_dataset_to_json(dataset_dir, dataset)
|
|
387
|
+
|
|
292
388
|
## GENERATORS
|
|
293
389
|
|
|
294
390
|
@self.router.get("/generators")
|
|
@@ -23,6 +23,7 @@ from pydantic import BaseModel
|
|
|
23
23
|
|
|
24
24
|
from mostlyai.sdk.domain import (
|
|
25
25
|
Connector,
|
|
26
|
+
Dataset,
|
|
26
27
|
Generator,
|
|
27
28
|
JobProgress,
|
|
28
29
|
ModelType,
|
|
@@ -82,6 +83,17 @@ def write_connector_to_json(connector_dir: Path, connector: Connector) -> None:
|
|
|
82
83
|
write_to_json(json_file, connector)
|
|
83
84
|
|
|
84
85
|
|
|
86
|
+
def read_dataset_from_json(dataset_dir: Path) -> Dataset:
|
|
87
|
+
json_file = dataset_dir / "dataset.json"
|
|
88
|
+
return Dataset(**json.loads(json_file.read_text()))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def write_dataset_to_json(dataset_dir: Path, dataset: Dataset) -> None:
|
|
92
|
+
json_file = dataset_dir / "dataset.json"
|
|
93
|
+
dataset_dir.mkdir(parents=True, exist_ok=True)
|
|
94
|
+
write_to_json(json_file, dataset)
|
|
95
|
+
|
|
96
|
+
|
|
85
97
|
def read_job_progress_from_json(resource_dir: Path) -> JobProgress:
|
|
86
98
|
progress_file = resource_dir / "job_progress.json"
|
|
87
99
|
lock_file = progress_file.with_suffix(".lock")
|
|
@@ -72,7 +72,7 @@ def convert_to_df(data: str, format: Literal["parquet", "jsonl"] = "parquet") ->
|
|
|
72
72
|
return df
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
def read_table_from_path(path: str | Path) ->
|
|
75
|
+
def read_table_from_path(path: str | Path) -> tuple[str, pd.DataFrame]:
|
|
76
76
|
# read data from file
|
|
77
77
|
fn = str(path)
|
|
78
78
|
if fn.lower().endswith((".pqt", ".parquet")):
|
|
@@ -30,6 +30,7 @@ from mostlyai.sdk.client._utils import (
|
|
|
30
30
|
)
|
|
31
31
|
from mostlyai.sdk.client.base import DEFAULT_BASE_URL, GET, _MostlyBaseClient
|
|
32
32
|
from mostlyai.sdk.client.connectors import _MostlyConnectorsClient
|
|
33
|
+
from mostlyai.sdk.client.datasets import _MostlyDatasetsClient
|
|
33
34
|
from mostlyai.sdk.client.exceptions import APIError
|
|
34
35
|
from mostlyai.sdk.client.generators import _MostlyGeneratorsClient
|
|
35
36
|
from mostlyai.sdk.client.synthetic_datasets import (
|
|
@@ -218,6 +219,7 @@ class MostlyAI(_MostlyBaseClient):
|
|
|
218
219
|
super().__init__(**client_kwargs)
|
|
219
220
|
self.connectors = _MostlyConnectorsClient(**client_kwargs)
|
|
220
221
|
self.generators = _MostlyGeneratorsClient(**client_kwargs)
|
|
222
|
+
self.datasets = _MostlyDatasetsClient(**client_kwargs)
|
|
221
223
|
self.synthetic_datasets = _MostlySyntheticDatasetsClient(**client_kwargs)
|
|
222
224
|
self.synthetic_probes = _MostlySyntheticProbesClient(**client_kwargs)
|
|
223
225
|
if mode == "LOCAL":
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# Copyright 2025 MOSTLY AI
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import re
|
|
16
|
+
from collections.abc import Iterator
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
import rich
|
|
21
|
+
|
|
22
|
+
from mostlyai.sdk.client.base import (
|
|
23
|
+
DELETE,
|
|
24
|
+
GET,
|
|
25
|
+
PATCH,
|
|
26
|
+
POST,
|
|
27
|
+
Paginator,
|
|
28
|
+
_MostlyBaseClient,
|
|
29
|
+
)
|
|
30
|
+
from mostlyai.sdk.domain import (
|
|
31
|
+
Dataset,
|
|
32
|
+
DatasetConfig,
|
|
33
|
+
DatasetListItem,
|
|
34
|
+
DatasetPatchConfig,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class _MostlyDatasetsClient(_MostlyBaseClient):
|
|
39
|
+
SECTION = ["datasets"]
|
|
40
|
+
|
|
41
|
+
# PUBLIC METHODS #
|
|
42
|
+
|
|
43
|
+
def list(
|
|
44
|
+
self,
|
|
45
|
+
offset: int = 0,
|
|
46
|
+
limit: int | None = None,
|
|
47
|
+
search_term: str | None = None,
|
|
48
|
+
owner_id: str | list[str] | None = None,
|
|
49
|
+
visibility: str | list[str] | None = None,
|
|
50
|
+
created_from: str | None = None,
|
|
51
|
+
created_to: str | None = None,
|
|
52
|
+
sort_by: str | list[str] | None = None,
|
|
53
|
+
) -> Iterator[DatasetListItem]:
|
|
54
|
+
"""
|
|
55
|
+
List datasets.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
offset: Offset for the entities in the response.
|
|
59
|
+
limit: Limit for the number of entities in the response.
|
|
60
|
+
status: Filter by generation status.
|
|
61
|
+
search_term: Filter by name or description.
|
|
62
|
+
owner_id: Filter by owner ID.
|
|
63
|
+
visibility: Filter by visibility (e.g., PUBLIC, PRIVATE or UNLISTED).
|
|
64
|
+
created_from: Filter by creation date, not older than this date. Format: YYYY-MM-DD.
|
|
65
|
+
created_to: Filter by creation date, not younger than this date. Format: YYYY-MM-DD.
|
|
66
|
+
sort_by: Sort by field. Either RECENCY, NO_OF_LIKES.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
An iterator over datasets.
|
|
70
|
+
|
|
71
|
+
Example for listing all datasets:
|
|
72
|
+
```python
|
|
73
|
+
from mostlyai.sdk import MostlyAI
|
|
74
|
+
mostly = MostlyAI()
|
|
75
|
+
for ds in mostly.datasets.list():
|
|
76
|
+
print(f"Dataset `{ds.name}` ({ds.id})")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Example for searching datasets via key word:
|
|
80
|
+
```python
|
|
81
|
+
from mostlyai.sdk import MostlyAI
|
|
82
|
+
mostly = MostlyAI()
|
|
83
|
+
datasets = list(mostly.datasets.list(search_term="census"))
|
|
84
|
+
print(f"Found {len(datasets)} datasets")
|
|
85
|
+
"""
|
|
86
|
+
with Paginator(
|
|
87
|
+
self,
|
|
88
|
+
DatasetListItem,
|
|
89
|
+
offset=offset,
|
|
90
|
+
limit=limit,
|
|
91
|
+
search_term=search_term,
|
|
92
|
+
owner_id=owner_id,
|
|
93
|
+
visibility=visibility,
|
|
94
|
+
created_from=created_from,
|
|
95
|
+
created_to=created_to,
|
|
96
|
+
sort_by=sort_by,
|
|
97
|
+
) as paginator:
|
|
98
|
+
yield from paginator
|
|
99
|
+
|
|
100
|
+
def get(self, dataset_id: str) -> Dataset:
|
|
101
|
+
"""
|
|
102
|
+
Retrieve a dataset by its ID.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
dataset_id: The unique identifier of the dataset.
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
Dataset: The retrieved dataset object.
|
|
109
|
+
|
|
110
|
+
Example for retrieving a dataset:
|
|
111
|
+
```python
|
|
112
|
+
from mostlyai.sdk import MostlyAI
|
|
113
|
+
mostly = MostlyAI()
|
|
114
|
+
ds = mostly.datasets.get('INSERT_YOUR_DATASET_ID')
|
|
115
|
+
ds
|
|
116
|
+
```
|
|
117
|
+
"""
|
|
118
|
+
if not isinstance(dataset_id, str) or len(dataset_id) != 36:
|
|
119
|
+
raise ValueError("The provided dataset_id must be a UUID string")
|
|
120
|
+
response = self.request(verb=GET, path=[dataset_id], response_type=Dataset)
|
|
121
|
+
return response
|
|
122
|
+
|
|
123
|
+
def create(self, config: DatasetConfig | dict[str, Any]) -> Dataset:
|
|
124
|
+
"""
|
|
125
|
+
Create a dataset.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
config: Configuration for the dataset.
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
The created dataset object.
|
|
132
|
+
|
|
133
|
+
Example for creating a dataset:
|
|
134
|
+
```python
|
|
135
|
+
from mostlyai.sdk import MostlyAI
|
|
136
|
+
mostly = MostlyAI()
|
|
137
|
+
ds = mostly.datasets.create(
|
|
138
|
+
config=DatasetConfig(
|
|
139
|
+
name="INSERT_YOUR_DATASET_NAME",
|
|
140
|
+
description="INSERT_YOUR_DATASET_DESCRIPTION",
|
|
141
|
+
connectors=[
|
|
142
|
+
DatasetConnector(
|
|
143
|
+
connector_id="INSERT_YOUR_CONNECTOR_ID",
|
|
144
|
+
location="INSERT_YOUR_LOCATION",
|
|
145
|
+
)
|
|
146
|
+
],
|
|
147
|
+
)
|
|
148
|
+
)
|
|
149
|
+
```
|
|
150
|
+
"""
|
|
151
|
+
dataset = self.request(
|
|
152
|
+
verb=POST,
|
|
153
|
+
path=[],
|
|
154
|
+
json=config,
|
|
155
|
+
response_type=Dataset,
|
|
156
|
+
)
|
|
157
|
+
dsid = dataset.id
|
|
158
|
+
if self.local:
|
|
159
|
+
rich.print(f"Created dataset [dodger_blue2]{dsid}[/]")
|
|
160
|
+
else:
|
|
161
|
+
rich.print(f"Created dataset [link={self.base_url}/d/datasets/{dsid} dodger_blue2 underline]{dsid}[/]")
|
|
162
|
+
return dataset
|
|
163
|
+
|
|
164
|
+
def _update(
|
|
165
|
+
self,
|
|
166
|
+
dataset_id: str,
|
|
167
|
+
config: DatasetPatchConfig | dict[str, Any],
|
|
168
|
+
) -> Dataset:
|
|
169
|
+
response = self.request(
|
|
170
|
+
verb=PATCH,
|
|
171
|
+
path=[dataset_id],
|
|
172
|
+
json=config,
|
|
173
|
+
response_type=Dataset,
|
|
174
|
+
)
|
|
175
|
+
return response
|
|
176
|
+
|
|
177
|
+
def _delete(self, dataset_id: str) -> None:
|
|
178
|
+
response = self.request(verb=DELETE, path=[dataset_id])
|
|
179
|
+
return response
|
|
180
|
+
|
|
181
|
+
def _config(self, dataset_id: str) -> DatasetConfig:
|
|
182
|
+
response = self.request(verb=GET, path=[dataset_id, "config"], response_type=DatasetConfig)
|
|
183
|
+
return response
|
|
184
|
+
|
|
185
|
+
def _download_file(
|
|
186
|
+
self,
|
|
187
|
+
dataset_id: str,
|
|
188
|
+
file_path: str,
|
|
189
|
+
) -> tuple[bytes, str | None]:
|
|
190
|
+
response = self.request(
|
|
191
|
+
verb=GET,
|
|
192
|
+
path=[dataset_id, "file"],
|
|
193
|
+
params={"filepath": file_path},
|
|
194
|
+
headers={
|
|
195
|
+
"Accept": "application/json, text/plain, */*",
|
|
196
|
+
},
|
|
197
|
+
raw_response=True,
|
|
198
|
+
)
|
|
199
|
+
content_bytes = response.content
|
|
200
|
+
# Check if 'Content-Disposition' header is present
|
|
201
|
+
if "Content-Disposition" in response.headers:
|
|
202
|
+
content_disposition = response.headers["Content-Disposition"]
|
|
203
|
+
filename = re.findall(r"filename(?:=|\*=UTF-8'')(.+)", content_disposition)[0]
|
|
204
|
+
else:
|
|
205
|
+
filename = Path(file_path).name
|
|
206
|
+
return content_bytes, filename
|
|
207
|
+
|
|
208
|
+
def _upload_file(
|
|
209
|
+
self,
|
|
210
|
+
dataset_id: str,
|
|
211
|
+
file_path: str | Path,
|
|
212
|
+
) -> None:
|
|
213
|
+
with open(file_path, "rb") as f:
|
|
214
|
+
_ = self.request(
|
|
215
|
+
verb=POST,
|
|
216
|
+
path=[dataset_id, "file"],
|
|
217
|
+
headers={
|
|
218
|
+
"Accept": "application/json, text/plain, */*",
|
|
219
|
+
},
|
|
220
|
+
files={"file": f},
|
|
221
|
+
)
|
|
222
|
+
rich.print(f"Uploaded file `{file_path}` to Dataset [dodger_blue2]{dataset_id}[/]")
|
|
223
|
+
|
|
224
|
+
def _delete_file(
|
|
225
|
+
self,
|
|
226
|
+
dataset_id: str,
|
|
227
|
+
file_path: str | Path,
|
|
228
|
+
) -> None:
|
|
229
|
+
_ = self.request(
|
|
230
|
+
verb=DELETE,
|
|
231
|
+
path=[dataset_id, "file"],
|
|
232
|
+
params={
|
|
233
|
+
"filepath": file_path,
|
|
234
|
+
},
|
|
235
|
+
)
|
|
236
|
+
rich.print(f"Deleted file `{file_path}` from Dataset [dodger_blue2]{dataset_id}[/]")
|
|
@@ -267,7 +267,7 @@ class _MostlyGeneratorsClient(_MostlyBaseClient):
|
|
|
267
267
|
def _export_to_file(
|
|
268
268
|
self,
|
|
269
269
|
generator_id: str,
|
|
270
|
-
) ->
|
|
270
|
+
) -> tuple[bytes, str | None]:
|
|
271
271
|
response = self.request(
|
|
272
272
|
verb=GET,
|
|
273
273
|
path=[generator_id, "export-to-file"],
|
|
@@ -318,7 +318,7 @@ class _MostlyGeneratorsClient(_MostlyBaseClient):
|
|
|
318
318
|
source_table_id: str,
|
|
319
319
|
model_type: ModelType = ModelType.tabular,
|
|
320
320
|
short_lived_file_token: str | None = None,
|
|
321
|
-
) ->
|
|
321
|
+
) -> tuple[str, str | None]:
|
|
322
322
|
response = self.request(
|
|
323
323
|
verb=GET,
|
|
324
324
|
path=[generator_id, "tables", source_table_id, "report"],
|
|
@@ -348,7 +348,7 @@ class _MostlyGeneratorsClient(_MostlyBaseClient):
|
|
|
348
348
|
generator = self.get(generator_id)
|
|
349
349
|
return generator
|
|
350
350
|
|
|
351
|
-
def _training_logs(self, generator_id: str, short_lived_file_token: str | None = None) ->
|
|
351
|
+
def _training_logs(self, generator_id: str, short_lived_file_token: str | None = None) -> tuple[bytes, str]:
|
|
352
352
|
response = self.request(
|
|
353
353
|
verb=GET,
|
|
354
354
|
path=[generator_id, "training", "logs"],
|
|
@@ -213,7 +213,7 @@ class _MostlySyntheticDatasetsClient(_MostlyBaseClient):
|
|
|
213
213
|
synthetic_dataset_id: str,
|
|
214
214
|
ds_format: SyntheticDatasetFormat = SyntheticDatasetFormat.parquet,
|
|
215
215
|
short_lived_file_token: str | None = None,
|
|
216
|
-
) ->
|
|
216
|
+
) -> tuple[bytes, str | None]:
|
|
217
217
|
response = self.request(
|
|
218
218
|
verb=GET,
|
|
219
219
|
path=[synthetic_dataset_id, "download"],
|
|
@@ -261,7 +261,7 @@ class _MostlySyntheticDatasetsClient(_MostlyBaseClient):
|
|
|
261
261
|
model_type: ModelType = ModelType.tabular,
|
|
262
262
|
report_type: SyntheticDatasetReportType = SyntheticDatasetReportType.model,
|
|
263
263
|
short_lived_file_token: str | None = None,
|
|
264
|
-
) ->
|
|
264
|
+
) -> tuple[str, str | None]:
|
|
265
265
|
response = self.request(
|
|
266
266
|
verb=GET,
|
|
267
267
|
path=[synthetic_dataset_id, "tables", synthetic_table_id, "report"],
|
|
@@ -300,7 +300,9 @@ class _MostlySyntheticDatasetsClient(_MostlyBaseClient):
|
|
|
300
300
|
synthetic_dataset = self.get(synthetic_dataset_id)
|
|
301
301
|
return synthetic_dataset
|
|
302
302
|
|
|
303
|
-
def _generation_logs(
|
|
303
|
+
def _generation_logs(
|
|
304
|
+
self, synthetic_dataset_id: str, short_lived_file_token: str | None = None
|
|
305
|
+
) -> tuple[bytes, str]:
|
|
304
306
|
response = self.request(
|
|
305
307
|
verb=GET,
|
|
306
308
|
path=[synthetic_dataset_id, "generation", "logs"],
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
# generated by datamodel-codegen:
|
|
16
|
-
# timestamp: 2025-
|
|
16
|
+
# timestamp: 2025-07-10T14:44:02+00:00
|
|
17
17
|
|
|
18
18
|
from __future__ import annotations
|
|
19
19
|
|
|
@@ -175,6 +175,19 @@ class PaginatedTotalCount(RootModel[int]):
|
|
|
175
175
|
root: int = Field(..., description="The total number of entities within the list")
|
|
176
176
|
|
|
177
177
|
|
|
178
|
+
class DatasetUsage(CustomBaseModel):
|
|
179
|
+
"""
|
|
180
|
+
Usage statistics of a dataset.
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
no_of_likes: int | None = Field(None, alias="noOfLikes", description="Number of likes of this dataset.")
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
class DatasetSortField(str, Enum):
|
|
187
|
+
recency = "RECENCY"
|
|
188
|
+
no_of_likes = "NO_OF_LIKES"
|
|
189
|
+
|
|
190
|
+
|
|
178
191
|
class ConnectorAccessType(str, Enum):
|
|
179
192
|
"""
|
|
180
193
|
The access permissions of a connector.
|
|
@@ -889,6 +902,7 @@ class AssistantMessageContentType(str, Enum):
|
|
|
889
902
|
artifact_generator = "artifact/generator"
|
|
890
903
|
artifact_synthetic_dataset = "artifact/synthetic-dataset"
|
|
891
904
|
artifact_connector = "artifact/connector"
|
|
905
|
+
artifact_dataset = "artifact/dataset"
|
|
892
906
|
|
|
893
907
|
|
|
894
908
|
class AssistantMessageDeltaContentType(str, Enum):
|
|
@@ -1794,6 +1808,148 @@ class Metadata(CustomBaseModel):
|
|
|
1794
1808
|
)
|
|
1795
1809
|
|
|
1796
1810
|
|
|
1811
|
+
class DatasetConnector(CustomBaseModel):
|
|
1812
|
+
"""
|
|
1813
|
+
Configuration for a dataset connector.
|
|
1814
|
+
"""
|
|
1815
|
+
|
|
1816
|
+
connector_id: str | None = Field(None, alias="connectorId", description="The unique identifier of a connector.")
|
|
1817
|
+
locations: list[str] | None = None
|
|
1818
|
+
|
|
1819
|
+
|
|
1820
|
+
class Dataset(CustomBaseModel):
|
|
1821
|
+
"""
|
|
1822
|
+
A dataset to be consumed via the assistant.
|
|
1823
|
+
"""
|
|
1824
|
+
|
|
1825
|
+
id: str = Field(..., description="The unique identifier of a dataset.")
|
|
1826
|
+
name: str | None = Field(None, description="The name of a dataset.")
|
|
1827
|
+
description: str | None = Field(None, description="The description of / instructions for a dataset.")
|
|
1828
|
+
connectors: list[DatasetConnector] | None = None
|
|
1829
|
+
files: list[str] | None = None
|
|
1830
|
+
usage: DatasetUsage | None = None
|
|
1831
|
+
metadata: Metadata | None = None
|
|
1832
|
+
OPEN_URL_PARTS: ClassVar[list] = ["d", "datasets"]
|
|
1833
|
+
|
|
1834
|
+
@model_validator(mode="before")
|
|
1835
|
+
@classmethod
|
|
1836
|
+
def add_required_fields(cls, values):
|
|
1837
|
+
if isinstance(values, dict):
|
|
1838
|
+
if "id" not in values:
|
|
1839
|
+
values["id"] = str(uuid.uuid4())
|
|
1840
|
+
return values
|
|
1841
|
+
|
|
1842
|
+
@field_validator("files", mode="after")
|
|
1843
|
+
@classmethod
|
|
1844
|
+
def initialize_file_list(cls, values):
|
|
1845
|
+
if values is None:
|
|
1846
|
+
values = []
|
|
1847
|
+
return values
|
|
1848
|
+
|
|
1849
|
+
def update(
|
|
1850
|
+
self,
|
|
1851
|
+
name: str | None = None,
|
|
1852
|
+
description: str | None = None,
|
|
1853
|
+
connectors: list[DatasetConnector] | None = None,
|
|
1854
|
+
) -> None:
|
|
1855
|
+
"""
|
|
1856
|
+
Update a dataset with specific parameters.
|
|
1857
|
+
|
|
1858
|
+
Args:
|
|
1859
|
+
name (str | None): The name of the connector.
|
|
1860
|
+
description (str | None): The description of the connector.
|
|
1861
|
+
connectors (list[DatasetConnector] | None): The connectors of the dataset.
|
|
1862
|
+
"""
|
|
1863
|
+
patch_config = DatasetPatchConfig(
|
|
1864
|
+
name=name,
|
|
1865
|
+
description=description,
|
|
1866
|
+
connectors=connectors,
|
|
1867
|
+
)
|
|
1868
|
+
self.client._update(
|
|
1869
|
+
dataset_id=self.id,
|
|
1870
|
+
config=patch_config,
|
|
1871
|
+
)
|
|
1872
|
+
self.reload()
|
|
1873
|
+
|
|
1874
|
+
def delete(self) -> None:
|
|
1875
|
+
"""
|
|
1876
|
+
Delete the dataset.
|
|
1877
|
+
"""
|
|
1878
|
+
return self.client._delete(dataset_id=self.id)
|
|
1879
|
+
|
|
1880
|
+
def download_file(
|
|
1881
|
+
self,
|
|
1882
|
+
dataset_file_path: str | Path,
|
|
1883
|
+
output_file_path: str | Path | None = None,
|
|
1884
|
+
) -> Path:
|
|
1885
|
+
"""
|
|
1886
|
+
Download the dataset file.
|
|
1887
|
+
|
|
1888
|
+
Args:
|
|
1889
|
+
file_path (str | Path | None): The file path to save the dataset file.
|
|
1890
|
+
|
|
1891
|
+
Returns:
|
|
1892
|
+
Path: The path to the saved file.
|
|
1893
|
+
"""
|
|
1894
|
+
bytes, filename = self.client._download_file(dataset_id=self.id, file_path=str(dataset_file_path))
|
|
1895
|
+
output_file_path = Path(output_file_path or ".")
|
|
1896
|
+
if output_file_path.is_dir():
|
|
1897
|
+
output_file_path = output_file_path / filename
|
|
1898
|
+
output_file_path.write_bytes(bytes)
|
|
1899
|
+
return output_file_path
|
|
1900
|
+
|
|
1901
|
+
def upload_file(
|
|
1902
|
+
self,
|
|
1903
|
+
file_path: str | Path,
|
|
1904
|
+
) -> None:
|
|
1905
|
+
"""
|
|
1906
|
+
Upload the dataset file.
|
|
1907
|
+
"""
|
|
1908
|
+
self.client._upload_file(dataset_id=self.id, file_path=str(file_path))
|
|
1909
|
+
self.reload()
|
|
1910
|
+
|
|
1911
|
+
def delete_file(
|
|
1912
|
+
self,
|
|
1913
|
+
file_path: str | Path,
|
|
1914
|
+
) -> None:
|
|
1915
|
+
"""
|
|
1916
|
+
Delete the dataset file.
|
|
1917
|
+
"""
|
|
1918
|
+
self.client._delete_file(dataset_id=self.id, file_path=str(file_path))
|
|
1919
|
+
self.reload()
|
|
1920
|
+
|
|
1921
|
+
|
|
1922
|
+
class DatasetListItem(CustomBaseModel):
|
|
1923
|
+
"""
|
|
1924
|
+
Essential dataset details for listings.
|
|
1925
|
+
"""
|
|
1926
|
+
|
|
1927
|
+
id: str = Field(..., description="The unique identifier of a dataset.")
|
|
1928
|
+
name: str | None = Field(None, description="The name of a dataset.")
|
|
1929
|
+
usage: DatasetUsage | None = None
|
|
1930
|
+
metadata: Metadata | None = None
|
|
1931
|
+
|
|
1932
|
+
|
|
1933
|
+
class DatasetConfig(CustomBaseModel):
|
|
1934
|
+
"""
|
|
1935
|
+
The configuration for creating a dataset.
|
|
1936
|
+
"""
|
|
1937
|
+
|
|
1938
|
+
name: str | None = Field(None, description="The name of a dataset.")
|
|
1939
|
+
description: str | None = Field(None, description="The description of / instructions for a dataset.")
|
|
1940
|
+
connectors: list[DatasetConnector] | None = None
|
|
1941
|
+
|
|
1942
|
+
|
|
1943
|
+
class DatasetPatchConfig(CustomBaseModel):
|
|
1944
|
+
"""
|
|
1945
|
+
The configuration for updating a dataset.
|
|
1946
|
+
"""
|
|
1947
|
+
|
|
1948
|
+
name: str | None = Field(None, description="The name of a dataset.")
|
|
1949
|
+
description: str | None = Field(None, description="The description of / instructions for a dataset.")
|
|
1950
|
+
connectors: list[DatasetConnector] | None = None
|
|
1951
|
+
|
|
1952
|
+
|
|
1797
1953
|
class ConnectorListItem(CustomBaseModel):
|
|
1798
1954
|
"""
|
|
1799
1955
|
Essential connector details for listings.
|
|
@@ -2680,11 +2836,9 @@ class SourceTableConfig(CustomBaseModel):
|
|
|
2680
2836
|
else:
|
|
2681
2837
|
has_tabular_model = True
|
|
2682
2838
|
has_language_model = False
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
if fk.is_context:
|
|
2687
|
-
has_tabular_model = True
|
|
2839
|
+
# Always train tabular model for tables with a primary key or linked tables to model sequences
|
|
2840
|
+
if values.primary_key or (values.foreign_keys and any(fk.is_context for fk in values.foreign_keys)):
|
|
2841
|
+
has_tabular_model = True
|
|
2688
2842
|
# Remove model configurations that are not applicable for the model type
|
|
2689
2843
|
if values.tabular_model_configuration and not has_tabular_model:
|
|
2690
2844
|
values.tabular_model_configuration = None
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "mostlyai"
|
|
3
|
-
version = "4.8.
|
|
3
|
+
version = "4.8.4"
|
|
4
4
|
description = "Synthetic Data SDK"
|
|
5
5
|
authors = [{ name = "MOSTLY AI", email = "dev@mostly.ai" }]
|
|
6
6
|
requires-python = ">=3.10,<3.14"
|
|
@@ -49,7 +49,7 @@ dependencies = [
|
|
|
49
49
|
local = [
|
|
50
50
|
# "mostlyai-engine @ git+https://github.com/mostly-ai/mostlyai-engine.git@main", # for development
|
|
51
51
|
# "mostlyai-qa @ git+https://github.com/mostly-ai/mostlyai-qa.git@main", # for development
|
|
52
|
-
"mostlyai-engine==1.4.
|
|
52
|
+
"mostlyai-engine==1.4.8", # for release
|
|
53
53
|
"mostlyai-qa==1.9.8", # for release
|
|
54
54
|
"fastapi>=0.115.6,<0.116",
|
|
55
55
|
"uvicorn>=0.34.0,<0.35",
|
|
@@ -75,7 +75,7 @@ local = [
|
|
|
75
75
|
local-gpu = [
|
|
76
76
|
# "mostlyai-engine[gpu] @ git+https://github.com/mostly-ai/mostlyai-engine.git@main", # for development
|
|
77
77
|
# "mostlyai-qa @ git+https://github.com/mostly-ai/mostlyai-qa.git@main", # for development
|
|
78
|
-
"mostlyai-engine[gpu]==1.4.
|
|
78
|
+
"mostlyai-engine[gpu]==1.4.8", # for release
|
|
79
79
|
"mostlyai-qa==1.9.8", # for release
|
|
80
80
|
"fastapi>=0.115.6,<0.116",
|
|
81
81
|
"uvicorn>=0.34.0,<0.35",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_analyze_training_data.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_encode_training_data.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mostlyai-4.8.2 → mostlyai-4.8.4}/mostlyai/sdk/_local/execution/step_generate_model_report_data.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|