(
knowledge_points: List[str], folder_path: Path, parallel=True, batch_size=3, max_workers=8, cfg: RunConfig = RunConfig()
)
| 758 | |
| 759 | |
| 760 | def run_Code2Video( |
| 761 | knowledge_points: List[str], folder_path: Path, parallel=True, batch_size=3, max_workers=8, cfg: RunConfig = RunConfig() |
| 762 | ): |
| 763 | all_results = [] |
| 764 | |
| 765 | if parallel: |
| 766 | batches = [] |
| 767 | for i in range(0, len(knowledge_points), batch_size): |
| 768 | batch = [(i + j, kp) for j, kp in enumerate(knowledge_points[i : i + batch_size])] |
| 769 | batches.append((i // batch_size, batch, folder_path)) |
| 770 | |
| 771 | print( |
| 772 | f"🔄 Parallel batch processing mode: {len(batches)} batches, each with {batch_size} knowledge points, {max_workers} concurrent batches" |
| 773 | ) |
| 774 | with ProcessPoolExecutor(max_workers=max_workers) as executor: |
| 775 | futures = {executor.submit(process_batch, batch, cfg): batch for batch in batches} |
| 776 | for future in as_completed(futures): |
| 777 | try: |
| 778 | batch_idx, batch_results = future.result() |
| 779 | all_results.extend(batch_results) |
| 780 | print(f"✅ Batch {batch_idx + 1} completed") |
| 781 | except Exception as e: |
| 782 | print(f"❌ Batch {batch_idx + 1} processing failed: {e}") |
| 783 | else: |
| 784 | print("🔄 Serial processing mode") |
| 785 | for idx, kp in enumerate(knowledge_points): |
| 786 | try: |
| 787 | all_results.append(process_knowledge_point(idx, kp, folder_path, cfg)) |
| 788 | except Exception as e: |
| 789 | print(f"❌ Serial processing {kp} failed: {e}") |
| 790 | all_results.append((kp, None, 0, 0)) |
| 791 | |
| 792 | successful_runs = [r for r in all_results if r[1] is not None] |
| 793 | total_runs = len(all_results) |
| 794 | if not successful_runs: |
| 795 | print("\nAll knowledge points failed, cannot calculate average.") |
| 796 | return |
| 797 | |
| 798 | total_duration = sum(r[2] for r in successful_runs) |
| 799 | total_tokens_consumed = sum(r[3] for r in successful_runs) |
| 800 | num_successful = len(successful_runs) |
| 801 | |
| 802 | print("\n" + "=" * 50) |
| 803 | print(f" Total knowledge points: {total_runs}") |
| 804 | print(f" Successfully processed: {num_successful} ({num_successful/total_runs*100:.1f}%)") |
| 805 | print(f" Average duration [min]: {total_duration/num_successful:.2f} minutes/knowledge point") |
| 806 | print(f" Average token consumption: {total_tokens_consumed/num_successful:,.0f} tokens/knowledge point") |
| 807 | print("=" * 50) |
| 808 | |
| 809 | |
| 810 | def get_api_and_output(API_name): |
no test coverage detected