mostlyai 0.3.6__tar.gz → 0.3.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mostlyai
3
- Version: 0.3.6
3
+ Version: 0.3.8
4
4
  Summary: The official Python client for the MOSTLY AI platform.
5
5
  Home-page: https://app.mostly.ai/
6
6
  License: Proprietary
@@ -0,0 +1,4 @@
1
+ from mostlyai.api import MostlyAI
2
+
3
+ __all__ = ["MostlyAI"]
4
+ __version__ = "0.3.8" # Do not set this manually. Use poetry version [params].
@@ -264,7 +264,14 @@ class MostlyAI(_MostlyBaseClient):
264
264
  :param progress_bar: If true, then the progress bar will be displayed, in case of wait=True
265
265
  :return: The created synthetic dataset.
266
266
  """
267
- config = _harmonize_sd_config(generator, size, seed, config, name)
267
+ config = _harmonize_sd_config(
268
+ generator,
269
+ get_generator=self.generators.get,
270
+ size=size,
271
+ seed=seed,
272
+ config=config,
273
+ name=name,
274
+ )
268
275
  sd = self.synthetic_datasets.create(config)
269
276
  rich.print(
270
277
  f"Created synthetic dataset "
@@ -302,7 +309,13 @@ class MostlyAI(_MostlyBaseClient):
302
309
  :param seed: Optional. Either a single pandas DataFrame data, or a path to a CSV or PARQUET file, or list of samples, or a dictionary of those. Used for seeding the subject table(s).
303
310
  :return: The created synthetic probe.
304
311
  """
305
- config = _harmonize_sd_config(generator, size, seed, config)
312
+ config = _harmonize_sd_config(
313
+ generator,
314
+ get_generator=self.generators.get,
315
+ size=size,
316
+ seed=seed,
317
+ config=config,
318
+ )
306
319
  dfs = self.synthetic_probes.create(config)
307
320
  if return_type == "auto" and len(dfs) == 1:
308
321
  return list(dfs.values())[0]
@@ -1,5 +1,5 @@
1
1
  # generated by datamodel-codegen:
2
- # timestamp: 2024-05-13T11:50:56+00:00
2
+ # timestamp: 2024-05-28T13:04:58+00:00
3
3
 
4
4
  from __future__ import annotations
5
5
 
@@ -123,6 +123,14 @@ class Metadata(CustomBaseModel):
123
123
  current_user_permission_level: Annotated[
124
124
  Optional[PermissionLevel], Field(None, alias="currentUserPermissionLevel")
125
125
  ] = None
126
+ short_lived_file_token: Annotated[
127
+ Optional[str],
128
+ Field(
129
+ None,
130
+ alias="shortLivedFileToken",
131
+ description="An auto-generated short-lived file token (`slft`) for accessing resource artefacts.\nThe token is always restricted to a single resource, only valid for 10 minutes, and \nonly accepted by API endpoints that allow to download single files.\n",
132
+ ),
133
+ ] = None
126
134
 
127
135
 
128
136
  class PaginatedTotalCount(RootModel[int]):
@@ -322,7 +330,7 @@ class GeneratorUsage(CustomBaseModel):
322
330
  Field(
323
331
  None,
324
332
  alias="totalComputeTime",
325
- description="The total compute time in seconds used for training this generator. \nThis is the sum of the compute time of all trained tasks.\n",
333
+ description="The total compute time in seconds used for training this generator.\nThis is the sum of the compute time of all trained tasks.\n",
326
334
  ),
327
335
  ] = None
328
336
  no_of_synthetic_datasets: Annotated[
@@ -372,24 +380,27 @@ class SourceColumnValueRange(CustomBaseModel):
372
380
  min: Annotated[
373
381
  Optional[str],
374
382
  Field(
375
- description="The minimum value of the column. For dates, this is represented in ISO format."
383
+ None,
384
+ description="The minimum value of the column. For dates, this is represented in ISO format.",
376
385
  ),
377
386
  ] = None
378
387
  max: Annotated[
379
388
  Optional[str],
380
389
  Field(
381
- description="The maximum value of the column. For dates, this is represented in ISO format."
390
+ None,
391
+ description="The maximum value of the column. For dates, this is represented in ISO format.",
382
392
  ),
383
393
  ] = None
384
394
  values: Annotated[
385
395
  Optional[List[str]],
386
396
  Field(
387
- description="The list of distinct values of the column. Limited to a maximum of 1000 values."
397
+ None,
398
+ description="The list of distinct values of the column. Limited to a maximum of 1000 values.",
388
399
  ),
389
400
  ] = None
390
401
  has_null: Annotated[
391
402
  Optional[bool],
392
- Field(description="If true, null value was detected within the column."),
403
+ Field(None, description="If true, null value was detected within the column."),
393
404
  ] = None
394
405
 
395
406
 
@@ -404,7 +415,7 @@ class SourceColumn(CustomBaseModel):
404
415
  ]
