| 369 | |
| 370 | |
| 371 | def process_data( |
| 372 | questions: Dict[int, Dict], prefix: str = 'data/', num_answers: int = 1 |
| 373 | ) -> List[List[str]]: |
| 374 | time.sleep(1) |
| 375 | for i, q in questions.items(): |
| 376 | timer = time.time() |
| 377 | try: |
| 378 | answers = chatgpt(q['query'], num_answers) |
| 379 | except WillBeSkipped: |
| 380 | time.sleep(random.uniform(1, 5)) |
| 381 | new_chat() |
| 382 | continue |
| 383 | q['chats'] = answers |
| 384 | with open(f'{prefix}.{i}.json', mode='w', encoding='utf8') as file: |
| 385 | # q.pop('query') |
| 386 | json.dump(q, file, indent=2, ensure_ascii=False) |
| 387 | printf(f'Saved at', file.name) |
| 388 | time.sleep(random.uniform(1, 5)) |
| 389 | new_chat() |
| 390 | timer = time.time() - timer |
| 391 | # if timer < 45: |
| 392 | # time.sleep(45 - timer) |
| 393 | |
| 394 | |
| 395 | def read_data(filename: str) -> Dict[int, Dict]: |