lfx-nightly 0.1.12.dev17__py3-none-any.whl → 0.1.12.dev19__py3-none-any.whl

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.

Potentially problematic release.


This version of lfx-nightly might be problematic. Click here for more details.

@@ -0,0 +1,401 @@
1
+ import secrets
2
+ from datetime import datetime, timedelta, timezone
3
+
4
+ from lfx.custom.custom_component.component import Component
5
+ from lfx.io import Output
6
+ from lfx.schema import Data, DataFrame
7
+ from lfx.schema.message import Message
8
+
9
+
10
+ class MockDataGeneratorComponent(Component):
11
+ """Mock Data Generator Component.
12
+
13
+ Generates sample data for testing and development purposes. Supports three main
14
+ Langflow output types: Message (text), Data (JSON), and DataFrame (tabular data).
15
+
16
+ This component is useful for:
17
+ - Testing workflows without real data sources
18
+ - Prototyping data processing pipelines
19
+ - Creating sample data for demonstrations
20
+ - Development and debugging of Langflow components
21
+ """
22
+
23
+ display_name = "Mock Data Generator"
24
+ description = (
25
+ "Generate sample data for testing and development. "
26
+ "Choose from text messages, JSON data, or tabular data formats."
27
+ )
28
+ icon = "database"
29
+ name = "MockDataGenerator"
30
+
31
+ inputs = []
32
+
33
+ outputs = [
34
+ Output(display_name="DataFrame Output", name="dataframe_output", method="generate_dataframe_output"),
35
+ Output(display_name="Message Output", name="message_output", method="generate_message_output"),
36
+ Output(display_name="Data Output", name="data_output", method="generate_data_output"),
37
+ ]
38
+
39
+ def build(self) -> DataFrame:
40
+ """Default build method - returns DataFrame when component is standalone."""
41
+ return self.generate_dataframe_output()
42
+
43
+ def generate_message_output(self) -> Message:
44
+ """Generate Message output specifically.
45
+
46
+ Returns:
47
+ Message: A Message object containing Lorem Ipsum text
48
+ """
49
+ try:
50
+ self.log("Generating Message mock data")
51
+ message = self._generate_message()
52
+ self.status = f"Generated Lorem Ipsum message ({len(message.text)} characters)"
53
+ except (ValueError, TypeError) as e:
54
+ error_msg = f"Error generating Message data: {e!s}"
55
+ self.log(error_msg)
56
+ self.status = f"Error: {error_msg}"
57
+ return Message(text=f"Error: {error_msg}")
58
+ else:
59
+ return message
60
+
61
+ def generate_data_output(self) -> Data:
62
+ """Generate Data output specifically.
63
+
64
+ Returns:
65
+ Data: A Data object containing sample JSON data (1 record)
66
+ """
67
+ try:
68
+ record_count = 1 # Fixed to 1 record for Data output
69
+ self.log(f"Generating Data mock data with {record_count} record")
70
+ data = self._generate_data(record_count)
71
+ self.status = f"Generated JSON data with {len(data.data.get('records', []))} record(s)"
72
+ except (ValueError, TypeError) as e:
73
+ error_msg = f"Error generating Data: {e!s}"
74
+ self.log(error_msg)
75
+ self.status = f"Error: {error_msg}"
76
+ return Data(data={"error": error_msg, "success": False})
77
+ else:
78
+ return data
79
+
80
+ def generate_dataframe_output(self) -> DataFrame:
81
+ """Generate DataFrame output specifically.
82
+
83
+ Returns:
84
+ DataFrame: A Langflow DataFrame with sample data (50 records)
85
+ """
86
+ try:
87
+ record_count = 50 # Fixed to 50 records for DataFrame output
88
+ self.log(f"Generating DataFrame mock data with {record_count} records")
89
+ return self._generate_dataframe(record_count)
90
+ except (ValueError, TypeError) as e:
91
+ error_msg = f"Error generating DataFrame: {e!s}"
92
+ self.log(error_msg)
93
+
94
+ try:
95
+ import pandas as pd
96
+
97
+ error_df = pd.DataFrame({"error": [error_msg]})
98
+ return DataFrame(error_df)
99
+ except ImportError:
100
+ # Even without pandas, return DataFrame wrapper
101
+ return DataFrame({"error": [error_msg]})
102
+
103
+ def _generate_message(self) -> Message:
104
+ """Generate a sample Message with Lorem Ipsum text.
105
+
106
+ Returns:
107
+ Message: A Message object containing Lorem Ipsum text
108
+ """
109
+ lorem_ipsum_texts = [
110
+ (
111
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor "
112
+ "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud "
113
+ "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
114
+ ),
115
+ (
116
+ "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
117
+ "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
118
+ "mollit anim id est laborum."
119
+ ),
120
+ (
121
+ "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, "
122
+ "totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto "
123
+ "beatae vitae dicta sunt explicabo."
124
+ ),
125
+ (
126
+ "Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, "
127
+ "sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt."
128
+ ),
129
+ (
130
+ "Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, "
131
+ "adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore "
132
+ "magnam aliquam quaerat voluptatem."
133
+ ),
134
+ ]
135
+
136
+ selected_text = secrets.choice(lorem_ipsum_texts)
137
+ return Message(text=selected_text)
138
+
139
+ def _generate_data(self, record_count: int) -> Data:
140
+ """Generate sample Data with JSON structure.
141
+
142
+ Args:
143
+ record_count: Number of records to generate
144
+
145
+ Returns:
146
+ Data: A Data object containing sample JSON data
147
+ """
148
+ # Sample data categories
149
+ companies = [
150
+ "TechCorp",
151
+ "DataSystems",
152
+ "CloudWorks",
153
+ "InnovateLab",
154
+ "DigitalFlow",
155
+ "SmartSolutions",
156
+ "FutureTech",
157
+ "NextGen",
158
+ ]
159
+ departments = ["Engineering", "Sales", "Marketing", "HR", "Finance", "Operations", "Support", "Research"]
160
+ statuses = ["active", "pending", "completed", "cancelled", "in_progress"]
161
+ categories = ["A", "B", "C", "D"]
162
+
163
+ # Generate sample records
164
+ records = []
165
+ base_date = datetime.now(tz=timezone.utc) - timedelta(days=365)
166
+
167
+ for i in range(record_count):
168
+ record = {
169
+ "id": f"REC-{1000 + i}",
170
+ "name": f"Sample Record {i + 1}",
171
+ "company": secrets.choice(companies),
172
+ "department": secrets.choice(departments),
173
+ "status": secrets.choice(statuses),
174
+ "category": secrets.choice(categories),
175
+ "value": round(secrets.randbelow(9901) + 100 + secrets.randbelow(100) / 100, 2),
176
+ "quantity": secrets.randbelow(100) + 1,
177
+ "rating": round(secrets.randbelow(41) / 10 + 1, 1),
178
+ "is_active": secrets.choice([True, False]),
179
+ "created_date": (base_date + timedelta(days=secrets.randbelow(366))).isoformat(),
180
+ "tags": [
181
+ secrets.choice(
182
+ [
183
+ "important",
184
+ "urgent",
185
+ "review",
186
+ "approved",
187
+ "draft",
188
+ "final",
189
+ ]
190
+ )
191
+ for _ in range(secrets.randbelow(3) + 1)
192
+ ],
193
+ }
194
+ records.append(record)
195
+
196
+ # Create the main data structure
197
+ data_structure = {
198
+ "records": records,
199
+ "summary": {
200
+ "total_count": record_count,
201
+ "active_count": sum(1 for r in records if r["is_active"]),
202
+ "total_value": sum(r["value"] for r in records),
203
+ "average_rating": round(sum(r["rating"] for r in records) / record_count, 2),
204
+ "categories": list({r["category"] for r in records}),
205
+ "companies": list({r["company"] for r in records}),
206
+ },
207
+ }
208
+
209
+ return Data(data=data_structure)
210
+
211
+ def _generate_dataframe(self, record_count: int) -> DataFrame:
212
+ """Generate sample DataFrame with realistic business data.
213
+
214
+ Args:
215
+ record_count: Number of rows to generate
216
+
217
+ Returns:
218
+ DataFrame: A Langflow DataFrame with sample data
219
+ """
220
+ try:
221
+ import pandas as pd
222
+
223
+ self.log(f"pandas imported successfully, version: {pd.__version__}")
224
+ except ImportError as e:
225
+ self.log(f"pandas not available: {e!s}, creating simple DataFrame fallback")
226
+ # Create a simple DataFrame-like structure without pandas
227
+ data_result = self._generate_data(record_count)
228
+ # Convert Data to simple DataFrame format
229
+ try:
230
+ # Create a basic DataFrame structure from the Data
231
+ records = data_result.data.get("records", [])
232
+ if records:
233
+ # Use first record to get column names
234
+ columns = list(records[0].keys()) if records else ["error"]
235
+ rows = [list(record.values()) for record in records]
236
+ else:
237
+ columns = ["error"]
238
+ rows = [["pandas not available"]]
239
+
240
+ # Create a simple dict-based DataFrame representation
241
+ simple_df_data = {
242
+ col: [row[i] if i < len(row) else None for row in rows] for i, col in enumerate(columns)
243
+ }
244
+
245
+ # Return as DataFrame wrapper (Langflow will handle the display)
246
+ return DataFrame(simple_df_data)
247
+ except (ValueError, TypeError):
248
+ # Ultimate fallback - return the Data as DataFrame
249
+ return DataFrame({"data": [str(data_result.data)]})
250
+
251
+ try:
252
+ self.log(f"Starting DataFrame generation with {record_count} records")
253
+
254
+ # Sample data for realistic business dataset
255
+ first_names = [
256
+ "John",
257
+ "Jane",
258
+ "Michael",
259
+ "Sarah",
260
+ "David",
261
+ "Emily",
262
+ "Robert",
263
+ "Lisa",
264
+ "William",
265
+ "Jennifer",
266
+ ]
267
+ last_names = [
268
+ "Smith",
269
+ "Johnson",
270
+ "Williams",
271
+ "Brown",
272
+ "Jones",
273
+ "Garcia",
274
+ "Miller",
275
+ "Davis",
276
+ "Rodriguez",
277
+ "Martinez",
278
+ ]
279
+ cities = [
280
+ "New York",
281
+ "Los Angeles",
282
+ "Chicago",
283
+ "Houston",
284
+ "Phoenix",
285
+ "Philadelphia",
286
+ "San Antonio",
287
+ "San Diego",
288
+ "Dallas",
289
+ "San Jose",
290
+ ]
291
+ countries = ["USA", "Canada", "UK", "Germany", "France", "Australia", "Japan", "Brazil", "India", "Mexico"]
292
+ products = [
293
+ "Product A",
294
+ "Product B",
295
+ "Product C",
296
+ "Product D",
297
+ "Product E",
298
+ "Service X",
299
+ "Service Y",
300
+ "Service Z",
301
+ ]
302
+
303
+ # Generate DataFrame data
304
+ data = []
305
+ base_date = datetime.now(tz=timezone.utc) - timedelta(days=365)
306
+
307
+ self.log("Generating row data...")
308
+ for i in range(record_count):
309
+ row = {
310
+ "customer_id": f"CUST-{10000 + i}",
311
+ "first_name": secrets.choice(first_names),
312
+ "last_name": secrets.choice(last_names),
313
+ "email": f"user{i + 1}@example.com",
314
+ "age": secrets.randbelow(63) + 18,
315
+ "city": secrets.choice(cities),
316
+ "country": secrets.choice(countries),
317
+ "product": secrets.choice(products),
318
+ "order_date": (base_date + timedelta(days=secrets.randbelow(366))).strftime("%Y-%m-%d"),
319
+ "order_value": round(secrets.randbelow(991) + 10 + secrets.randbelow(100) / 100, 2),
320
+ "quantity": secrets.randbelow(10) + 1,
321
+ "discount": round(secrets.randbelow(31) / 100, 2),
322
+ "is_premium": secrets.choice([True, False]),
323
+ "satisfaction_score": secrets.randbelow(10) + 1,
324
+ "last_contact": (base_date + timedelta(days=secrets.randbelow(366))).strftime("%Y-%m-%d"),
325
+ }
326
+ data.append(row)
327
+ # Create DataFrame
328
+ self.log("Creating pandas DataFrame...")
329
+ df = pd.DataFrame(data)
330
+ self.log(f"DataFrame created with shape: {df.shape}")
331
+
332
+ # Add calculated columns
333
+ self.log("Adding calculated columns...")
334
+ df["full_name"] = df["first_name"] + " " + df["last_name"]
335
+ df["discounted_value"] = df["order_value"] * (1 - df["discount"])
336
+ df["total_value"] = df["discounted_value"] * df["quantity"]
337
+
338
+ # Age group boundaries as constants
339
+ age_group_18_25 = 25
340
+ age_group_26_35 = 35
341
+ age_group_36_50 = 50
342
+ age_group_51_65 = 65
343
+
344
+ # Create age groups with better error handling
345
+ try:
346
+ df["age_group"] = pd.cut(
347
+ df["age"],
348
+ bins=[
349
+ 0,
350
+ age_group_18_25,
351
+ age_group_26_35,
352
+ age_group_36_50,
353
+ age_group_51_65,
354
+ 100,
355
+ ],
356
+ labels=[
357
+ "18-25",
358
+ "26-35",
359
+ "36-50",
360
+ "51-65",
361
+ "65+",
362
+ ],
363
+ )
364
+ except (ValueError, TypeError) as e:
365
+ self.log(f"Error creating age groups with pd.cut: {e!s}, using simple categorization")
366
+ df["age_group"] = df["age"].apply(
367
+ lambda x: "18-25"
368
+ if x <= age_group_18_25
369
+ else "26-35"
370
+ if x <= age_group_26_35
371
+ else "36-50"
372
+ if x <= age_group_36_50
373
+ else "51-65"
374
+ if x <= age_group_51_65
375
+ else "65+"
376
+ )
377
+
378
+ self.log(f"Successfully generated DataFrame with shape: {df.shape}, columns: {list(df.columns)}")
379
+ # CRITICAL: Use DataFrame wrapper from Langflow
380
+ # DO NOT set self.status when returning DataFrames - it interferes with display
381
+ return DataFrame(df)
382
+
383
+ except (ValueError, TypeError) as e:
384
+ error_msg = f"Error generating DataFrame: {e!s}"
385
+ self.log(error_msg)
386
+ # DO NOT set self.status when returning DataFrames - it interferes with display
387
+ # Return a fallback DataFrame with error info using Langflow wrapper
388
+ try:
389
+ error_df = pd.DataFrame(
390
+ {
391
+ "error": [error_msg],
392
+ "timestamp": [datetime.now(tz=timezone.utc).isoformat()],
393
+ "attempted_records": [record_count],
394
+ }
395
+ )
396
+ return DataFrame(error_df)
397
+ except (ValueError, TypeError) as fallback_error:
398
+ # Last resort: return simple error DataFrame
399
+ self.log(f"Fallback also failed: {fallback_error!s}")
400
+ simple_error_df = pd.DataFrame({"error": [error_msg]})
401
+ return DataFrame(simple_error_df)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lfx-nightly
3
- Version: 0.1.12.dev17
3
+ Version: 0.1.12.dev19
4
4
  Summary: Langflow Executor - A lightweight CLI tool for executing and serving Langflow AI flows