405
416
  model_encoding_type: Annotated[ModelEncodingType, Field(alias="modelEncodingType")]
406
417
  value_range: Annotated[
407
- Optional[SourceColumnValueRange], Field(alias="valueRange")
418
+ Optional[SourceColumnValueRange], Field(None, alias="valueRange")
408
419
  ] = None
409
420
 
410
421
 
@@ -537,7 +548,7 @@ class ModelConfiguration(CustomBaseModel):
537
548
  Field(
538
549
  "CONSTANT",
539
550
  alias="rareCategoryReplacementMethod",
540
- description="Specifies, if the rare categories for categoricals will be replaced by a constant \n_RARE_ or by a sample from non-rare categories.\n",
551
+ description="Specifies, if the rare categories for categoricals will be replaced by a constant\n_RARE_ or by a sample from non-rare categories.\n",
541
552
  ),
542
553
  ] = "CONSTANT"
543
554
 
@@ -666,7 +677,7 @@ class SyntheticDatasetUsage(CustomBaseModel):
666
677
  Field(
667
678
  None,
668
679
  alias="totalComputeTime",
669
- description="The total compute time in seconds used for generating this synthetic dataset. \nThis is the sum of the compute time of all trained tasks.\n",
680
+ description="The total compute time in seconds used for generating this synthetic dataset.\nThis is the sum of the compute time of all trained tasks.\n",
670
681
  ),
671
682
  ] = None
672
683
  no_of_shares: Annotated[
@@ -729,7 +740,7 @@ class SyntheticTableRebalancing(CustomBaseModel):
729
740
  Optional[Dict[str, float]],
730
741
  Field(
731
742
  None,
732
- description="The target distribution of samples values. \nThe keys are the categorical values, and the values are the probabilities.\n",
743
+ description="The target distribution of samples values.\nThe keys are the categorical values, and the values are the probabilities.\n",
733
744
  examples=[[{"US": 0.8}, {"male": 0.5, "female": 0.5}]],
734
745
  ),
735
746
  ] = None
@@ -754,7 +765,7 @@ class SyntheticTableConfiguration(CustomBaseModel):
754
765
  Field(
755
766
  None,
756
767
  alias="sampleSeedConnectorId",
757
- description="The connector id of the seed data for conditional generation. \nOnly applicable for subject tables.\n",
768
+ description="The connector id of the seed data for conditional generation.\nOnly applicable for subject tables.\n",
758
769
  ),
759
770
  ] = None
760
771
  sample_seed_dict: Annotated[
@@ -868,6 +879,174 @@ class SyntheticDatasetDelivery(CustomBaseModel):
868
879
  ]
869
880
 
870
881
 
