mostlyai 4.1.0__tar.gz → 4.1.2__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.1.0 → mostlyai-4.1.2}/PKG-INFO +6 -4
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/__init__.py +1 -1
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/routes.py +30 -49
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/server.py +22 -28
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/storage.py +10 -6
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/client/_utils.py +2 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/client/api.py +23 -16
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/client/base.py +4 -1
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/client/connectors.py +4 -1
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/client/generators.py +25 -2
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/client/synthetic_datasets.py +23 -3
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/domain.py +141 -38
- {mostlyai-4.1.0 → mostlyai-4.1.2}/pyproject.toml +8 -6
- {mostlyai-4.1.0 → mostlyai-4.1.2}/.gitignore +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/LICENSE +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/README.md +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/__init__.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/auto_detect.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/base.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/context.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/conversions.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/db/__init__.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/db/base.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/db/bigquery.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/db/databricks.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/db/hive.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/db/mssql.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/db/mysql.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/db/oracle.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/db/postgresql.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/db/snowflake.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/db/sqlite.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/db/types_coercion.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/dtype.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/exceptions.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/__init__.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/base.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/container/__init__.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/container/aws.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/container/azure.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/container/bucket_based.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/container/gcs.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/container/minio.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/table/__init__.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/table/csv.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/table/feather.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/table/json.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/table/parquet.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/file/utils.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/language_model.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/metadata_objects.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/non_context.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/progress_callback.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/pull.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/pull_context.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/pull_utils.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/push.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/util/__init__.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/util/common.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_data/util/kerberos.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/__init__.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/cli.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/connectors.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/__init__.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/jobs.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/plan.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_analyze_training_data.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_create_data_report.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_create_model_report.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_deliver_data.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_encode_training_data.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_finalize_generation.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_finalize_training.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_generate_data.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_generate_model_report_data.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_pull_training_data.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_train_model.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/generators.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/progress.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/synthetic_datasets.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/client/__init__.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/client/_base_utils.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/client/_naming_conventions.py +0 -0
- {mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/client/exceptions.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mostlyai
|
|
3
|
-
Version: 4.1.
|
|
3
|
+
Version: 4.1.2
|
|
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
|
|
@@ -33,7 +33,9 @@ Requires-Dist: gcsfs<2024,>=2023.1.0
|
|
|
33
33
|
Requires-Dist: greenlet<4,>=3.1.1
|
|
34
34
|
Requires-Dist: gunicorn>=23.0.0
|
|
35
35
|
Requires-Dist: httpx>=0.25.0
|
|
36
|
+
Requires-Dist: ipywidgets>=8.1.0
|
|
36
37
|
Requires-Dist: joblib>=1.2.0
|
|
38
|
+
Requires-Dist: networkx<4,>=3.0
|
|
37
39
|
Requires-Dist: openpyxl>=3.1.5
|
|
38
40
|
Requires-Dist: pandas>=2.0.0
|
|
39
41
|
Requires-Dist: psutil>=5.9.5
|
|
@@ -63,14 +65,14 @@ Requires-Dist: pyhive[hive-pure-sasl]<0.8,>=0.7.0; extra == 'hive'
|
|
|
63
65
|
Provides-Extra: local
|
|
64
66
|
Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local'
|
|
65
67
|
Requires-Dist: mostlyai-engine==1.0.4; extra == 'local'
|
|
66
|
-
Requires-Dist: mostlyai-qa==1.5.
|
|
68
|
+
Requires-Dist: mostlyai-qa==1.5.5; extra == 'local'
|
|
67
69
|
Requires-Dist: python-multipart>=0.0.20; extra == 'local'
|
|
68
70
|
Requires-Dist: torch<2.6.0,>=2.5.1; extra == 'local'
|
|
69
71
|
Requires-Dist: uvicorn<0.35,>=0.34.0; extra == 'local'
|
|
70
72
|
Provides-Extra: local-cpu
|
|
71
73
|
Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-cpu'
|
|
72
74
|
Requires-Dist: mostlyai-engine[cpu]==1.0.4; extra == 'local-cpu'
|
|
73
|
-
Requires-Dist: mostlyai-qa[cpu]==1.5.
|
|
75
|
+
Requires-Dist: mostlyai-qa[cpu]==1.5.5; extra == 'local-cpu'
|
|
74
76
|
Requires-Dist: python-multipart>=0.0.20; extra == 'local-cpu'
|
|
75
77
|
Requires-Dist: torch<2.6.0,>=2.5.1; (sys_platform != 'linux') and extra == 'local-cpu'
|
|
76
78
|
Requires-Dist: torch==2.5.1+cpu; (sys_platform == 'linux') and extra == 'local-cpu'
|
|
@@ -78,7 +80,7 @@ Requires-Dist: uvicorn<0.35,>=0.34.0; extra == 'local-cpu'
|
|
|
78
80
|
Provides-Extra: local-gpu
|
|
79
81
|
Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-gpu'
|
|
80
82
|
Requires-Dist: mostlyai-engine[gpu]==1.0.4; extra == 'local-gpu'
|
|
81
|
-
Requires-Dist: mostlyai-qa[gpu]==1.5.
|
|
83
|
+
Requires-Dist: mostlyai-qa[gpu]==1.5.5; extra == 'local-gpu'
|
|
82
84
|
Requires-Dist: python-multipart>=0.0.20; extra == 'local-gpu'
|
|
83
85
|
Requires-Dist: torch<2.6.0,>=2.5.1; extra == 'local-gpu'
|
|
84
86
|
Requires-Dist: uvicorn<0.35,>=0.34.0; extra == 'local-gpu'
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import os
|
|
15
15
|
import shutil
|
|
16
16
|
import subprocess
|
|
17
|
+
import sys
|
|
17
18
|
import uuid
|
|
18
19
|
import zipfile
|
|
19
20
|
from io import BytesIO
|
|
@@ -21,7 +22,7 @@ from pathlib import Path
|
|
|
21
22
|
|
|
22
23
|
from fastapi import APIRouter, Body, HTTPException, UploadFile, File
|
|
23
24
|
from fastapi.encoders import jsonable_encoder
|
|
24
|
-
from fastapi.responses import FileResponse, JSONResponse, StreamingResponse, HTMLResponse
|
|
25
|
+
from fastapi.responses import FileResponse, JSONResponse, StreamingResponse, HTMLResponse
|
|
25
26
|
|
|
26
27
|
from mostlyai import sdk
|
|
27
28
|
from mostlyai.sdk._data.conversions import create_container_from_connector
|
|
@@ -105,51 +106,6 @@ class Routes:
|
|
|
105
106
|
def _initialize_routes(self):
|
|
106
107
|
## GENERAL
|
|
107
108
|
|
|
108
|
-
@self.router.get("/", include_in_schema=False)
|
|
109
|
-
async def root() -> RedirectResponse:
|
|
110
|
-
return RedirectResponse(url="/docs")
|
|
111
|
-
|
|
112
|
-
@self.router.get("/d/connectors/{id}", response_class=HTMLResponse, include_in_schema=False)
|
|
113
|
-
async def show_connector(id: str) -> HTMLResponse:
|
|
114
|
-
connector_dir = self.home_dir / "connectors" / id
|
|
115
|
-
connector_json = connector_dir / "connector.json"
|
|
116
|
-
body = f"<h3>file://{connector_json}</h3><pre>{connector_json.read_text()}</pre>"
|
|
117
|
-
return HTMLResponse(content=self._html("Connector", body))
|
|
118
|
-
|
|
119
|
-
@self.router.get("/d/generators/{id}", response_class=HTMLResponse, include_in_schema=False)
|
|
120
|
-
async def show_generator(id: str) -> HTMLResponse:
|
|
121
|
-
generator_dir = self.home_dir / "generators" / id
|
|
122
|
-
generator_json = generator_dir / "generator.json"
|
|
123
|
-
progress_json = generator_dir / "job_progress.json"
|
|
124
|
-
job_log_file = generator_dir / "job.log"
|
|
125
|
-
job_log_logs = job_log_file.read_text() if job_log_file.exists() else ""
|
|
126
|
-
body = (
|
|
127
|
-
f"<h3>file://{generator_json}</h3>"
|
|
128
|
-
f"<pre>{generator_json.read_text()}</pre>"
|
|
129
|
-
f"<h3>file://{progress_json}</h3>"
|
|
130
|
-
f"<pre>{progress_json.read_text()}</pre>"
|
|
131
|
-
f"<h3>file://{job_log_file}</h3>"
|
|
132
|
-
f"<pre>{job_log_logs}</pre>"
|
|
133
|
-
)
|
|
134
|
-
return HTMLResponse(content=self._html("Generator", body))
|
|
135
|
-
|
|
136
|
-
@self.router.get("/d/synthetic-datasets/{id}", response_class=HTMLResponse, include_in_schema=False)
|
|
137
|
-
async def show_synthetic_dataset(id: str) -> HTMLResponse:
|
|
138
|
-
synthetic_dataset_dir = self.home_dir / "synthetic-datasets" / id
|
|
139
|
-
synthetic_dataset_json = synthetic_dataset_dir / "synthetic-dataset.json"
|
|
140
|
-
progress_json = synthetic_dataset_dir / "job_progress.json"
|
|
141
|
-
job_log_file = synthetic_dataset_dir / "job.log"
|
|
142
|
-
job_log_logs = job_log_file.read_text() if job_log_file.exists() else ""
|
|
143
|
-
body = (
|
|
144
|
-
f"<h3>file://{synthetic_dataset_json}</h3>"
|
|
145
|
-
f"<pre>{synthetic_dataset_json.read_text()}</pre>"
|
|
146
|
-
f"<h3>file://{progress_json}</h3>"
|
|
147
|
-
f"<pre>{progress_json.read_text()}</pre>"
|
|
148
|
-
f"<h3>file://{job_log_file}</h3>"
|
|
149
|
-
f"<pre>{job_log_logs}</pre>"
|
|
150
|
-
)
|
|
151
|
-
return HTMLResponse(content=self._html("Synthetic Dataset", body))
|
|
152
|
-
|
|
153
109
|
@self.router.get("/about", response_model=AboutService)
|
|
154
110
|
async def get_about_service() -> AboutService:
|
|
155
111
|
return AboutService(version=sdk.__version__, assistant=False)
|
|
@@ -335,7 +291,7 @@ class Routes:
|
|
|
335
291
|
if len(connector_dirs) < len(generator.tables):
|
|
336
292
|
raise HTTPException(
|
|
337
293
|
status_code=400,
|
|
338
|
-
detail="
|
|
294
|
+
detail="Cannot clone a generator whose connectors have been deleted.",
|
|
339
295
|
)
|
|
340
296
|
|
|
341
297
|
# check if any connectors are file upload
|
|
@@ -375,12 +331,26 @@ class Routes:
|
|
|
375
331
|
|
|
376
332
|
# call shell script to start training job
|
|
377
333
|
cli_py = str((Path(os.path.dirname(os.path.realpath(__file__))) / "cli.py").absolute())
|
|
378
|
-
cmd = [
|
|
334
|
+
cmd = [sys.executable, cli_py, "run-training", generator.id, str(self.home_dir.absolute())]
|
|
379
335
|
subprocess.Popen(cmd)
|
|
380
336
|
|
|
337
|
+
@self.router.get("/generators/{id}/training/logs", response_class=StreamingResponse)
|
|
338
|
+
async def download_training_logs(id: str, slft: str) -> StreamingResponse:
|
|
339
|
+
_ = slft # ignore parameter
|
|
340
|
+
generator_dir = self.home_dir / "generators" / id
|
|
341
|
+
zip_buffer = create_zip_in_memory(generator_dir, "*.log")
|
|
342
|
+
return StreamingResponse(
|
|
343
|
+
zip_buffer,
|
|
344
|
+
media_type="application/zip",
|
|
345
|
+
headers={"Content-Disposition": f"attachment; filename=generator-{id[:8]}-logs.zip"},
|
|
346
|
+
)
|
|
347
|
+
|
|
381
348
|
@self.router.get("/generators/{id}/export-to-file", response_class=StreamingResponse)
|
|
382
349
|
async def export_generator_to_file(id: str) -> StreamingResponse:
|
|
383
350
|
generator_dir = self.home_dir / "generators" / id
|
|
351
|
+
generator = read_generator_from_json(generator_dir)
|
|
352
|
+
if generator.training_status != ProgressStatus.done:
|
|
353
|
+
raise HTTPException(status_code=400, detail="Cannot export generator that is not trained")
|
|
384
354
|
zip_buffer = create_zip_in_memory(generator_dir)
|
|
385
355
|
return StreamingResponse(
|
|
386
356
|
zip_buffer,
|
|
@@ -501,9 +471,20 @@ class Routes:
|
|
|
501
471
|
|
|
502
472
|
# call shell script to start generation job
|
|
503
473
|
cli_py = str((Path(os.path.dirname(os.path.realpath(__file__))) / "cli.py").absolute())
|
|
504
|
-
cmd = [
|
|
474
|
+
cmd = [sys.executable, cli_py, "run-generation", synthetic_dataset.id, str(self.home_dir.absolute())]
|
|
505
475
|
subprocess.Popen(cmd)
|
|
506
476
|
|
|
477
|
+
@self.router.get("/synthetic-datasets/{id}/generation/logs", response_class=StreamingResponse)
|
|
478
|
+
async def download_generation_logs(id: str, slft: str) -> StreamingResponse:
|
|
479
|
+
_ = slft # ignore parameter
|
|
480
|
+
synthetic_dataset_dir = self.home_dir / "synthetic-datasets" / id
|
|
481
|
+
zip_buffer = create_zip_in_memory(synthetic_dataset_dir, "*.log")
|
|
482
|
+
return StreamingResponse(
|
|
483
|
+
zip_buffer,
|
|
484
|
+
media_type="application/zip",
|
|
485
|
+
headers={"Content-Disposition": f"attachment; filename=synthetic-dataset-{id[:8]}-logs.zip"},
|
|
486
|
+
)
|
|
487
|
+
|
|
507
488
|
@self.router.get("/synthetic-datasets/{id}/config", response_model=SyntheticDatasetConfig)
|
|
508
489
|
async def get_synthetic_dataset_config(id: str) -> SyntheticDatasetConfig:
|
|
509
490
|
return synthetic_datasets.get_synthetic_dataset_config(self.home_dir, id)
|
|
@@ -11,30 +11,32 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
-
|
|
14
|
+
import atexit
|
|
15
|
+
import tempfile
|
|
15
16
|
import time
|
|
16
17
|
from pathlib import Path
|
|
17
|
-
|
|
18
|
+
|
|
18
19
|
from threading import Thread
|
|
19
20
|
|
|
20
21
|
import rich
|
|
21
22
|
from fastapi import FastAPI
|
|
22
23
|
import uvicorn
|
|
23
24
|
from mostlyai.sdk._local.routes import Routes
|
|
24
|
-
|
|
25
|
+
|
|
26
|
+
import os
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
class LocalServer:
|
|
28
30
|
def __init__(
|
|
29
31
|
self,
|
|
30
32
|
home_dir: str | Path | None = None,
|
|
31
|
-
host: str | None = None,
|
|
32
|
-
port: int | None = None,
|
|
33
33
|
):
|
|
34
|
-
self.home_dir = Path(home_dir
|
|
35
|
-
self.
|
|
36
|
-
self.
|
|
37
|
-
|
|
34
|
+
self.home_dir = Path(home_dir or "~/mostlyai").expanduser()
|
|
35
|
+
self.home_dir.mkdir(parents=True, exist_ok=True)
|
|
36
|
+
self.uds = tempfile.NamedTemporaryFile(
|
|
37
|
+
dir=self.home_dir, prefix=".mostlyai-", suffix=".sock", delete=False
|
|
38
|
+
).name
|
|
39
|
+
self.base_url = "http://127.0.0.1"
|
|
38
40
|
self._app = FastAPI(
|
|
39
41
|
root_path="/api/v2",
|
|
40
42
|
title="Synthetic Data SDK ✨",
|
|
@@ -50,24 +52,13 @@ class LocalServer:
|
|
|
50
52
|
self._thread = None
|
|
51
53
|
self.start() # Automatically start the server during initialization
|
|
52
54
|
|
|
53
|
-
def
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return s.connect_ex((host, port)) == 0
|
|
57
|
-
|
|
58
|
-
failed_ports = []
|
|
59
|
-
min_port, max_port = 49152, 65535
|
|
60
|
-
for _ in range(10):
|
|
61
|
-
port = random.randint(min_port, max_port)
|
|
62
|
-
if not is_port_in_use(port, self.host):
|
|
63
|
-
return port
|
|
64
|
-
failed_ports.append(port)
|
|
65
|
-
raise ValueError(
|
|
66
|
-
f"Could not find an available port in range {min_port}-{max_port} after 10 attempts. Tried ports: {failed_ports}"
|
|
67
|
-
)
|
|
55
|
+
def _clear_socket_file(self):
|
|
56
|
+
if os.path.exists(self.uds):
|
|
57
|
+
os.remove(self.uds)
|
|
68
58
|
|
|
69
59
|
def _create_server(self):
|
|
70
|
-
|
|
60
|
+
self._clear_socket_file()
|
|
61
|
+
config = uvicorn.Config(self._app, uds=self.uds, log_level="error", reload=False)
|
|
71
62
|
self._server = uvicorn.Server(config)
|
|
72
63
|
|
|
73
64
|
def _run_server(self):
|
|
@@ -77,18 +68,21 @@ class LocalServer:
|
|
|
77
68
|
def start(self):
|
|
78
69
|
if not self._server:
|
|
79
70
|
rich.print(
|
|
80
|
-
f"Starting
|
|
71
|
+
f"Starting Synthetic Data SDK in local mode using [link=file://{self.home_dir} dodger_blue2 underline]file://{self.home_dir}[/]"
|
|
81
72
|
)
|
|
82
73
|
self._create_server()
|
|
83
74
|
self._thread = Thread(target=self._run_server, daemon=True)
|
|
84
75
|
self._thread.start()
|
|
76
|
+
# make sure the socket file is cleaned up on exit
|
|
77
|
+
atexit.register(self._clear_socket_file)
|
|
85
78
|
time.sleep(0.5) # give the server a moment to start
|
|
86
79
|
|
|
87
80
|
def stop(self):
|
|
88
81
|
if self._server and self._server.started:
|
|
89
|
-
rich.print(
|
|
82
|
+
rich.print("Stopping Synthetic Data SDK in local mode")
|
|
90
83
|
self._server.should_exit = True # Signal the server to shut down
|
|
91
84
|
self._thread.join() # Wait for the server thread to finish
|
|
85
|
+
self._clear_socket_file()
|
|
92
86
|
|
|
93
87
|
def __enter__(self):
|
|
94
88
|
# Ensure the server is running
|
|
@@ -102,5 +96,5 @@ class LocalServer:
|
|
|
102
96
|
def __del__(self):
|
|
103
97
|
# Backup cleanup in case `stop` was not called explicitly or via context
|
|
104
98
|
if self._server and self._server.started:
|
|
105
|
-
print(
|
|
99
|
+
print("Automatically shutting down server")
|
|
106
100
|
self.stop()
|
|
@@ -69,15 +69,19 @@ def write_synthetic_dataset_to_json(synthetic_dataset_dir: Path, synthetic_datas
|
|
|
69
69
|
write_to_json(json_file, synthetic_dataset)
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
def create_zip_in_memory(
|
|
72
|
+
def create_zip_in_memory(path: Path, pattern: str = "*") -> BytesIO:
|
|
73
73
|
# Create an in-memory zip file
|
|
74
74
|
zip_buffer = BytesIO()
|
|
75
75
|
with zipfile.ZipFile(zip_buffer, "w") as zip_file:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
#
|
|
80
|
-
|
|
76
|
+
if path.is_dir():
|
|
77
|
+
# Iterate over all files in the directory and subdirectories
|
|
78
|
+
for file_path in path.rglob(pattern):
|
|
79
|
+
if file_path.is_file(): # Ensure it's a file (not a directory)
|
|
80
|
+
# Add file to the zip archive, keeping the directory structure
|
|
81
|
+
zip_file.write(file_path, file_path.relative_to(path))
|
|
82
|
+
else:
|
|
83
|
+
# Add the single file to the zip archive
|
|
84
|
+
zip_file.write(path, path.name)
|
|
81
85
|
# Ensure the buffer is ready for streaming
|
|
82
86
|
zip_buffer.seek(0)
|
|
83
87
|
return zip_buffer
|
|
@@ -65,6 +65,7 @@ def job_wait(
|
|
|
65
65
|
),
|
|
66
66
|
TaskProgressColumn(),
|
|
67
67
|
TimeElapsedColumn(),
|
|
68
|
+
refresh_per_second=1 / interval,
|
|
68
69
|
)
|
|
69
70
|
progress_bars = {
|
|
70
71
|
"overall": progress.add_task(
|
|
@@ -127,6 +128,7 @@ def job_wait(
|
|
|
127
128
|
return
|
|
128
129
|
# check whether we are done
|
|
129
130
|
if job.progress.value >= job.progress.max:
|
|
131
|
+
progress.refresh()
|
|
130
132
|
time.sleep(1) # give the system a moment to update the status
|
|
131
133
|
return
|
|
132
134
|
else:
|
|
@@ -53,9 +53,9 @@ class MostlyAI(_MostlyBaseClient):
|
|
|
53
53
|
Example for instantiating the SDK in local mode:
|
|
54
54
|
```python
|
|
55
55
|
from mostlyai.sdk import MostlyAI
|
|
56
|
-
mostly = MostlyAI(local=True
|
|
56
|
+
mostly = MostlyAI(local=True)
|
|
57
57
|
mostly
|
|
58
|
-
# MostlyAI(
|
|
58
|
+
# MostlyAI(local=True)
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
Example for instantiating the SDK in client mode with explicit arguments:
|
|
@@ -85,8 +85,6 @@ class MostlyAI(_MostlyBaseClient):
|
|
|
85
85
|
api_key: The API key for authenticating. If not provided, it would rely on environment variables.
|
|
86
86
|
local: Whether to run in local mode or not.
|
|
87
87
|
local_dir: The directory to use for local mode. If not provided, `~/mostlyai` will be used.
|
|
88
|
-
local_port: The port to use for local mode. If not provided, a random port will be used.
|
|
89
|
-
local_host: The host to use for local mode. If not provided, then 127.0.0.1 will be used.
|
|
90
88
|
timeout: Timeout for HTTPS requests in seconds.
|
|
91
89
|
ssl_verify: Whether to verify SSL certificates.
|
|
92
90
|
quiet: Whether to suppress rich output.
|
|
@@ -98,8 +96,6 @@ class MostlyAI(_MostlyBaseClient):
|
|
|
98
96
|
api_key: str | None = None,
|
|
99
97
|
local: bool = False,
|
|
100
98
|
local_dir: str | Path | None = None,
|
|
101
|
-
local_port: int | None = None,
|
|
102
|
-
local_host: str | None = None,
|
|
103
99
|
timeout: float = 60.0,
|
|
104
100
|
ssl_verify: bool = True,
|
|
105
101
|
quiet: bool = False,
|
|
@@ -117,27 +113,35 @@ class MostlyAI(_MostlyBaseClient):
|
|
|
117
113
|
from mostlyai import qa # noqa
|
|
118
114
|
except ImportError:
|
|
119
115
|
raise APIError(
|
|
120
|
-
"
|
|
116
|
+
"LOCAL mode requires additional packages to be installed. Run `pip install 'mostlyai[local]'`."
|
|
121
117
|
)
|
|
122
118
|
|
|
123
|
-
self.local = LocalServer(home_dir=local_dir
|
|
119
|
+
self.local = LocalServer(home_dir=local_dir)
|
|
124
120
|
base_url = self.local.base_url
|
|
125
121
|
api_key = "local"
|
|
122
|
+
uds = self.local.uds
|
|
123
|
+
else:
|
|
124
|
+
uds = None
|
|
126
125
|
|
|
127
|
-
super().__init__(base_url=base_url, api_key=api_key, timeout=timeout, ssl_verify=ssl_verify)
|
|
128
126
|
client_kwargs = {
|
|
129
|
-
"base_url":
|
|
130
|
-
"api_key":
|
|
131
|
-
"
|
|
132
|
-
"
|
|
127
|
+
"base_url": base_url,
|
|
128
|
+
"api_key": api_key,
|
|
129
|
+
"uds": uds,
|
|
130
|
+
"timeout": timeout,
|
|
131
|
+
"ssl_verify": ssl_verify,
|
|
133
132
|
}
|
|
133
|
+
super().__init__(**client_kwargs)
|
|
134
134
|
self.connectors = _MostlyConnectorsClient(**client_kwargs)
|
|
135
135
|
self.generators = _MostlyGeneratorsClient(**client_kwargs)
|
|
136
136
|
self.synthetic_datasets = _MostlySyntheticDatasetsClient(**client_kwargs)
|
|
137
137
|
self.synthetic_probes = _MostlySyntheticProbesClient(**client_kwargs)
|
|
138
138
|
try:
|
|
139
|
+
if local:
|
|
140
|
+
msg = "Connected to Synthetic Data SDK in local mode"
|
|
141
|
+
else:
|
|
142
|
+
msg = f"Connected to [link={self.base_url} dodger_blue2 underline]{self.base_url}[/]"
|
|
139
143
|
version = self.about().version
|
|
140
|
-
msg
|
|
144
|
+
msg += f" ({version})"
|
|
141
145
|
email = self.me().email
|
|
142
146
|
if email:
|
|
143
147
|
msg += f" as [bold]{email}[/bold]"
|
|
@@ -146,8 +150,11 @@ class MostlyAI(_MostlyBaseClient):
|
|
|
146
150
|
rich.print(f"Failed to connect to {self.base_url}: {e}.")
|
|
147
151
|
|
|
148
152
|
def __repr__(self) -> str:
|
|
149
|
-
|
|
150
|
-
|
|
153
|
+
if self.local:
|
|
154
|
+
return "MostlyAI(local=True)"
|
|
155
|
+
else:
|
|
156
|
+
api_key = "'***'" if self.api_key else "None"
|
|
157
|
+
return f"MostlyAI(base_url='{self.base_url}', api_key={api_key})"
|
|
151
158
|
|
|
152
159
|
def connect(
|
|
153
160
|
self,
|
|
@@ -63,11 +63,14 @@ class _MostlyBaseClient:
|
|
|
63
63
|
self,
|
|
64
64
|
base_url: str | None = None,
|
|
65
65
|
api_key: str | None = None,
|
|
66
|
+
uds: str | None = None,
|
|
66
67
|
timeout: float = 60.0,
|
|
67
68
|
ssl_verify: bool = True,
|
|
68
69
|
):
|
|
69
70
|
self.base_url = (base_url or os.getenv("MOSTLY_BASE_URL") or DEFAULT_BASE_URL).rstrip("/")
|
|
70
71
|
self.api_key = api_key or os.getenv("MOSTLY_API_KEY")
|
|
72
|
+
self.local = uds is not None
|
|
73
|
+
self.transport = httpx.HTTPTransport(uds=uds) if uds else None
|
|
71
74
|
self.timeout = timeout
|
|
72
75
|
self.ssl_verify = ssl_verify
|
|
73
76
|
if not self.api_key:
|
|
@@ -137,7 +140,7 @@ class _MostlyBaseClient:
|
|
|
137
140
|
kwargs["params"] = map_snake_to_camel_case(kwargs["params"])
|
|
138
141
|
|
|
139
142
|
try:
|
|
140
|
-
with httpx.Client(timeout=self.timeout, verify=self.ssl_verify) as client:
|
|
143
|
+
with httpx.Client(timeout=self.timeout, verify=self.ssl_verify, transport=self.transport) as client:
|
|
141
144
|
response = client.request(method=verb, url=full_url, **kwargs)
|
|
142
145
|
response.raise_for_status()
|
|
143
146
|
except httpx.HTTPStatusError as exc:
|
|
@@ -126,7 +126,10 @@ class _MostlyConnectorsClient(_MostlyBaseClient):
|
|
|
126
126
|
response_type=Connector,
|
|
127
127
|
)
|
|
128
128
|
cid = connector.id
|
|
129
|
-
|
|
129
|
+
if self.local:
|
|
130
|
+
rich.print(f"Created connector [dodger_blue2]{cid}[/]")
|
|
131
|
+
else:
|
|
132
|
+
rich.print(f"Created connector [link={self.base_url}/d/connectors/{cid} dodger_blue2 underline]{cid}[/]")
|
|
130
133
|
return connector
|
|
131
134
|
|
|
132
135
|
# PRIVATE METHODS #
|
|
@@ -172,7 +172,10 @@ class _MostlyGeneratorsClient(_MostlyBaseClient):
|
|
|
172
172
|
table["columns"] = [{"name": col} if isinstance(col, str) else col for col in table["columns"]]
|
|
173
173
|
generator = self.request(verb=POST, path=[], json=config, response_type=Generator)
|
|
174
174
|
gid = generator.id
|
|
175
|
-
|
|
175
|
+
if self.local:
|
|
176
|
+
rich.print(f"Created generator [dodger_blue2]{gid}[/]")
|
|
177
|
+
else:
|
|
178
|
+
rich.print(f"Created generator [link={self.base_url}/d/generators/{gid} dodger_blue2 underline]{gid}[/]")
|
|
176
179
|
return generator
|
|
177
180
|
|
|
178
181
|
def import_from_file(
|
|
@@ -206,7 +209,10 @@ class _MostlyGeneratorsClient(_MostlyBaseClient):
|
|
|
206
209
|
response_type=Generator,
|
|
207
210
|
)
|
|
208
211
|
gid = generator.id
|
|
209
|
-
|
|
212
|
+
if self.local:
|
|
213
|
+
rich.print(f"Imported generator [dodger_blue2]{gid}[/]")
|
|
214
|
+
else:
|
|
215
|
+
rich.print(f"Imported generator [link={self.base_url}/d/generators/{gid} dodger_blue2 underline]{gid}[/]")
|
|
210
216
|
return generator
|
|
211
217
|
|
|
212
218
|
# PRIVATE METHODS #
|
|
@@ -293,3 +299,20 @@ class _MostlyGeneratorsClient(_MostlyBaseClient):
|
|
|
293
299
|
job_wait(lambda: self._training_progress(generator_id), interval, progress_bar)
|
|
294
300
|
generator = self.get(generator_id)
|
|
295
301
|
return generator
|
|
302
|
+
|
|
303
|
+
def _training_logs(self, generator_id: str, short_lived_file_token: str | None = None) -> (bytes, str):
|
|
304
|
+
response = self.request(
|
|
305
|
+
verb=GET,
|
|
306
|
+
path=[generator_id, "training", "logs"],
|
|
307
|
+
params={
|
|
308
|
+
"slft": short_lived_file_token,
|
|
309
|
+
},
|
|
310
|
+
headers={
|
|
311
|
+
"Content-Type": "application/zip",
|
|
312
|
+
"Accept": "application/json, text/plain, */*",
|
|
313
|
+
},
|
|
314
|
+
raw_response=True,
|
|
315
|
+
)
|
|
316
|
+
content_bytes = response.content
|
|
317
|
+
filename = f"generator-{generator_id[:8]}-logs.zip"
|
|
318
|
+
return content_bytes, filename
|
|
@@ -158,9 +158,12 @@ class _MostlySyntheticDatasetsClient(_MostlyBaseClient):
|
|
|
158
158
|
)
|
|
159
159
|
sid = synthetic_dataset.id
|
|
160
160
|
gid = synthetic_dataset.generator_id
|
|
161
|
-
|
|
162
|
-
f"Created synthetic dataset [
|
|
163
|
-
|
|
161
|
+
if self.local:
|
|
162
|
+
rich.print(f"Created synthetic dataset [dodger_blue2]{sid}[/] with generator [dodger_blue2]{gid}[/]")
|
|
163
|
+
else:
|
|
164
|
+
rich.print(
|
|
165
|
+
f"Created synthetic dataset [link={self.base_url}/d/synthetic-datasets/{sid} dodger_blue2 underline]{sid}[/] with generator [link={self.base_url}/d/generators/{gid} dodger_blue2 underline]{gid}[/]"
|
|
166
|
+
)
|
|
164
167
|
return synthetic_dataset
|
|
165
168
|
|
|
166
169
|
# PRIVATE METHODS #
|
|
@@ -283,6 +286,23 @@ class _MostlySyntheticDatasetsClient(_MostlyBaseClient):
|
|
|
283
286
|
synthetic_dataset = self.get(synthetic_dataset_id)
|
|
284
287
|
return synthetic_dataset
|
|
285
288
|
|
|
289
|
+
def _generation_logs(self, synthetic_dataset_id: str, short_lived_file_token: str | None = None) -> (bytes, str):
|
|
290
|
+
response = self.request(
|
|
291
|
+
verb=GET,
|
|
292
|
+
path=[synthetic_dataset_id, "generation", "logs"],
|
|
293
|
+
params={
|
|
294
|
+
"slft": short_lived_file_token,
|
|
295
|
+
},
|
|
296
|
+
headers={
|
|
297
|
+
"Content-Type": "application/zip",
|
|
298
|
+
"Accept": "application/json, text/plain, */*",
|
|
299
|
+
},
|
|
300
|
+
raw_response=True,
|
|
301
|
+
)
|
|
302
|
+
content_bytes = response.content
|
|
303
|
+
filename = f"synthetic-dataset-{synthetic_dataset_id[:8]}-logs.zip"
|
|
304
|
+
return content_bytes, filename
|
|
305
|
+
|
|
286
306
|
|
|
287
307
|
class _MostlySyntheticProbesClient(_MostlyBaseClient):
|
|
288
308
|
SECTION = ["synthetic-probes"]
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
# generated by datamodel-codegen:
|
|
16
|
-
# timestamp: 2025-02-
|
|
16
|
+
# timestamp: 2025-02-13T12:18:42+00:00
|
|
17
17
|
|
|
18
18
|
from __future__ import annotations
|
|
19
19
|
|
|
@@ -688,7 +688,7 @@ class AssistantMessage(CustomBaseModel):
|
|
|
688
688
|
id: str | None = Field(None, description="The unique identifier of a assistant message.")
|
|
689
689
|
role: AssistantMessageRole | None = None
|
|
690
690
|
content_type: AssistantMessageContentType | None = Field(None, alias="contentType")
|
|
691
|
-
content: str | None = Field(None, description="The content of a message",
|
|
691
|
+
content: str | None = Field(None, description="The content of a message", min_length=0)
|
|
692
692
|
finish_reason: AssistantMessageFinishReason | None = Field(None, alias="finishReason")
|
|
693
693
|
tokens_consumed: int | None = Field(
|
|
694
694
|
None,
|
|
@@ -705,12 +705,7 @@ class AssistantMessageDelta(CustomBaseModel):
|
|
|
705
705
|
id: str | None = Field(None, description="The unique identifier of a assistant message.")
|
|
706
706
|
role: AssistantMessageRole | None = None
|
|
707
707
|
content_type: AssistantMessageContentType | None = Field(None, alias="contentType")
|
|
708
|
-
delta: str | None = Field(
|
|
709
|
-
None,
|
|
710
|
-
description="The partial content of a message",
|
|
711
|
-
max_length=65000,
|
|
712
|
-
min_length=1,
|
|
713
|
-
)
|
|
708
|
+
delta: str | None = Field(None, description="The partial content of a message", min_length=0)
|
|
714
709
|
finish_reason: AssistantMessageFinishReason | None = Field(None, alias="finishReason")
|
|
715
710
|
tokens_consumed: int | None = Field(
|
|
716
711
|
None,
|
|
@@ -744,7 +739,7 @@ class AssistantMessageConfig(CustomBaseModel):
|
|
|
744
739
|
True,
|
|
745
740
|
description="Whether to stream back partial progress. If set, message deltas will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available, with the stream terminated by a data: [DONE] message.",
|
|
746
741
|
)
|
|
747
|
-
content: str | None = Field(None, description="The content of a message",
|
|
742
|
+
content: str | None = Field(None, description="The content of a message", min_length=0)
|
|
748
743
|
content_type: AssistantMessageContentType | None = Field(None, alias="contentType")
|
|
749
744
|
|
|
750
745
|
|
|
@@ -1644,6 +1639,7 @@ class SourceColumn(CustomBaseModel):
|
|
|
1644
1639
|
name: str = Field(
|
|
1645
1640
|
...,
|
|
1646
1641
|
description="The name of a source column. It must be unique within a source table.",
|
|
1642
|
+
max_length=256,
|
|
1647
1643
|
min_length=1,
|
|
1648
1644
|
)
|
|
1649
1645
|
included: bool | None = Field(
|
|
@@ -1684,6 +1680,7 @@ class SourceColumnConfig(CustomBaseModel):
|
|
|
1684
1680
|
name: str = Field(
|
|
1685
1681
|
...,
|
|
1686
1682
|
description="The name of a source column. It must be unique within a source table.",
|
|
1683
|
+
max_length=256,
|
|
1687
1684
|
min_length=1,
|
|
1688
1685
|
)
|
|
1689
1686
|
model_encoding_type: ModelEncodingType | None = Field(ModelEncodingType.auto, alias="modelEncodingType")
|
|
@@ -2064,6 +2061,7 @@ class SourceTable(CustomBaseModel):
|
|
|
2064
2061
|
name: str = Field(
|
|
2065
2062
|
...,
|
|
2066
2063
|
description="The name of a source table. It must be unique within a generator.",
|
|
2064
|
+
max_length=256,
|
|
2067
2065
|
min_length=1,
|
|
2068
2066
|
)
|
|
2069
2067
|
primary_key: str | None = Field(None, alias="primaryKey", description="The column name of the primary key.")
|
|
@@ -2098,6 +2096,7 @@ class SourceTableConfig(CustomBaseModel):
|
|
|
2098
2096
|
name: str = Field(
|
|
2099
2097
|
...,
|
|
2100
2098
|
description="The name of a source table. It must be unique within a generator.",
|
|
2099
|
+
max_length=256,
|
|
2101
2100
|
min_length=1,
|
|
2102
2101
|
)
|
|
2103
2102
|
source_connector_id: str | None = Field(
|
|
@@ -2128,6 +2127,23 @@ class SourceTableConfig(CustomBaseModel):
|
|
|
2128
2127
|
def convert_data_before(cls, value):
|
|
2129
2128
|
return convert_to_base64(value) if isinstance(value, pd.DataFrame) else value
|
|
2130
2129
|
|
|
2130
|
+
@field_validator("columns", mode="before")
|
|
2131
|
+
@classmethod
|
|
2132
|
+
def filter_excluded_columns(cls, columns):
|
|
2133
|
+
if columns is None or not isinstance(columns, list):
|
|
2134
|
+
return columns
|
|
2135
|
+
included_columns = []
|
|
2136
|
+
for column in columns:
|
|
2137
|
+
is_included = any(
|
|
2138
|
+
(
|
|
2139
|
+
isinstance(column, dict) and bool(column.get("included", True)),
|
|
2140
|
+
isinstance(column, SourceColumn) and column.included,
|
|
2141
|
+
)
|
|
2142
|
+
)
|
|
2143
|
+
if is_included:
|
|
2144
|
+
included_columns.append(column)
|
|
2145
|
+
return included_columns
|
|
2146
|
+
|
|
2131
2147
|
@model_validator(mode="after")
|
|
2132
2148
|
@classmethod
|
|
2133
2149
|
def add_model_configuration(cls, values):
|
|
@@ -2148,11 +2164,11 @@ class SourceTableConfig(CustomBaseModel):
|
|
|
2148
2164
|
for fk in values.foreign_keys:
|
|
2149
2165
|
if fk.is_context:
|
|
2150
2166
|
has_tabular_model = True
|
|
2151
|
-
#
|
|
2167
|
+
# Remove model configurations that are not applicable for the model type
|
|
2152
2168
|
if values.tabular_model_configuration and not has_tabular_model:
|
|
2153
|
-
|
|
2169
|
+
values.tabular_model_configuration = None
|
|
2154
2170
|
if values.language_model_configuration and not has_language_model:
|
|
2155
|
-
|
|
2171
|
+
values.language_model_configuration = None
|
|
2156
2172
|
# Add default model configurations if none were provided
|
|
2157
2173
|
if has_tabular_model and not values.tabular_model_configuration:
|
|
2158
2174
|
default_model = "MOSTLY_AI/Medium"
|
|
@@ -2216,6 +2232,7 @@ class SourceTablePatchConfig(CustomBaseModel):
|
|
|
2216
2232
|
name: str | None = Field(
|
|
2217
2233
|
None,
|
|
2218
2234
|
description="The name of a source table. It must be unique within a generator.",
|
|
2235
|
+
max_length=256,
|
|
2219
2236
|
min_length=1,
|
|
2220
2237
|
)
|
|
2221
2238
|
primary_key: str | None = Field(None, alias="primaryKey", description="The column name of the primary key.")
|
|
@@ -2240,6 +2257,7 @@ class SourceTableAddConfig(CustomBaseModel):
|
|
|
2240
2257
|
name: str | None = Field(
|
|
2241
2258
|
None,
|
|
2242
2259
|
description="The name of a source table. It must be unique within a generator.",
|
|
2260
|
+
max_length=256,
|
|
2243
2261
|
min_length=1,
|
|
2244
2262
|
)
|
|
2245
2263
|
include_children: bool | None = Field(
|
|
@@ -2283,6 +2301,7 @@ class SyntheticTable(CustomBaseModel):
|
|
|
2283
2301
|
name: str = Field(
|
|
2284
2302
|
...,
|
|
2285
2303
|
description="The name of a source table. It must be unique within a generator.",
|
|
2304
|
+
max_length=256,
|
|
2286
2305
|
min_length=1,
|
|
2287
2306
|
)
|
|
2288
2307
|
configuration: SyntheticTableConfiguration | None = None
|
|
@@ -2473,15 +2492,19 @@ class Generator(CustomBaseModel):
|
|
|
2473
2492
|
"""
|
|
2474
2493
|
return self.client._clone(generator_id=self.id, training_status=training_status)
|
|
2475
2494
|
|
|
2476
|
-
def reports(self, file_path: str | Path | None = None) -> Path:
|
|
2495
|
+
def reports(self, file_path: str | Path | None = None, display: bool = False) -> Path | None:
|
|
2477
2496
|
"""
|
|
2478
|
-
Download the quality assurance reports
|
|
2497
|
+
Download or display the quality assurance reports.
|
|
2498
|
+
|
|
2499
|
+
If display is True, the report is rendered inline via IPython display and no file is downloaded.
|
|
2500
|
+
Otherwise, the report is downloaded and saved to file_path (or a default location if None).
|
|
2479
2501
|
|
|
2480
2502
|
Args:
|
|
2481
|
-
file_path: The file path to save the zipped reports.
|
|
2503
|
+
file_path: The file path to save the zipped reports (ignored if display=True).
|
|
2504
|
+
display: If True, render the report inline instead of downloading it.
|
|
2482
2505
|
|
|
2483
2506
|
Returns:
|
|
2484
|
-
The path to the saved file.
|
|
2507
|
+
The path to the saved file if downloading, or None if display=True.
|
|
2485
2508
|
"""
|
|
2486
2509
|
reports = {}
|
|
2487
2510
|
for table in self.tables:
|
|
@@ -2500,15 +2523,31 @@ class Generator(CustomBaseModel):
|
|
|
2500
2523
|
short_lived_file_token=(self.metadata.short_lived_file_token if self.metadata else None),
|
|
2501
2524
|
)
|
|
2502
2525
|
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2526
|
+
if display:
|
|
2527
|
+
if not rich.console._is_jupyter():
|
|
2528
|
+
raise ValueError("Displaying reports is only supported in Jupyter notebooks.")
|
|
2529
|
+
|
|
2530
|
+
import html # noqa
|
|
2531
|
+
|
|
2532
|
+
from IPython.display import HTML, display # noqa
|
|
2533
|
+
|
|
2534
|
+
iframes = ""
|
|
2535
|
+
for content in reports.values():
|
|
2536
|
+
content = html.escape(content, quote=True)
|
|
2537
|
+
iframes += f'<p><iframe srcdoc="{content}" width="100%" height="600"></iframe></p> '
|
|
2538
|
+
|
|
2539
|
+
display(HTML(iframes))
|
|
2540
|
+
return None
|
|
2541
|
+
else:
|
|
2542
|
+
file_path = Path(file_path or ".")
|
|
2543
|
+
if file_path.is_dir():
|
|
2544
|
+
file_path = file_path / f"generator-{self.id[:8]}-reports.zip"
|
|
2545
|
+
if file_path.exists():
|
|
2546
|
+
file_path.unlink()
|
|
2547
|
+
with zipfile.ZipFile(file_path, "w", zipfile.ZIP_DEFLATED) as zip_file:
|
|
2548
|
+
for filename, content in reports.items():
|
|
2549
|
+
zip_file.writestr(filename, content)
|
|
2550
|
+
return file_path
|
|
2512
2551
|
|
|
2513
2552
|
class Training:
|
|
2514
2553
|
def __init__(self, _generator: Generator):
|
|
@@ -2554,6 +2593,28 @@ class Generator(CustomBaseModel):
|
|
|
2554
2593
|
"Publish it so others can do the same."
|
|
2555
2594
|
)
|
|
2556
2595
|
|
|
2596
|
+
def logs(self, file_path: str | Path | None = None) -> Path:
|
|
2597
|
+
"""
|
|
2598
|
+
Download the training logs and save to file.
|
|
2599
|
+
|
|
2600
|
+
Args:
|
|
2601
|
+
file_path: The file path to save the logs.
|
|
2602
|
+
|
|
2603
|
+
Returns:
|
|
2604
|
+
The path to the saved file.
|
|
2605
|
+
"""
|
|
2606
|
+
bytes, filename = self.generator.client._training_logs(
|
|
2607
|
+
generator_id=self.generator.id,
|
|
2608
|
+
short_lived_file_token=(
|
|
2609
|
+
self.generator.metadata.short_lived_file_token if self.generator.metadata else None
|
|
2610
|
+
),
|
|
2611
|
+
)
|
|
2612
|
+
file_path = Path(file_path or ".")
|
|
2613
|
+
if file_path.is_dir():
|
|
2614
|
+
file_path = file_path / filename
|
|
2615
|
+
file_path.write_bytes(bytes)
|
|
2616
|
+
return file_path
|
|
2617
|
+
|
|
2557
2618
|
|
|
2558
2619
|
class GeneratorConfig(CustomBaseModel):
|
|
2559
2620
|
"""
|
|
@@ -2745,15 +2806,19 @@ class SyntheticDataset(CustomBaseModel):
|
|
|
2745
2806
|
else:
|
|
2746
2807
|
return dfs
|
|
2747
2808
|
|
|
2748
|
-
def reports(self, file_path: str | Path | None = None) -> Path:
|
|
2809
|
+
def reports(self, file_path: str | Path | None = None, display: bool = False) -> Path | None:
|
|
2749
2810
|
"""
|
|
2750
|
-
Download the quality assurance reports
|
|
2811
|
+
Download or display the quality assurance reports.
|
|
2812
|
+
|
|
2813
|
+
If display is True, the report is rendered inline via IPython display and no file is downloaded.
|
|
2814
|
+
Otherwise, the report is downloaded and saved to file_path (or a default location if None).
|
|
2751
2815
|
|
|
2752
2816
|
Args:
|
|
2753
|
-
file_path: The file path to save the zipped reports.
|
|
2817
|
+
file_path: The file path to save the zipped reports (ignored if display=True).
|
|
2818
|
+
display: If True, render the report inline instead of downloading it.
|
|
2754
2819
|
|
|
2755
2820
|
Returns:
|
|
2756
|
-
The path to the saved file.
|
|
2821
|
+
The path to the saved file if downloading, or None if display=True.
|
|
2757
2822
|
"""
|
|
2758
2823
|
reports = {}
|
|
2759
2824
|
for report_type in [
|
|
@@ -2779,15 +2844,31 @@ class SyntheticDataset(CustomBaseModel):
|
|
|
2779
2844
|
short_lived_file_token=(self.metadata.short_lived_file_token if self.metadata else None),
|
|
2780
2845
|
)
|
|
2781
2846
|
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2847
|
+
if display:
|
|
2848
|
+
if not rich.console._is_jupyter():
|
|
2849
|
+
raise ValueError("Displaying reports is only supported in Jupyter notebooks.")
|
|
2850
|
+
|
|
2851
|
+
import html # noqa
|
|
2852
|
+
|
|
2853
|
+
from IPython.display import HTML, display # noqa
|
|
2854
|
+
|
|
2855
|
+
iframes = ""
|
|
2856
|
+
for content in reports.values():
|
|
2857
|
+
content = html.escape(content, quote=True)
|
|
2858
|
+
iframes += f'<p><iframe srcdoc="{content}" width="100%" height="600"></iframe></p> '
|
|
2859
|
+
|
|
2860
|
+
display(HTML(iframes))
|
|
2861
|
+
return None
|
|
2862
|
+
else:
|
|
2863
|
+
file_path = Path(file_path or ".")
|
|
2864
|
+
if file_path.is_dir():
|
|
2865
|
+
file_path = file_path / f"synthetic-dataset-{self.id[:8]}-reports.zip"
|
|
2866
|
+
if file_path.exists():
|
|
2867
|
+
file_path.unlink()
|
|
2868
|
+
with zipfile.ZipFile(file_path, "w", zipfile.ZIP_DEFLATED) as zip_file:
|
|
2869
|
+
for filename, content in reports.items():
|
|
2870
|
+
zip_file.writestr(filename, content)
|
|
2871
|
+
return file_path
|
|
2791
2872
|
|
|
2792
2873
|
class Generation:
|
|
2793
2874
|
def __init__(self, _synthetic_dataset: SyntheticDataset):
|
|
@@ -2835,6 +2916,28 @@ class SyntheticDataset(CustomBaseModel):
|
|
|
2835
2916
|
"Publish it so others can do the same."
|
|
2836
2917
|
)
|
|
2837
2918
|
|
|
2919
|
+
def logs(self, file_path: str | Path | None = None) -> Path:
|
|
2920
|
+
"""
|
|
2921
|
+
Download the generation logs and save to file.
|
|
2922
|
+
|
|
2923
|
+
Args:
|
|
2924
|
+
file_path: The file path to save the logs.
|
|
2925
|
+
|
|
2926
|
+
Returns:
|
|
2927
|
+
The path to the saved file.
|
|
2928
|
+
"""
|
|
2929
|
+
bytes, filename = self.synthetic_dataset.client._generation_logs(
|
|
2930
|
+
synthetic_dataset_id=self.synthetic_dataset.id,
|
|
2931
|
+
short_lived_file_token=(
|
|
2932
|
+
self.synthetic_dataset.metadata.short_lived_file_token if self.synthetic_dataset.metadata else None
|
|
2933
|
+
),
|
|
2934
|
+
)
|
|
2935
|
+
file_path = Path(file_path or ".")
|
|
2936
|
+
if file_path.is_dir():
|
|
2937
|
+
file_path = file_path / filename
|
|
2938
|
+
file_path.write_bytes(bytes)
|
|
2939
|
+
return file_path
|
|
2940
|
+
|
|
2838
2941
|
|
|
2839
2942
|
class _SyntheticTableConfigValidation(CustomBaseModel):
|
|
2840
2943
|
"""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "mostlyai"
|
|
3
|
-
version = "4.1.
|
|
3
|
+
version = "4.1.2"
|
|
4
4
|
description = "Synthetic Data SDK"
|
|
5
5
|
authors = [{ name = "MOSTLY AI", email = "dev@mostly.ai" }]
|
|
6
6
|
requires-python = ">=3.10,<3.14"
|
|
@@ -45,6 +45,8 @@ dependencies = [
|
|
|
45
45
|
"sshtunnel>=0.4.0,<0.5",
|
|
46
46
|
"xlsxwriter>=3.1.9,<4",
|
|
47
47
|
"openpyxl>=3.1.5",
|
|
48
|
+
"networkx>=3.0,<4",
|
|
49
|
+
"ipywidgets>=8.1.0",
|
|
48
50
|
# cloud-based connectors
|
|
49
51
|
"s3fs>=2023.1.0,<2024",
|
|
50
52
|
"gcsfs>=2023.1.0,<2024",
|
|
@@ -59,7 +61,7 @@ dependencies = [
|
|
|
59
61
|
local = [
|
|
60
62
|
# local
|
|
61
63
|
"mostlyai-engine==1.0.4",
|
|
62
|
-
"mostlyai-qa==1.5.
|
|
64
|
+
"mostlyai-qa==1.5.5",
|
|
63
65
|
"fastapi>=0.115.6,<0.116",
|
|
64
66
|
"uvicorn>=0.34.0,<0.35",
|
|
65
67
|
"python-multipart>=0.0.20",
|
|
@@ -67,7 +69,7 @@ local = [
|
|
|
67
69
|
]
|
|
68
70
|
local-gpu = [
|
|
69
71
|
"mostlyai-engine[gpu]==1.0.4",
|
|
70
|
-
"mostlyai-qa[gpu]==1.5.
|
|
72
|
+
"mostlyai-qa[gpu]==1.5.5",
|
|
71
73
|
"fastapi>=0.115.6,<0.116",
|
|
72
74
|
"uvicorn>=0.34.0,<0.35",
|
|
73
75
|
"python-multipart>=0.0.20",
|
|
@@ -75,7 +77,7 @@ local-gpu = [
|
|
|
75
77
|
]
|
|
76
78
|
local-cpu = [
|
|
77
79
|
"mostlyai-engine[cpu]==1.0.4",
|
|
78
|
-
"mostlyai-qa[cpu]==1.5.
|
|
80
|
+
"mostlyai-qa[cpu]==1.5.5",
|
|
79
81
|
"fastapi>=0.115.6,<0.116",
|
|
80
82
|
"uvicorn>=0.34.0,<0.35",
|
|
81
83
|
"python-multipart>=0.0.20",
|
|
@@ -104,10 +106,10 @@ dev = [
|
|
|
104
106
|
"vcrpy>=5.1.0,<6",
|
|
105
107
|
"ruff==0.9.2",
|
|
106
108
|
"respx>=0.20.2,<0.21",
|
|
107
|
-
"twine>=6.0
|
|
108
|
-
"pkginfo>=1.12.0,<2",
|
|
109
|
+
"twine>=6.1.0,<7",
|
|
109
110
|
"poetry-bumpversion>=0.3.2,<0.4",
|
|
110
111
|
"httpx<0.28",
|
|
112
|
+
"ipykernel>=6.25.2",
|
|
111
113
|
]
|
|
112
114
|
docs = [
|
|
113
115
|
"mkdocs>=1.5.3",
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_analyze_training_data.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mostlyai-4.1.0 → mostlyai-4.1.2}/mostlyai/sdk/_local/execution/step_encode_training_data.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mostlyai-4.1.0 → mostlyai-4.1.2}/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
|