5
5
  Author-email: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
6
6
  Requires-Python: <3.14,>=3.10
@@ -207,6 +207,7 @@ lfx/components/data/csv_to_data.py,sha256=NsNe8rZdkqscnWPynbbd3-svrRj3EEWNaJszjW
207
207
  lfx/components/data/directory.py,sha256=iqINxxy5w60l753zraB-EDpYny8FR6vaa-AgVkdYsLk,3936
208
208
  lfx/components/data/file.py,sha256=mh1Jf0-RwvR5W9rhctlF63DiqNm-o1UICtg9EhQ4peo,26068
209
209
  lfx/components/data/json_to_data.py,sha256=p6MPyUgDvY9aKTL2_2cUGmkeK7baS-G9rkCvzHAnhw8,3571
210
+ lfx/components/data/mock_data.py,sha256=9DAVvi_FfWhlATdWTdMCh95H4P6Mc4gGap0xM1UuQLU,16164
210
211
  lfx/components/data/news_search.py,sha256=m_Ez7ebKlx4Hg5jGjtM4kHwLltnCiqmxDMEDH6dHd4c,6181
211
212
  lfx/components/data/rss.py,sha256=RGUB2Iz07Du7p_GOm84W-i2uqDfG6DOc0IQdTKNQsjY,2487