882
+ class AssistantLiteLlmExtraItem(CustomBaseModel):
883
+ key: Optional[str] = None
884
+ value: Optional[str] = None
885
+
886
+
887
+ class LiteLlm(CustomBaseModel):
888
+ model: Annotated[
889
+ Optional[str],
890
+ Field(
891
+ None,
892
+ description="The LiteLLM model of the assistant. See https://docs.litellm.ai/docs/providers.",
893
+ examples=[["openai/gpt-3.5-turbo", "mistral/mistral-tiny"]],
894
+ ),
895
+ ] = None
896
+ api_key: Annotated[
897
+ Optional[str],
898
+ Field(
899
+ None,
900
+ alias="apiKey",
901
+ description="The API key for the selected LiteLLM model. See https://docs.litellm.ai/docs/providers.",
902
+ ),
903
+ ] = None
904
+ extra: Annotated[
905
+ Optional[List[AssistantLiteLlmExtraItem]],
906
+ Field(
907
+ None,
908
+ description="Any additional configuration parameters for the selected LiteLLM model. See https://docs.litellm.ai/docs/providers.",
909
+ ),
910
+ ] = None
911
+
912
+
913
+ class DataLlm(CustomBaseModel):
914
+ api_key: Annotated[
915
+ Optional[str],
916
+ Field(
917
+ None,
918
+ alias="apiKey",
919
+ description="The API key for the DataLLM service. See https://data.mostly.ai.",
920
+ ),
921
+ ] = None
922
+
923
+
924
+ class AssistantSettings(CustomBaseModel):
925
+ """
926
+ Additional optional assistant settings used for LiteLLM
927
+ """
928
+
929
+ is_enabled: Annotated[
930
+ Optional[bool],
931
+ Field(
932
+ None, alias="isEnabled", description="If true, the assistant is enabled."
933
+ ),
934
+ ] = None
935
+ lite_llm: Annotated[Optional[LiteLlm], Field(None, alias="liteLlm")] = None
936
+ data_llm: Annotated[Optional[DataLlm], Field(None, alias="dataLlm")] = None
937
+ system_instructions: Annotated[
938
+ Optional[str],
939
+ Field(
940
+ None,
941
+ alias="systemInstructions",
942
+ description="The system instructions of the assistant",
943
+ ),
944
+ ] = None
945
+ custom_instructions: Annotated[
946
+ Optional[str],
947
+ Field(
948
+ None,
949
+ alias="customInstructions",
950
+ description="The custom instructions of the assistant",
951
+ ),
952
+ ] = None
953
+
954
+
955
+ class AssistantThreadSessionStatus(str, Enum):
956
+ pending = "pending"
957
+ active = "active"
958
+ inactive = "inactive"
959
+
960
+
961
+ class AssistantMessageRole(str, Enum):
962
+ """
963
+ The role of the author of this message
964
+ """
965
+
966
+ system = "system"
967
+ user = "user"
968
+ assistant = "assistant"
969
+ tool = "tool"
970
+
971
+
972
+ class AssistantMessageContentType(str, Enum):
973
+ """
974
+ The type of the message content
975
+ """
976
+
977
+ text = "text"
978
+ python = "python"
979
+ console = "console"
980
+
981
+
982
+ class AssistantMessageFinishReason(str, Enum):
983
+ stop = "stop"
984
+ length = "length"
985
+ tool_calls = "tool_calls"
986
+
987
+
988
+ class AssistantMessage(CustomBaseModel):
989
+ """
990
+ A complete message.
991
+ """
992
+
993
+ id: Annotated[
994
+ Optional[str],
995
+ Field(None, description="The unique identifier of a assistant message"),
996
+ ] = None
997
+ role: Optional[AssistantMessageRole] = None
998
+ content_type: Annotated[
999
+ Optional[AssistantMessageContentType], Field(None, alias="contentType")
1000
+ ] = None
1001
+ content: Annotated[
1002
+ Optional[str],
1003
+ Field(
1004
+ None, description="The content of a message", max_length=65000, min_length=1
1005
+ ),
1006
+ ] = None
1007
+ finish_reason: Annotated[
1008
+ Optional[AssistantMessageFinishReason], Field(None, alias="finishReason")
1009
+ ] = None
1010
+
1011
+
1012
+ class AssistantMessageDelta(CustomBaseModel):
1013
+ """
1014
+ A partial message delta generated by streamed model responses.
1015
+ """
1016
+
1017
+ id: Annotated[
1018
+ Optional[str],
1019
+ Field(None, description="The unique identifier of a assistant message"),
1020
+ ] = None
1021
+ role: Optional[AssistantMessageRole] = None
1022
+ content_type: Annotated[
1023
+ Optional[AssistantMessageContentType], Field(None, alias="contentType")
1024
+ ] = None
1025
+ delta: Annotated[
1026
+ Optional[str],
1027
+ Field(
1028
+ None,
1029
+ description="The partial content of a message",
1030
+ max_length=65000,
1031
+ min_length=1,
1032
+ ),
1033
+ ] = None
1034
+ finish_reason: Annotated[
1035
+ Optional[AssistantMessageFinishReason], Field(None, alias="finishReason")
1036
+ ] = None
1037
+
1038
+
1039
+ class AssistantThreadUsage(CustomBaseModel):
1040
+ no_of_shares: Annotated[
1041
+ Optional[int],
1042
+ Field(
1043
+ None,
1044
+ alias="noOfShares",
1045
+ description="Number of shares of this assistant thread.",
1046
+ ),
1047
+ ] = None
1048
+
1049
+
871
1050
  class BaseResource(CustomBaseModel):
872
1051
  id: Annotated[
873
1052
  Optional[str], Field(None, description="The unique identifier of the entity")
@@ -1067,7 +1246,7 @@ class ProgressStep(CustomBaseModel):
1067
1246
  Field(
1068
1247
  None,
1069
1248
  alias="endDate",
1070
- description="The UTC date and time when the job has ended. \nIf the job is still, then this is None.\n",
1249
+ description="The UTC date and time when the job has ended.\nIf the job is still, then this is None.\n",
1071
1250
  examples=["2024-01-25T12:34:56Z"],
1072
1251
  ),
1073
1252
  ] = None
