-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_sample_data.py
More file actions
303 lines (285 loc) · 12.5 KB
/
create_sample_data.py
File metadata and controls
303 lines (285 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
"""
Create sample conversation data for testing
This script generates a sample conversations.json file in ChatGPT format
"""
import json
from pathlib import Path
from datetime import datetime, timedelta
def create_sample_conversations():
"""Generate sample conversations in ChatGPT export format"""
conversations = []
base_time = datetime.now().timestamp()
# Sample conversation 1: Python programming
conversations.append({
"id": "sample_conv_1",
"title": "Python List Comprehensions",
"create_time": base_time - 86400 * 7, # 7 days ago
"update_time": base_time - 86400 * 7,
"mapping": {
"node_1": {
"id": "node_1",
"message": {
"id": "msg_1",
"author": {"role": "user"},
"create_time": base_time - 86400 * 7,
"content": {
"content_type": "text",
"parts": ["How do I use list comprehensions in Python?"]
}
},
"parent": None,
"children": ["node_2"]
},
"node_2": {
"id": "node_2",
"message": {
"id": "msg_2",
"author": {"role": "assistant"},
"create_time": base_time - 86400 * 7 + 10,
"content": {
"content_type": "text",
"parts": [
"List comprehensions in Python provide a concise way to create lists. "
"Here's the basic syntax:\n\n"
"[expression for item in iterable if condition]\n\n"
"Example:\n"
"squares = [x**2 for x in range(10)]\n"
"# Creates [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]\n\n"
"With condition:\n"
"even_squares = [x**2 for x in range(10) if x % 2 == 0]\n"
"# Creates [0, 4, 16, 36, 64]"
]
}
},
"parent": "node_1",
"children": []
}
}
})
# Sample conversation 2: AI and Machine Learning
conversations.append({
"id": "sample_conv_2",
"title": "Introduction to Neural Networks",
"create_time": base_time - 86400 * 5, # 5 days ago
"update_time": base_time - 86400 * 5,
"mapping": {
"node_1": {
"id": "node_1",
"message": {
"id": "msg_1",
"author": {"role": "user"},
"create_time": base_time - 86400 * 5,
"content": {
"content_type": "text",
"parts": ["Explain how neural networks work"]
}
},
"parent": None,
"children": ["node_2"]
},
"node_2": {
"id": "node_2",
"message": {
"id": "msg_2",
"author": {"role": "assistant"},
"create_time": base_time - 86400 * 5 + 15,
"content": {
"content_type": "text",
"parts": [
"Neural networks are computing systems inspired by biological neural networks. "
"They consist of:\n\n"
"1. **Input Layer**: Receives input data\n"
"2. **Hidden Layers**: Process information through weighted connections\n"
"3. **Output Layer**: Produces final results\n\n"
"Each connection has a weight that gets adjusted during training. "
"The network learns by:\n"
"- Forward propagation: passing data through layers\n"
"- Calculating error: comparing output to expected result\n"
"- Backpropagation: adjusting weights to minimize error\n\n"
"This process repeats thousands of times until the network can make accurate predictions."
]
}
},
"parent": "node_1",
"children": ["node_3"]
},
"node_3": {
"id": "node_3",
"message": {
"id": "msg_3",
"author": {"role": "user"},
"create_time": base_time - 86400 * 5 + 30,
"content": {
"content_type": "text",
"parts": ["What's the difference between CNN and RNN?"]
}
},
"parent": "node_2",
"children": ["node_4"]
},
"node_4": {
"id": "node_4",
"message": {
"id": "msg_4",
"author": {"role": "assistant"},
"create_time": base_time - 86400 * 5 + 45,
"content": {
"content_type": "text",
"parts": [
"Great question! CNNs and RNNs are specialized neural network architectures:\n\n"
"**CNNs (Convolutional Neural Networks):**\n"
"- Best for: Image and video processing\n"
"- Key feature: Convolutional layers that detect patterns (edges, shapes)\n"
"- Use cases: Image classification, object detection, face recognition\n\n"
"**RNNs (Recurrent Neural Networks):**\n"
"- Best for: Sequential data and time series\n"
"- Key feature: Memory of previous inputs (feedback loops)\n"
"- Use cases: Natural language processing, speech recognition, time series prediction\n\n"
"Modern variants include:\n"
"- LSTM/GRU (improved RNNs)\n"
"- Transformers (replacing RNNs for many NLP tasks)"
]
}
},
"parent": "node_3",
"children": []
}
}
})
# Sample conversation 3: Web Development
conversations.append({
"id": "sample_conv_3",
"title": "RESTful API Design Best Practices",
"create_time": base_time - 86400 * 3, # 3 days ago
"update_time": base_time - 86400 * 3,
"mapping": {
"node_1": {
"id": "node_1",
"message": {
"id": "msg_1",
"author": {"role": "user"},
"create_time": base_time - 86400 * 3,
"content": {
"content_type": "text",
"parts": ["What are the best practices for designing a REST API?"]
}
},
"parent": None,
"children": ["node_2"]
},
"node_2": {
"id": "node_2",
"message": {
"id": "msg_2",
"author": {"role": "assistant"},
"create_time": base_time - 86400 * 3 + 12,
"content": {
"content_type": "text",
"parts": [
"Here are key REST API design best practices:\n\n"
"1. **Use Proper HTTP Methods:**\n"
" - GET: Retrieve resources\n"
" - POST: Create resources\n"
" - PUT/PATCH: Update resources\n"
" - DELETE: Remove resources\n\n"
"2. **Meaningful URLs:**\n"
" - Use nouns, not verbs: /users not /getUsers\n"
" - Hierarchical structure: /users/123/orders/456\n"
" - Lowercase and hyphens: /user-profiles\n\n"
"3. **Status Codes:**\n"
" - 200: Success\n"
" - 201: Created\n"
" - 400: Bad request\n"
" - 401: Unauthorized\n"
" - 404: Not found\n"
" - 500: Server error\n\n"
"4. **Versioning:** Include version in URL (/api/v1/users)\n\n"
"5. **Pagination:** For large datasets, use limit/offset or cursor-based\n\n"
"6. **Error Handling:** Return consistent error response format"
]
}
},
"parent": "node_1",
"children": []
}
}
})
# Sample conversation 4: Data Science
conversations.append({
"id": "sample_conv_4",
"title": "Data Cleaning Techniques",
"create_time": base_time - 86400 * 1, # Yesterday
"update_time": base_time - 86400 * 1,
"mapping": {
"node_1": {
"id": "node_1",
"message": {
"id": "msg_1",
"author": {"role": "user"},
"create_time": base_time - 86400 * 1,
"content": {
"content_type": "text",
"parts": ["How do I handle missing data in pandas?"]
}
},
"parent": None,
"children": ["node_2"]
},
"node_2": {
"id": "node_2",
"message": {
"id": "msg_2",
"author": {"role": "assistant"},
"create_time": base_time - 86400 * 1 + 8,
"content": {
"content_type": "text",
"parts": [
"Pandas offers several methods for handling missing data:\n\n"
"**1. Detection:**\n"
"```python\n"
"df.isnull().sum() # Count missing values per column\n"
"df.info() # Overview including null counts\n"
"```\n\n"
"**2. Removal:**\n"
"```python\n"
"df.dropna() # Remove rows with any NaN\n"
"df.dropna(axis=1) # Remove columns with any NaN\n"
"df.dropna(thresh=2) # Keep rows with at least 2 non-NaN values\n"
"```\n\n"
"**3. Filling:**\n"
"```python\n"
"df.fillna(0) # Fill with zero\n"
"df.fillna(df.mean()) # Fill with mean\n"
"df.fillna(method='ffill') # Forward fill\n"
"df.fillna(method='bfill') # Backward fill\n"
"```\n\n"
"Choose based on your data and analysis needs!"
]
}
},
"parent": "node_1",
"children": []
}
}
})
return conversations
def main():
"""Create sample conversations file"""
print("🎨 Creating sample conversation data...")
# Create conversations
conversations = create_sample_conversations()
# Ensure _intake directory exists
intake_dir = Path("_intake")
intake_dir.mkdir(exist_ok=True)
# Save to file
output_file = intake_dir / "sample_conversations.json"
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(conversations, f, indent=2, ensure_ascii=False)
print(f"✅ Created {len(conversations)} sample conversations")
print(f"📁 Saved to: {output_file}")
print(f"\n💡 Next steps:")
print(f" 1. Run: python ingest.py")
print(f" 2. Run: python index.py")
print(f" 3. Run: streamlit run app.py")
if __name__ == "__main__":
main()