212
213
  lfx/components/data/sql_executor.py,sha256=sN1lWM65O_pCfZxNAzgjtZmcTPGBLqMud2_7nFv-kpM,3726
@@ -717,7 +718,7 @@ lfx/utils/schemas.py,sha256=NbOtVQBrn4d0BAu-0H_eCTZI2CXkKZlRY37XCSmuJwc,3865
717
718
  lfx/utils/util.py,sha256=xGR32XDRr_TtruhjnXfI7lEWmk-vgywHAy3kz5SBowc,15725
718
719
  lfx/utils/util_strings.py,sha256=nU_IcdphNaj6bAPbjeL-c1cInQPfTBit8mp5Y57lwQk,1686
719
720
  lfx/utils/version.py,sha256=cHpbO0OJD2JQAvVaTH_6ibYeFbHJV0QDHs_YXXZ-bT8,671
720
- lfx_nightly-0.1.12.dev17.dist-info/METADATA,sha256=pSxVkQBQGicCBtp7pePa9ZSKfzP1aXpXK9P84qPK1iI,8068
721
- lfx_nightly-0.1.12.dev17.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
722
- lfx_nightly-0.1.12.dev17.dist-info/entry_points.txt,sha256=1724p3RHDQRT2CKx_QRzEIa7sFuSVO0Ux70YfXfoMT4,42
723
- lfx_nightly-0.1.12.dev17.dist-info/RECORD,,
721
+ lfx_nightly-0.1.12.dev19.dist-info/METADATA,sha256=L6pWiI-1d3n3yki0GmLDV31hV_bMPLcgKZaB3Bq2BYs,8068
722
+ lfx_nightly-0.1.12.dev19.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
723
+ lfx_nightly-0.1.12.dev19.dist-info/entry_points.txt,sha256=1724p3RHDQRT2CKx_QRzEIa7sFuSVO0Ux70YfXfoMT4,42
724
+ lfx_nightly-0.1.12.dev19.dist-info/RECORD,,