@@ -1151,7 +1330,9 @@ class SyntheticDataset(CustomBaseModel):
1151
1330
  :param file_path: The file path to save the synthetic dataset
1152
1331
  """
1153
1332
  bytes, filename = self.client._download(
1154
- synthetic_dataset_id=self.id, ds_format=format
1333
+ synthetic_dataset_id=self.id,
1334
+ ds_format=format,
1335
+ short_lived_file_token=self.metadata.short_lived_file_token,
1155
1336
  )
1156
1337
  file_path = Path(file_path or ".")
1157
1338
  if file_path.is_dir():
@@ -1167,7 +1348,10 @@ class SyntheticDataset(CustomBaseModel):
1167
1348
 
1168
1349
  :return: The synthetic dataset as dictionary of pandas DataFrames
1169
1350
  """
1170
- dfs = self.client._data(synthetic_dataset_id=self.id)
1351
+ dfs = self.client._data(
1352
+ synthetic_dataset_id=self.id,
1353
+ short_lived_file_token=self.metadata.short_lived_file_token,
1354
+ )
1171
1355
  if return_type == "auto" and len(dfs) == 1:
1172
1356
  return list(dfs.values())[0]
1173
1357
  else:
@@ -1216,6 +1400,37 @@ class SyntheticDataset(CustomBaseModel):
1216
1400
  )
1217
1401
 
1218
1402
 
1403
+ class AssistantThreadListItem(CustomBaseModel):
1404
+ id: Annotated[str, Field(description="The unique identifier of a assistant thread")]
1405
+ metadata: Metadata
1406
+ name: Annotated[
1407
+ Optional[str], Field(None, description="The name of a assistant thread")
1408
+ ] = None
1409
+ usage: Optional[AssistantThreadUsage] = None
1410
+
1411
+
1412
+ class AssistantThread(CustomBaseModel):
1413
+ id: Annotated[
1414
+ Optional[str],
1415
+ Field(None, description="The unique identifier of a assistant thread"),
1416
+ ] = None
1417
+ metadata: Optional[Metadata] = None
1418
+ name: Annotated[
1419
+ Optional[str], Field(None, description="The name of a assistant thread")
1420
+ ] = None
1421
+ session_status: Annotated[
1422
+ Optional[AssistantThreadSessionStatus], Field(None, alias="sessionStatus")
1423
+ ] = None
1424
+ messages: Annotated[
1425
+ Optional[List[AssistantMessage]],
1426
+ Field(
1427
+ None,
1428
+ description="List of all existing messages, excluding any system message.\nExample:\n What's the square root of 9? role: user type: text\n ok, I will write some python role: assistant type: text\n r = math.sqrt(9)\\nr role: assistant type: python\n 3 role: tool type: console\n The answer is 3! role: assistant type: text\n Plot me a random barplot role: user type: text\n ... plt.savefig() ... role: assistant type: python\n Here is ![img]() ... role: assistant type: text\n Write me a random file role: user type: text\n ... .to_csv() ... role: assistant type: python\n Here is [file]() ... role: assistant type: text\n",
1429
+ ),
1430
+ ] = None
1431
+ usage: Optional[AssistantThreadUsage] = None
1432
+
1433
+
1219
1434
  class Share(User):
1220
1435
  permission_level: Annotated[
1221
1436
  Optional[PermissionLevel], Field(None, alias="permissionLevel")
@@ -1348,7 +1563,7 @@ class JobProgress(CustomBaseModel):
1348
1563
  Field(
1349
1564
  None,
1350
1565
  alias="endDate",
1351
- description="The UTC date and time when the job has ended. \nIf the job is still, then this is None.\n",
1566
+ description="The UTC date and time when the job has ended.\nIf the job is still, then this is None.\n",
1352
1567
  examples=["2024-01-25T12:34:56Z"],
1353
1568
  ),
1354
1569
  ] = None
@@ -99,12 +99,17 @@ class _MostlySyntheticDatasetsClient(_MostlyBaseClient):
99
99
  self,
100
100
  synthetic_dataset_id: str,
101
101
  ds_format: SyntheticDatasetFormat = SyntheticDatasetFormat.parquet,
102
+ short_lived_file_token: Optional[str] = None,
102
103
  ) -> (bytes, Optional[str]):
