mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 14:04:50 +00:00
fix(agent): prevent redundant final video chunks in embedding workflow
This commit is contained in:
@@ -395,4 +395,40 @@ describe('Agent Embedding Workflow', () => {
|
|||||||
output: { error: 'AI Service Unavailable' },
|
output: { error: 'AI Service Unavailable' },
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should not create redundant chunks when video exactly matches chunk duration', async () => {
|
||||||
|
mockActivities.getEmbeddingContextActivity.mockResolvedValue({
|
||||||
|
agent: { id: 'b1' },
|
||||||
|
asset: {
|
||||||
|
id: 'a1',
|
||||||
|
mediaType: 'video/mp4',
|
||||||
|
storageKey: { key: 'test.mp4' },
|
||||||
|
media: {
|
||||||
|
duration: 60.0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
chunkDuration: 60.0,
|
||||||
|
chunkOverlap: 5.0,
|
||||||
|
})
|
||||||
|
|
||||||
|
const task = await prisma.workflowTask.create({
|
||||||
|
data: {
|
||||||
|
type: 'ai_embedding',
|
||||||
|
status: 'pending',
|
||||||
|
assetId: 'a1',
|
||||||
|
teamId: 't1',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await agentEmbeddingMedia(task)
|
||||||
|
|
||||||
|
// Verify only 1 chunk was created instead of 2 (0-60 and 55-60)
|
||||||
|
expect(mockActivities.transcodeVideoChunkActivity).toHaveBeenCalledTimes(1)
|
||||||
|
expect(mockActivities.transcodeVideoChunkActivity).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
startTime: 0,
|
||||||
|
endTime: 60,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -154,7 +154,9 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
|
|||||||
|
|
||||||
for (let start = 0.0; start < duration; start += step) {
|
for (let start = 0.0; start < duration; start += step) {
|
||||||
let end = start + limit
|
let end = start + limit
|
||||||
if (end > duration) end = duration
|
if (end >= duration) {
|
||||||
|
end = duration
|
||||||
|
}
|
||||||
|
|
||||||
// Step A: Slice chunk on transcode worker and upload to S3
|
// Step A: Slice chunk on transcode worker and upload to S3
|
||||||
const chunkRes = await executeActivity(transcodeWorkerQueue, transcodeVideoChunkActivity, {
|
const chunkRes = await executeActivity(transcodeWorkerQueue, transcodeVideoChunkActivity, {
|
||||||
@@ -192,6 +194,11 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
|
|||||||
key: chunkKey,
|
key: chunkKey,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If this chunk reached the end of the video, stop to avoid redundant overlapping chunks
|
||||||
|
if (end >= duration) {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user