mostlyai-mock 0.0.1__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_mock-0.0.1/.gitignore +9 -0
- mostlyai_mock-0.0.1/LICENSE +201 -0
- mostlyai_mock-0.0.1/LICENSE_HEADER +13 -0
- mostlyai_mock-0.0.1/PKG-INFO +98 -0
- mostlyai_mock-0.0.1/README.md +79 -0
- mostlyai_mock-0.0.1/mostlyai/mock/__init__.py +18 -0
- mostlyai_mock-0.0.1/mostlyai/mock/core.py +512 -0
- mostlyai_mock-0.0.1/pyproject.toml +55 -0
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
@@ -0,0 +1,13 @@
|
|
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.
|
@@ -0,0 +1,98 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: mostlyai-mock
|
3
|
+
Version: 0.0.1
|
4
|
+
Summary: Synthetic Mock Data
|
5
|
+
Project-URL: homepage, https://github.com/mostly-ai/mostlyai-mock
|
6
|
+
Project-URL: repository, https://github.com/mostly-ai/mostlyai-mock
|
7
|
+
Project-URL: documentation, https://mostly-ai.github.io/mostlyai-mock/
|
8
|
+
Author-email: MOSTLY AI <dev@mostly.ai>
|
9
|
+
License-Expression: Apache-2.0
|
10
|
+
License-File: LICENSE
|
11
|
+
License-File: LICENSE_HEADER
|
12
|
+
Requires-Python: >=3.10
|
13
|
+
Requires-Dist: litellm>=1.67.0
|
14
|
+
Requires-Dist: numpy>=1.26.3
|
15
|
+
Requires-Dist: pandas>=2.0.0
|
16
|
+
Requires-Dist: pyarrow>=14.0.0
|
17
|
+
Requires-Dist: pydantic<3.0.0,>=2.0.0
|
18
|
+
Description-Content-Type: text/markdown
|
19
|
+
|
20
|
+
# Synthetic Mock Data 🔮
|
21
|
+
|
22
|
+
[](https://mostly-ai.github.io/mostlyai-mock/) [](https://pypi.org/project/mostlyai-mock/)   
|
23
|
+
|
24
|
+
Create data out of nothing. Prompt LLMs for Tabular Data.
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
|
28
|
+
The latest release of `mostlyai-mock` can be installed via pip:
|
29
|
+
|
30
|
+
```bash
|
31
|
+
pip install -U mostlyai-mock
|
32
|
+
```
|
33
|
+
|
34
|
+
Note: An API key to a LLM endpoint, with structured response, is required. It is recommended to set such a key as an environment variable (e.g. `OPENAI_API_KEY`, `GEMINI_API_KEY`, etc.). Alternatively, the key needs to be passed to every call to the library iteself via the parameter `api_key`.
|
35
|
+
|
36
|
+
## Quick Start
|
37
|
+
|
38
|
+
### Single Table
|
39
|
+
|
40
|
+
```python
|
41
|
+
from mostlyai import mock
|
42
|
+
|
43
|
+
tables = {
|
44
|
+
"guests": {
|
45
|
+
"description": "Guests of an Alpine ski hotel in Austria",
|
46
|
+
"columns": {
|
47
|
+
"nationality": {"prompt": "2-letter code for the nationality", "dtype": "string"},
|
48
|
+
"name": {"prompt": "first name and last name of the guest", "dtype": "string"},
|
49
|
+
"gender": {"prompt": "gender of the guest; male or female", "dtype": "string"},
|
50
|
+
"age": {"prompt": "age in years; min: 18, max: 80; avg: 25", "dtype": "integer"},
|
51
|
+
"date_of_birth": {"prompt": "date of birth", "dtype": "date"},
|
52
|
+
"checkin_time": {"prompt": "the check in timestamp of the guest; may 2025", "dtype": "datetime"},
|
53
|
+
"is_vip": {"prompt": "is the guest a VIP", "dtype": "boolean"},
|
54
|
+
"price_per_night": {"prompt": "price paid per night, in EUR", "dtype": "float"},
|
55
|
+
},
|
56
|
+
}
|
57
|
+
}
|
58
|
+
df = mock.sample(tables=tables, sample_size=10, model="openai/gpt-4.1-nano")
|
59
|
+
print(df)
|
60
|
+
```
|
61
|
+
|
62
|
+
### Multiple Tables
|
63
|
+
|
64
|
+
```python
|
65
|
+
from mostlyai import mock
|
66
|
+
|
67
|
+
tables = {
|
68
|
+
"guests": {
|
69
|
+
"description": "Guests of an Alpine ski hotel in Austria",
|
70
|
+
"columns": {
|
71
|
+
"id": {"prompt": "the unique id of the guest", "dtype": "integer"},
|
72
|
+
"name": {"prompt": "first name and last name of the guest", "dtype": "string"},
|
73
|
+
},
|
74
|
+
"primary_key": "id",
|
75
|
+
},
|
76
|
+
"purchases": {
|
77
|
+
"description": "Purchases of a Guest during their stay",
|
78
|
+
"columns": {
|
79
|
+
"guest_id": {"prompt": "the guest id for that purchase", "dtype": "integer"},
|
80
|
+
"purchase_id": {"prompt": "the unique id of the purchase", "dtype": "string"},
|
81
|
+
"text": {"prompt": "purchase text description", "dtype": "string"},
|
82
|
+
"amount": {"prompt": "purchase amount in EUR", "dtype": "float"},
|
83
|
+
},
|
84
|
+
"foreign_keys": [
|
85
|
+
{
|
86
|
+
"column": "guest_id",
|
87
|
+
"referenced_table": "guests",
|
88
|
+
"description": "each guest has anywhere between 1 and 10 purchases",
|
89
|
+
}
|
90
|
+
],
|
91
|
+
},
|
92
|
+
}
|
93
|
+
data = mock.sample(tables=tables, sample_size=5, model="openai/gpt-4.1-nano")
|
94
|
+
df_guests = data["guests"]
|
95
|
+
df_purchases = data["purchases"]
|
96
|
+
print(df_guests)
|
97
|
+
print(df_purchases)
|
98
|
+
```
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Synthetic Mock Data 🔮
|
2
|
+
|
3
|
+
[](https://mostly-ai.github.io/mostlyai-mock/) [](https://pypi.org/project/mostlyai-mock/)   
|
4
|
+
|
5
|
+
Create data out of nothing. Prompt LLMs for Tabular Data.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
The latest release of `mostlyai-mock` can be installed via pip:
|
10
|
+
|
11
|
+
```bash
|
12
|
+
pip install -U mostlyai-mock
|
13
|
+
```
|
14
|
+
|
15
|
+
Note: An API key to a LLM endpoint, with structured response, is required. It is recommended to set such a key as an environment variable (e.g. `OPENAI_API_KEY`, `GEMINI_API_KEY`, etc.). Alternatively, the key needs to be passed to every call to the library iteself via the parameter `api_key`.
|
16
|
+
|
17
|
+
## Quick Start
|
18
|
+
|
19
|
+
### Single Table
|
20
|
+
|
21
|
+
```python
|
22
|
+
from mostlyai import mock
|
23
|
+
|
24
|
+
tables = {
|
25
|
+
"guests": {
|
26
|
+
"description": "Guests of an Alpine ski hotel in Austria",
|
27
|
+
"columns": {
|
28
|
+
"nationality": {"prompt": "2-letter code for the nationality", "dtype": "string"},
|
29
|
+
"name": {"prompt": "first name and last name of the guest", "dtype": "string"},
|
30
|
+
"gender": {"prompt": "gender of the guest; male or female", "dtype": "string"},
|
31
|
+
"age": {"prompt": "age in years; min: 18, max: 80; avg: 25", "dtype": "integer"},
|
32
|
+
"date_of_birth": {"prompt": "date of birth", "dtype": "date"},
|
33
|
+
"checkin_time": {"prompt": "the check in timestamp of the guest; may 2025", "dtype": "datetime"},
|
34
|
+
"is_vip": {"prompt": "is the guest a VIP", "dtype": "boolean"},
|
35
|
+
"price_per_night": {"prompt": "price paid per night, in EUR", "dtype": "float"},
|
36
|
+
},
|
37
|
+
}
|
38
|
+
}
|
39
|
+
df = mock.sample(tables=tables, sample_size=10, model="openai/gpt-4.1-nano")
|
40
|
+
print(df)
|
41
|
+
```
|
42
|
+
|
43
|
+
### Multiple Tables
|
44
|
+
|
45
|
+
```python
|
46
|
+
from mostlyai import mock
|
47
|
+
|
48
|
+
tables = {
|
49
|
+
"guests": {
|
50
|
+
"description": "Guests of an Alpine ski hotel in Austria",
|
51
|
+
"columns": {
|
52
|
+
"id": {"prompt": "the unique id of the guest", "dtype": "integer"},
|
53
|
+
"name": {"prompt": "first name and last name of the guest", "dtype": "string"},
|
54
|
+
},
|
55
|
+
"primary_key": "id",
|
56
|
+
},
|
57
|
+
"purchases": {
|
58
|
+
"description": "Purchases of a Guest during their stay",
|
59
|
+
"columns": {
|
60
|
+
"guest_id": {"prompt": "the guest id for that purchase", "dtype": "integer"},
|
61
|
+
"purchase_id": {"prompt": "the unique id of the purchase", "dtype": "string"},
|
62
|
+
"text": {"prompt": "purchase text description", "dtype": "string"},
|
63
|
+
"amount": {"prompt": "purchase amount in EUR", "dtype": "float"},
|
64
|
+
},
|
65
|
+
"foreign_keys": [
|
66
|
+
{
|
67
|
+
"column": "guest_id",
|
68
|
+
"referenced_table": "guests",
|
69
|
+
"description": "each guest has anywhere between 1 and 10 purchases",
|
70
|
+
}
|
71
|
+
],
|
72
|
+
},
|
73
|
+
}
|
74
|
+
data = mock.sample(tables=tables, sample_size=5, model="openai/gpt-4.1-nano")
|
75
|
+
df_guests = data["guests"]
|
76
|
+
df_purchases = data["purchases"]
|
77
|
+
print(df_guests)
|
78
|
+
print(df_purchases)
|
79
|
+
```
|
@@ -0,0 +1,18 @@
|
|
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
|
+
from mostlyai.mock.core import sample
|
16
|
+
|
17
|
+
__all__ = ["sample"]
|
18
|
+
__version__ = "0.0.1" # Do not set this manually. Use poetry version [params].
|
@@ -0,0 +1,512 @@
|
|
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
|
+
from __future__ import annotations
|
16
|
+
|
17
|
+
import json
|
18
|
+
from collections import deque
|
19
|
+
from collections.abc import Generator
|
20
|
+
from enum import Enum
|
21
|
+
|
22
|
+
import litellm
|
23
|
+
import pandas as pd
|
24
|
+
from pydantic import BaseModel, Field, RootModel, create_model, field_validator
|
25
|
+
from tqdm import tqdm
|
26
|
+
|
27
|
+
SYSTEM_PROMPT = f"""
|
28
|
+
You are a specialized synthetic data generator designed to create
|
29
|
+
highly realistic, contextually appropriate data based on schema definitions. Your task is to:
|
30
|
+
|
31
|
+
1. Generate data that strictly adheres to the provided schema constraints (data types, ranges, formats)
|
32
|
+
2. Ensure logical consistency across related tables and foreign key relationships
|
33
|
+
3. Create contextually appropriate values that reflect real-world patterns and distributions
|
34
|
+
4. Produce diverse, non-repetitive data that avoids obvious patterns
|
35
|
+
5. Respect uniqueness constraints and other data integrity rules
|
36
|
+
6. Return well-formatted JSON output that can be directly parsed.
|
37
|
+
7. Don't use markdown formatting.
|
38
|
+
|
39
|
+
For numeric fields, generate realistic distributions rather than random values. For text fields, create contextually \
|
40
|
+
appropriate content. For dates and timestamps, ensure logical chronology. Always maintain referential integrity \
|
41
|
+
across tables.
|
42
|
+
"""
|
43
|
+
|
44
|
+
|
45
|
+
class LLMConfig(BaseModel):
|
46
|
+
model: str
|
47
|
+
api_key: str | None = None
|
48
|
+
|
49
|
+
|
50
|
+
class MockConfig(RootModel[dict[str, "TableConfig"]]):
|
51
|
+
root: dict[str, TableConfig] = Field(..., min_items=1)
|
52
|
+
|
53
|
+
@field_validator("root")
|
54
|
+
@classmethod
|
55
|
+
def validate_consistency_of_relationships(cls, tables: dict[str, TableConfig]) -> dict[str, TableConfig]:
|
56
|
+
for table_name, table_config in tables.items():
|
57
|
+
if not table_config.foreign_keys:
|
58
|
+
continue
|
59
|
+
|
60
|
+
for fk in table_config.foreign_keys:
|
61
|
+
if fk.referenced_table not in tables:
|
62
|
+
raise ValueError(
|
63
|
+
f"Foreign key violation in table '{table_name}': "
|
64
|
+
f"Referenced table '{fk.referenced_table}' does not exist"
|
65
|
+
)
|
66
|
+
|
67
|
+
referenced_config = tables[fk.referenced_table]
|
68
|
+
if not referenced_config.primary_key:
|
69
|
+
raise ValueError(
|
70
|
+
f"Foreign key violation in table '{table_name}': "
|
71
|
+
f"Referenced table '{fk.referenced_table}' has no primary key defined"
|
72
|
+
)
|
73
|
+
|
74
|
+
if fk.column not in table_config.columns:
|
75
|
+
raise ValueError(
|
76
|
+
f"Foreign key violation in table '{table_name}': "
|
77
|
+
f"Column '{fk.column}' does not exist in the schema"
|
78
|
+
)
|
79
|
+
|
80
|
+
fk_field = table_config.columns[fk.column]
|
81
|
+
pk_field = referenced_config.columns[referenced_config.primary_key]
|
82
|
+
if fk_field.dtype != pk_field.dtype:
|
83
|
+
raise ValueError(
|
84
|
+
f"Foreign key violation in table '{table_name}': "
|
85
|
+
f"Column '{fk.column}' type '{fk_field.dtype}' does not match "
|
86
|
+
f"referenced primary key '{referenced_config.primary_key}' type '{pk_field.dtype}'"
|
87
|
+
)
|
88
|
+
|
89
|
+
return tables
|
90
|
+
|
91
|
+
|
92
|
+
class TableConfig(BaseModel):
|
93
|
+
description: str = ""
|
94
|
+
columns: dict[str, ColumnConfig] = Field(..., min_items=1)
|
95
|
+
primary_key: str | None = None
|
96
|
+
foreign_keys: list[ForeignKeyConfig] = Field(default_factory=list, min_length=0, max_length=1)
|
97
|
+
|
98
|
+
|
99
|
+
class ColumnConfig(BaseModel):
|
100
|
+
prompt: str
|
101
|
+
dtype: DType
|
102
|
+
|
103
|
+
|
104
|
+
class DType(str, Enum):
|
105
|
+
INTEGER = "integer"
|
106
|
+
FLOAT = "float"
|
107
|
+
STRING = "string"
|
108
|
+
BOOLEAN = "boolean"
|
109
|
+
DATE = "date"
|
110
|
+
DATETIME = "datetime"
|
111
|
+
|
112
|
+
|
113
|
+
class ForeignKeyConfig(BaseModel):
|
114
|
+
column: str
|
115
|
+
referenced_table: str
|
116
|
+
description: str | None = None
|
117
|
+
|
118
|
+
|
119
|
+
def _sample_table(
|
120
|
+
*,
|
121
|
+
table_name: str,
|
122
|
+
table_config: TableConfig,
|
123
|
+
primary_keys: dict[str, str] | None,
|
124
|
+
sample_size: int | None,
|
125
|
+
context_data: pd.DataFrame | None,
|
126
|
+
temperature: float,
|
127
|
+
top_p: float,
|
128
|
+
batch_size: int,
|
129
|
+
previous_rows_size: int,
|
130
|
+
llm_config: LLMConfig,
|
131
|
+
) -> pd.DataFrame:
|
132
|
+
assert (sample_size is None) != (context_data is None), (
|
133
|
+
"Exactly one of sample_size or context_data must be provided"
|
134
|
+
)
|
135
|
+
if sample_size is None:
|
136
|
+
sample_size = len(context_data)
|
137
|
+
table_rows_generator = _create_table_rows_generator(
|
138
|
+
table_name=table_name,
|
139
|
+
table_config=table_config,
|
140
|
+
primary_keys=primary_keys,
|
141
|
+
sample_size=sample_size,
|
142
|
+
context_data=context_data,
|
143
|
+
temperature=temperature,
|
144
|
+
top_p=top_p,
|
145
|
+
batch_size=batch_size,
|
146
|
+
previous_rows_size=previous_rows_size,
|
147
|
+
llm_config=llm_config,
|
148
|
+
)
|
149
|
+
table_rows_generator = tqdm(table_rows_generator, desc=f"Generating rows for table `{table_name}`".ljust(45))
|
150
|
+
table_df = _convert_table_rows_generator_to_df(table_rows_generator=table_rows_generator, table_config=table_config)
|
151
|
+
return table_df
|
152
|
+
|
153
|
+
|
154
|
+
def _create_table_prompt(
|
155
|
+
*,
|
156
|
+
table_name: str,
|
157
|
+
table_description: str,
|
158
|
+
columns: dict[str, ColumnConfig],
|
159
|
+
primary_keys: dict[str, str] | None,
|
160
|
+
batch_size: int | None,
|
161
|
+
foreign_keys: list[ForeignKeyConfig] | None,
|
162
|
+
context_data: pd.DataFrame | None,
|
163
|
+
previous_rows: list[dict],
|
164
|
+
) -> str:
|
165
|
+
if batch_size is not None:
|
166
|
+
assert foreign_keys is None
|
167
|
+
assert context_data is None
|
168
|
+
else:
|
169
|
+
assert foreign_keys is not None
|
170
|
+
assert context_data is not None
|
171
|
+
assert primary_keys is not None
|
172
|
+
|
173
|
+
# add description
|
174
|
+
prompt = f"# {table_description}\n\n"
|
175
|
+
|
176
|
+
# define table
|
177
|
+
prompt += f"## Table: {table_name}\n\n"
|
178
|
+
|
179
|
+
# add columns specifications
|
180
|
+
prompt += "## Columns Specifications:\n\n"
|
181
|
+
prompt += f"{json.dumps({name: config.model_dump() for name, config in columns.items()}, indent=2)}\n\n"
|
182
|
+
|
183
|
+
# define foreign keys
|
184
|
+
if foreign_keys is not None:
|
185
|
+
prompt += "## Foreign Keys:\n\n"
|
186
|
+
prompt += f"{json.dumps([fk.model_dump() for fk in foreign_keys], indent=2)}\n\n"
|
187
|
+
|
188
|
+
# add previous rows as context to help the LLM generate consistent data
|
189
|
+
if previous_rows:
|
190
|
+
prompt += f"\n## Previous {len(previous_rows)} Rows:\n\n"
|
191
|
+
prompt += json.dumps(previous_rows, indent=2)
|
192
|
+
|
193
|
+
# add context table name, primary key and data
|
194
|
+
if context_data is not None:
|
195
|
+
fk = foreign_keys[0]
|
196
|
+
prompt += f"## Context Table: `{fk.referenced_table}`\n\n"
|
197
|
+
|
198
|
+
prompt += f"## Context Table Primary Key: `{primary_keys[fk.referenced_table]}`\n\n"
|
199
|
+
|
200
|
+
prompt += f"## Context Table Data:\n\n"
|
201
|
+
prompt += f"{context_data.to_json(orient='records', indent=2)}\n\n"
|
202
|
+
|
203
|
+
# add instructions
|
204
|
+
prompt += "\n## Instructions:\n\n"
|
205
|
+
if batch_size is not None:
|
206
|
+
prompt += f"Generate {batch_size} rows for the `{table_name}` table.\n\n"
|
207
|
+
else:
|
208
|
+
prompt += (
|
209
|
+
f"Generate rows for the `{table_name}` table. "
|
210
|
+
f"The Foreign Key column may only contain values from Context Table Data.\n\n"
|
211
|
+
)
|
212
|
+
if previous_rows:
|
213
|
+
prompt += (
|
214
|
+
"Generate new rows that maintain consistency with the previous rows where appropriate. "
|
215
|
+
"Don't pay attention to the number of previous rows; there might have been more generated than provided.\n\n"
|
216
|
+
)
|
217
|
+
prompt += f"Do not use code to generate the data.\n\n"
|
218
|
+
prompt += f"Return the full data as a JSON string.\n"
|
219
|
+
|
220
|
+
return prompt
|
221
|
+
|
222
|
+
|
223
|
+
def _create_table_rows_generator(
|
224
|
+
*,
|
225
|
+
table_name: str,
|
226
|
+
table_config: TableConfig,
|
227
|
+
primary_keys: dict[str, str] | None,
|
228
|
+
sample_size: int,
|
229
|
+
temperature: float,
|
230
|
+
top_p: float,
|
231
|
+
context_data: pd.DataFrame | None,
|
232
|
+
batch_size: int,
|
233
|
+
previous_rows_size: int,
|
234
|
+
llm_config: LLMConfig,
|
235
|
+
) -> Generator[dict]:
|
236
|
+
def create_table_response_format(columns: dict[str, ColumnConfig]) -> BaseModel:
|
237
|
+
dtype_to_pydantic_type = {
|
238
|
+
DType.INTEGER: int,
|
239
|
+
DType.FLOAT: float,
|
240
|
+
DType.STRING: str,
|
241
|
+
DType.BOOLEAN: bool,
|
242
|
+
# response_format has limited support for JSON Schema features
|
243
|
+
# thus we represent dates and datetimes as strings
|
244
|
+
DType.DATE: str,
|
245
|
+
DType.DATETIME: str,
|
246
|
+
}
|
247
|
+
fields = {}
|
248
|
+
for column_name, column_config in columns.items():
|
249
|
+
annotation = dtype_to_pydantic_type[column_config.dtype]
|
250
|
+
fields[column_name] = (annotation, Field(...))
|
251
|
+
TableRow = create_model("TableRow", **fields)
|
252
|
+
TableRows = create_model("TableRows", rows=(list[TableRow], ...))
|
253
|
+
return TableRows
|
254
|
+
|
255
|
+
def yield_rows_from_json_chunks_stream(response: litellm.CustomStreamWrapper) -> Generator[dict]:
|
256
|
+
# starting with dirty buffer is to handle the `{"rows": []}` case
|
257
|
+
buffer = "garbage"
|
258
|
+
rows_json_started = False
|
259
|
+
in_row_json = False
|
260
|
+
for chunk in response:
|
261
|
+
delta = chunk.choices[0].delta.content
|
262
|
+
if delta is None:
|
263
|
+
continue
|
264
|
+
for char in delta:
|
265
|
+
buffer += char
|
266
|
+
if char == "{" and not rows_json_started:
|
267
|
+
# {"rows": [{"name": "Jo\}h\{n"}]}
|
268
|
+
# * <- start of rows json stream
|
269
|
+
rows_json_started = True
|
270
|
+
elif char == "{" and not in_row_json:
|
271
|
+
# {"rows": [{"name": "Jo\}h\{n"}]}
|
272
|
+
# * <- start of single row json stream
|
273
|
+
buffer = "{"
|
274
|
+
in_row_json = True
|
275
|
+
elif char == "}":
|
276
|
+
# {"rows": [{"name": "Jo\}h\{n"}]}
|
277
|
+
# * * * <- any of these
|
278
|
+
try:
|
279
|
+
row = json.loads(buffer)
|
280
|
+
yield row
|
281
|
+
buffer = ""
|
282
|
+
in_row_json = False
|
283
|
+
except json.JSONDecodeError:
|
284
|
+
continue
|
285
|
+
|
286
|
+
def batch_infinitely(data: pd.DataFrame | None) -> Generator[pd.DataFrame | None]:
|
287
|
+
while True:
|
288
|
+
if data is None:
|
289
|
+
yield None
|
290
|
+
else:
|
291
|
+
for i in range(0, len(data), batch_size):
|
292
|
+
yield data.iloc[i : i + batch_size]
|
293
|
+
|
294
|
+
# ensure model supports response_format and json schema
|
295
|
+
supported_params = litellm.get_supported_openai_params(model=llm_config.model)
|
296
|
+
assert "response_format" in supported_params
|
297
|
+
assert litellm.supports_response_schema(llm_config.model), (
|
298
|
+
"The model does not support structured output / JSON mode."
|
299
|
+
)
|
300
|
+
|
301
|
+
litellm_kwargs = {
|
302
|
+
"response_format": create_table_response_format(columns=table_config.columns),
|
303
|
+
"temperature": temperature,
|
304
|
+
"top_p": top_p,
|
305
|
+
"model": llm_config.model,
|
306
|
+
"api_key": llm_config.api_key,
|
307
|
+
"stream": True,
|
308
|
+
}
|
309
|
+
|
310
|
+
yielded_sequences = 0
|
311
|
+
previous_rows = deque(maxlen=previous_rows_size)
|
312
|
+
for context_batch in batch_infinitely(context_data):
|
313
|
+
prompt_kwargs = {
|
314
|
+
"table_name": table_name,
|
315
|
+
"table_description": table_config.description,
|
316
|
+
"columns": table_config.columns,
|
317
|
+
"primary_keys": primary_keys,
|
318
|
+
"batch_size": batch_size if context_batch is None else None,
|
319
|
+
"foreign_keys": table_config.foreign_keys if context_batch is not None else None,
|
320
|
+
"context_data": context_batch if context_batch is not None else None,
|
321
|
+
"previous_rows": list(previous_rows),
|
322
|
+
}
|
323
|
+
prompt = _create_table_prompt(**prompt_kwargs)
|
324
|
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": prompt}]
|
325
|
+
|
326
|
+
response = litellm.completion(messages=messages, **litellm_kwargs)
|
327
|
+
rows_stream = yield_rows_from_json_chunks_stream(response)
|
328
|
+
|
329
|
+
while True:
|
330
|
+
try:
|
331
|
+
row = next(rows_stream)
|
332
|
+
except StopIteration:
|
333
|
+
break # move to next batch
|
334
|
+
previous_rows.append(row)
|
335
|
+
yield row
|
336
|
+
if context_batch is None:
|
337
|
+
# each subject row is considered a single sequence
|
338
|
+
yielded_sequences += 1
|
339
|
+
if yielded_sequences >= sample_size:
|
340
|
+
return # move to next table
|
341
|
+
if context_batch is not None:
|
342
|
+
# for each context_batch, full sequences are generated
|
343
|
+
yielded_sequences += len(context_batch)
|
344
|
+
if yielded_sequences >= sample_size:
|
345
|
+
return # move to next table
|
346
|
+
|
347
|
+
|
348
|
+
def _convert_table_rows_generator_to_df(
|
349
|
+
table_rows_generator: Generator[dict], table_config: TableConfig
|
350
|
+
) -> pd.DataFrame:
|
351
|
+
def align_df_dtypes_with_mock_dtypes(df: pd.DataFrame, columns: dict[str, ColumnConfig]) -> pd.DataFrame:
|
352
|
+
for column_name, column_config in columns.items():
|
353
|
+
if column_config.dtype in [DType.DATE, DType.DATETIME]:
|
354
|
+
# datetime.date, datetime.datetime -> datetime64[ns] / datetime64[ns, tz]
|
355
|
+
df[column_name] = pd.to_datetime(df[column_name], errors="coerce")
|
356
|
+
elif column_config.dtype in [DType.INTEGER, DType.FLOAT]:
|
357
|
+
# int -> int64[pyarrow], float -> double[pyarrow]
|
358
|
+
df[column_name] = pd.to_numeric(df[column_name], errors="coerce", dtype_backend="pyarrow")
|
359
|
+
elif column_config.dtype is DType.BOOLEAN:
|
360
|
+
# bool -> bool
|
361
|
+
df[column_name] = df[column_name].astype(bool)
|
362
|
+
else:
|
363
|
+
# other -> string[pyarrow]
|
364
|
+
df[column_name] = df[column_name].astype("string[pyarrow]")
|
365
|
+
return df
|
366
|
+
|
367
|
+
df = pd.DataFrame(list(table_rows_generator))
|
368
|
+
df = align_df_dtypes_with_mock_dtypes(df, table_config.columns)
|
369
|
+
return df
|
370
|
+
|
371
|
+
|
372
|
+
def _harmonize_sample_size(sample_size: int | dict[str, int], config: MockConfig) -> dict[str, int]:
|
373
|
+
if isinstance(sample_size, int):
|
374
|
+
return {table_name: sample_size for table_name in config.root}
|
375
|
+
|
376
|
+
if sample_size.keys() != config.root.keys():
|
377
|
+
raise ValueError(f"Sample size keys must match table names: {sample_size.keys()} != {config.root.keys()}")
|
378
|
+
return sample_size
|
379
|
+
|
380
|
+
|
381
|
+
def sample(
|
382
|
+
*,
|
383
|
+
tables: dict[str, dict],
|
384
|
+
sample_size: int | dict[str, int] = 10,
|
385
|
+
model: str = "openai/gpt-4.1-nano",
|
386
|
+
api_key: str | None = None,
|
387
|
+
temperature: float = 1.0,
|
388
|
+
top_p: float = 0.95,
|
389
|
+
) -> pd.DataFrame | dict[str, pd.DataFrame]:
|
390
|
+
"""
|
391
|
+
Generate mock data by prompting an LLM.
|
392
|
+
|
393
|
+
Args:
|
394
|
+
tables (dict[str, dict]): The table specifications to generate mock data for. See examples for usage.
|
395
|
+
sample_size (int | dict[str, int]): The number of rows to generate for each subject table.
|
396
|
+
If a single integer is provided, the same number of rows will be generated for each subject table.
|
397
|
+
If a dictionary is provided, the number of rows to generate for each subject table can be specified
|
398
|
+
individually.
|
399
|
+
Default is 10.
|
400
|
+
model (str): The LiteLLM chat completion model to be used. Requires support for structured output / JSON mode.
|
401
|
+
Examples include:
|
402
|
+
- `openai/gpt-4.1-nano` (default)
|
403
|
+
- `openai/gpt-4.1-mini`
|
404
|
+
- `openai/gpt-4.1`
|
405
|
+
- `gemini/gemini-2.0-flash`
|
406
|
+
- `gemini/gemini-2.5-flash-preview-04-17`
|
407
|
+
See https://docs.litellm.ai/docs/providers/ for more options.
|
408
|
+
api_key (str | None): The API key to use for the LLM. If not provided, LiteLLM will take it from the environment variables.
|
409
|
+
temperature (float): The temperature to use for the LLM. Default is 1.0.
|
410
|
+
top_p (float): The top-p value to use for the LLM. Default is 0.95.
|
411
|
+
|
412
|
+
Returns:
|
413
|
+
- pd.DataFrame: A single DataFrame containing the generated mock data, if only one table is provided.
|
414
|
+
- dict[str, pd.DataFrame]: A dictionary containing the generated mock data for each table, if multiple tables are provided.
|
415
|
+
|
416
|
+
Example of single table (without PK):
|
417
|
+
```python
|
418
|
+
from mostlyai import mock
|
419
|
+
|
420
|
+
tables = {
|
421
|
+
"guests": {
|
422
|
+
"description": "Guests of an Alpine ski hotel in Austria",
|
423
|
+
"columns": {
|
424
|
+
"nationality": {"prompt": "2-letter code for the nationality", "dtype": "string"},
|
425
|
+
"name": {"prompt": "first name and last name of the guest", "dtype": "string"},
|
426
|
+
"gender": {"prompt": "gender of the guest; male or female", "dtype": "string"},
|
427
|
+
"age": {"prompt": "age in years; min: 18, max: 80; avg: 25", "dtype": "integer"},
|
428
|
+
"date_of_birth": {"prompt": "date of birth", "dtype": "date"},
|
429
|
+
"checkin_time": {"prompt": "the check in timestamp of the guest; may 2025", "dtype": "datetime"},
|
430
|
+
"is_vip": {"prompt": "is the guest a VIP", "dtype": "boolean"},
|
431
|
+
"price_per_night": {"prompt": "price paid per night, in EUR", "dtype": "float"},
|
432
|
+
},
|
433
|
+
}
|
434
|
+
}
|
435
|
+
df = mock.sample(tables=tables, sample_size=10, model="openai/gpt-4.1-nano")
|
436
|
+
```
|
437
|
+
|
438
|
+
Example of multiple tables (with PK/FK relationships):
|
439
|
+
```python
|
440
|
+
from mostlyai import mock
|
441
|
+
|
442
|
+
tables = {
|
443
|
+
"guests": {
|
444
|
+
"description": "Guests of an Alpine ski hotel in Austria",
|
445
|
+
"columns": {
|
446
|
+
"id": {"prompt": "the unique id of the guest", "dtype": "integer"},
|
447
|
+
"name": {"prompt": "first name and last name of the guest", "dtype": "string"},
|
448
|
+
},
|
449
|
+
"primary_key": "id",
|
450
|
+
},
|
451
|
+
"purchases": {
|
452
|
+
"description": "Purchases of a Guest during their stay",
|
453
|
+
"columns": {
|
454
|
+
"guest_id": {"prompt": "the guest id for that purchase", "dtype": "integer"},
|
455
|
+
"purchase_id": {"prompt": "the unique id of the purchase", "dtype": "string"},
|
456
|
+
"text": {"prompt": "purchase text description", "dtype": "string"},
|
457
|
+
"amount": {"prompt": "purchase amount in EUR", "dtype": "float"},
|
458
|
+
},
|
459
|
+
"foreign_keys": [
|
460
|
+
{
|
461
|
+
"column": "guest_id",
|
462
|
+
"referenced_table": "guests",
|
463
|
+
"description": "each guest has anywhere between 1 and 10 purchases",
|
464
|
+
}
|
465
|
+
],
|
466
|
+
},
|
467
|
+
}
|
468
|
+
data = mock.sample(tables=tables, sample_size=5, model="openai/gpt-4.1-nano")
|
469
|
+
df_guests = data["guests"]
|
470
|
+
df_purchases = data["purchases"]
|
471
|
+
```
|
472
|
+
"""
|
473
|
+
|
474
|
+
config = MockConfig(tables)
|
475
|
+
|
476
|
+
sample_size = _harmonize_sample_size(sample_size, config)
|
477
|
+
primary_keys = {table_name: table_config.primary_key for table_name, table_config in config.root.items()}
|
478
|
+
dfs = {}
|
479
|
+
for table_name, table_config in config.root.items():
|
480
|
+
if len(dfs) == 0:
|
481
|
+
# subject table
|
482
|
+
df = _sample_table(
|
483
|
+
table_name=table_name,
|
484
|
+
table_config=table_config,
|
485
|
+
primary_keys=None,
|
486
|
+
sample_size=sample_size[table_name],
|
487
|
+
context_data=None,
|
488
|
+
temperature=temperature,
|
489
|
+
top_p=top_p,
|
490
|
+
batch_size=20, # generate 20 subjects at a time
|
491
|
+
previous_rows_size=5,
|
492
|
+
llm_config=LLMConfig(model=model, api_key=api_key),
|
493
|
+
)
|
494
|
+
elif len(dfs) == 1:
|
495
|
+
# sequence table
|
496
|
+
df = _sample_table(
|
497
|
+
table_name=table_name,
|
498
|
+
table_config=table_config,
|
499
|
+
primary_keys=primary_keys,
|
500
|
+
sample_size=None,
|
501
|
+
context_data=next(iter(dfs.values())),
|
502
|
+
temperature=temperature,
|
503
|
+
top_p=top_p,
|
504
|
+
batch_size=1, # generate one sequence at a time
|
505
|
+
previous_rows_size=5,
|
506
|
+
llm_config=LLMConfig(model=model, api_key=api_key),
|
507
|
+
)
|
508
|
+
else:
|
509
|
+
raise RuntimeError("Only 1 or 2 table setups are supported for now")
|
510
|
+
dfs[table_name] = df
|
511
|
+
|
512
|
+
return dfs if len(dfs) > 1 else next(iter(dfs.values()))
|
@@ -0,0 +1,55 @@
|
|
1
|
+
[project]
|
2
|
+
name = "mostlyai-mock"
|
3
|
+
version = "0.0.1"
|
4
|
+
description = "Synthetic Mock Data"
|
5
|
+
authors = [{ name = "MOSTLY AI", email = "dev@mostly.ai" }]
|
6
|
+
requires-python = ">=3.10"
|
7
|
+
readme = "README.md"
|
8
|
+
license = "Apache-2.0"
|
9
|
+
dependencies = [
|
10
|
+
"pydantic>=2.0.0,<3.0.0",
|
11
|
+
"numpy>=1.26.3",
|
12
|
+
"pandas>=2.0.0",
|
13
|
+
"pyarrow>=14.0.0",
|
14
|
+
"litellm>=1.67.0",
|
15
|
+
]
|
16
|
+
|
17
|
+
[project.urls]
|
18
|
+
homepage = "https://github.com/mostly-ai/mostlyai-mock"
|
19
|
+
repository = "https://github.com/mostly-ai/mostlyai-mock"
|
20
|
+
documentation = "https://mostly-ai.github.io/mostlyai-mock/"
|
21
|
+
|
22
|
+
[dependency-groups]
|
23
|
+
dev = [
|
24
|
+
"pytest>=8.0",
|
25
|
+
"ruff>=0.11", # sync'ed with .pre-commit-config
|
26
|
+
"pre-commit>=4.0",
|
27
|
+
"twine>=6.1",
|
28
|
+
"ipykernel>=6.25",
|
29
|
+
]
|
30
|
+
docs = [
|
31
|
+
"mkdocs>=1.6",
|
32
|
+
"mkdocstrings[crystal, python]>=0.29",
|
33
|
+
"mkdocs-material>=9.0",
|
34
|
+
"griffe>=1.0",
|
35
|
+
"pymdown-extensions>=10.0",
|
36
|
+
"griffe-fieldz>=0.2",
|
37
|
+
"black>=25.0",
|
38
|
+
]
|
39
|
+
|
40
|
+
[tool.uv]
|
41
|
+
default-groups = ["dev", "docs"]
|
42
|
+
|
43
|
+
[tool.hatch.build.targets.sdist]
|
44
|
+
include = ["mostlyai/mock"]
|
45
|
+
|
46
|
+
[tool.hatch.build.targets.wheel]
|
47
|
+
include = ["mostlyai/mock"]
|
48
|
+
|
49
|
+
[build-system]
|
50
|
+
requires = ["hatchling"]
|
51
|
+
build-backend = "hatchling.build"
|
52
|
+
|
53
|
+
[tool.ruff]
|
54
|
+
target-version = "py310"
|
55
|
+
line-length = 120
|