103
- ds_format = ds_format.upper() if isinstance(ds_format, str) else ds_format.value
104
104
  response = self.request(
105
105
  verb=GET,
106
106
  path=[synthetic_dataset_id, "download"],
107
- params={"format": ds_format},
107
+ params={
108
+ "format": ds_format.upper()
109
+ if isinstance(ds_format, str)
110
+ else ds_format.value,
111
+ "slft": short_lived_file_token,
112
+ },
108
113
  headers={
109
114
  "Content-Type": "application/zip",
110
115
  "Accept": "application/json, text/plain, */*",
@@ -120,10 +125,14 @@ class _MostlySyntheticDatasetsClient(_MostlyBaseClient):
120
125
  filename = None
121
126
  return content_bytes, filename
122
127
 
123
- def _data(self, synthetic_dataset_id: str) -> dict[str, pd.DataFrame]:
128
+ def _data(
129
+ self, synthetic_dataset_id: str, short_lived_file_token: Optional[str]
130
+ ) -> dict[str, pd.DataFrame]:
124
131
  # download pqt
125
132
  pqt_zip_bytes, filename = self._download(
126
- synthetic_dataset_id, SyntheticDatasetFormat.parquet
133
+ synthetic_dataset_id=synthetic_dataset_id,
134
+ ds_format=SyntheticDatasetFormat.parquet,
135
+ short_lived_file_token=short_lived_file_token,
127
136
  )
128
137
  # read each parquet file into a pandas dataframe
129
138
  with zipfile.ZipFile(io.BytesIO(pqt_zip_bytes), "r") as z:
@@ -160,31 +160,44 @@ Seed = Union[pd.DataFrame, str, Path, list[dict[str, Any]]]
160
160
 
161
161
  def _harmonize_sd_config(
162
162
  generator: Union[Generator, str, None] = None,
163
+ get_generator: Union[Callable[[str], Generator], None] = None,
163
164
  size: Union[int, dict[str, int], None] = None,
164
165
  seed: Union[Seed, dict[str, Seed], None] = None,
165
166
  config: Union[dict, None] = None,
166
167
  name: Optional[str] = None,
167
168
  ) -> dict:
168
169
  config = config or {}
169
- subject_tables = _get_subject_table_names(generator)
170
+ size = size if size is not None else {}
171
+ seed = seed if seed is not None else {}
170
172
 
171
- # insert generatorId into config
172
173
  if isinstance(generator, Generator):
173
- config["generatorId"] = str(generator.id)
174
+ generator_id = str(generator.id)
174
175
  elif generator is not None:
175
- config["generatorId"] = str(generator)
176
+ generator_id = str(generator)
176
177
  elif "generatorId" not in config:
177
178
  raise ValueError(
178
179
  "Either a generator or a configuration with a generatorId must be provided."
179
180
  )
180
181
 
182
+ if (
183
+ not isinstance(size, dict)
184
+ or not isinstance(seed, dict)
185
+ or "tables" not in config
186
+ ):
187
+ if not isinstance(generator, Generator):
188
+ generator = get_generator(generator_id)
189
+ subject_tables = _get_subject_table_names(generator)
190
+ else:
191
+ subject_tables = []
192
+
193
+ # insert generatorId into config
194
+ config["generatorId"] = generator_id
195
+
181
196
  # normalize size
182
- size = size if size is not None else {}
183
197
  if not isinstance(size, dict):
184
198
  size = {table: size for table in subject_tables}
185
199
 
186
200
  # normalize seed
187
- seed = seed if seed is not None else {}
188
201
  if not isinstance(seed, dict):
189
202
  seed = {table: seed for table in subject_tables}
190
203
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "mostlyai"
3
- version = "0.3.6"
3
+ version = "0.3.8"
4
4
  description = "The official Python client for the MOSTLY AI platform."
5
5
  homepage = "https://app.mostly.ai/"
6
6
  authors = ["MOSTLY AI <office@mostly.ai>"]
@@ -31,6 +31,7 @@ commitizen = "^3.18.0"
31
31
  mkdocs = "^1.5.3"
32
32
  mkdocstrings = "^0.24.1"
33
33
  mkdocs-material = "^9.5.13"
34
+ poetry-bumpversion = "^0.3.2"
34
35
 
35
36
  [tool.mypy]
36
37
  python_version = "3.9"
@@ -51,6 +52,11 @@ version_provider = "poetry"
51
52
  update_changelog_on_bump = true
52
53
  major_version_zero = true
53
54
 
55
+ [[tool.poetry_bumpversion.replacements]]
56
+ files = ["mostlyai/__init__.py"]
57
+ search = '__version__ = "{current_version}"'
58
+ replace = '__version__ = "{new_version}"'
59
+
54
60
  [build-system]
55
61
  requires = ["poetry-core"]
56
62
  build-backend = "poetry.core.masonry.api"
@@ -1,3 +0,0 @@
1
- from mostlyai.api import MostlyAI
2
-
3
- __all__ = ["MostlyAI"]
File without changes
File without changes
File without changes
File without changes