feat: add concurrent batch lesson generation

This commit is contained in:
2026-06-16 07:33:29 -06:00
parent 2321b5f68e
commit 8b0e4df43d
3 changed files with 179 additions and 9 deletions

View File

@@ -13,6 +13,8 @@ import PrintBook from './PrintBook.vue'
import UploadDropzone from './UploadDropzone.vue'
import WorkspaceToolbar from './WorkspaceToolbar.vue'
const BATCH_GENERATE_CONCURRENCY = 3
const props = defineProps<{ bookId: string }>()
defineEmits<{ back: [] }>()
@@ -35,6 +37,7 @@ const {
updateDesign,
clearBook,
generateLesson,
generateLessons,
regenerateLesson,
} = useTeachingBook(props.bookId)
@@ -153,15 +156,19 @@ async function handleBatchStart(topics: string[]): Promise<void> {
batchTotal.value = topics.length
batchError.value = null
for (const topic of topics) {
if (batchCancelled.value) break
batchCurrentTopic.value = topic
const result = await generateLesson(topic)
if (!result.ok) {
batchError.value = result.message
break
}
batchDone.value++
const result = await generateLessons(topics, {
concurrency: BATCH_GENERATE_CONCURRENCY,
isCancelled: () => batchCancelled.value,
onTopicStart: (topic) => {
batchCurrentTopic.value = topic
},
onLessonComplete: (count) => {
batchDone.value += count
},
})
if (!result.ok) {
batchError.value = result.message
}
batchRunning.value = false