mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 22:49:30 +00:00
feat: remove all ai transcription related code and schema
This commit is contained in:
@@ -175,7 +175,7 @@ export async function generateEmbeddingActivity(params: GenerateEmbeddingParams)
|
||||
export interface ExtractAiMetadataParams {
|
||||
assetKey: string
|
||||
filePath: string
|
||||
type: 'autofill' | 'transcription'
|
||||
type: 'autofill'
|
||||
isImage: boolean
|
||||
}
|
||||
|
||||
@@ -190,21 +190,7 @@ export async function extractAiMetadataActivity(
|
||||
const tmpDir = path.dirname(params.filePath)
|
||||
|
||||
try {
|
||||
if (params.type === 'transcription') {
|
||||
const targetKey = path.join(aiDir, 'audio.mp3')
|
||||
try {
|
||||
await s3Service.headObject(bucket, targetKey)
|
||||
return [targetKey]
|
||||
} catch {
|
||||
// Not found
|
||||
}
|
||||
|
||||
const outputFile = path.join(tmpDir, 'audio.mp3')
|
||||
await transcodeService.extractAudio(params.filePath, outputFile, '16k')
|
||||
const buffer = fs.readFileSync(outputFile)
|
||||
await s3Service.putObject(bucket, targetKey, buffer, buffer.length, 'audio/mpeg')
|
||||
generatedFiles.push(targetKey)
|
||||
} else if (params.type === 'autofill') {
|
||||
if (params.type === 'autofill') {
|
||||
const targetKey = path.join(aiDir, '1.webp')
|
||||
try {
|
||||
await s3Service.headObject(bucket, targetKey)
|
||||
|
||||
@@ -11,7 +11,7 @@ describe('Task Activities', () => {
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
assetId: 'asset-1',
|
||||
type: WorkflowTaskType.ai_transcription,
|
||||
type: WorkflowTaskType.ai_embedding,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
},
|
||||
})
|
||||
@@ -48,7 +48,7 @@ describe('Task Activities', () => {
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
assetId: 'asset-1',
|
||||
type: WorkflowTaskType.ai_transcription,
|
||||
type: WorkflowTaskType.ai_embedding,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { prisma } from '@/db'
|
||||
import { WorkflowTask, WorkflowTaskStatus, WorkflowTaskType } from '@/generated/prisma/client'
|
||||
import { Executor } from './executor'
|
||||
import { aiTranscriptionMedia } from './workflows/ai-transcription'
|
||||
import { agentEmbeddingMedia } from './workflows/agent-embedding'
|
||||
import { agentAutofillMedia } from './workflows/agent-autofill'
|
||||
import { agentChat } from './workflows/agent-chat'
|
||||
@@ -83,9 +82,6 @@ export class LocalExecutor implements Executor {
|
||||
|
||||
try {
|
||||
switch (task.type) {
|
||||
case WorkflowTaskType.ai_transcription:
|
||||
await aiTranscriptionMedia(task)
|
||||
break
|
||||
case WorkflowTaskType.ai_embedding:
|
||||
await agentEmbeddingMedia(task)
|
||||
break
|
||||
|
||||
@@ -16,9 +16,6 @@ export class TemporalExecutor implements Executor {
|
||||
|
||||
let workflowName: string
|
||||
switch (task.type) {
|
||||
case WorkflowTaskType.ai_transcription:
|
||||
workflowName = 'aiTranscriptionWorkflow'
|
||||
break
|
||||
case WorkflowTaskType.ai_embedding:
|
||||
workflowName = 'agentEmbeddingWorkflow'
|
||||
break
|
||||
|
||||
@@ -2,7 +2,6 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||
import { prisma } from '@/db'
|
||||
import { workflowService } from './workflow'
|
||||
import { WorkflowTaskStatus, WorkflowTaskType } from '@/generated/prisma/client'
|
||||
import { s3Service } from '@/services/s3/s3'
|
||||
|
||||
vi.mock('@/services/s3/s3', () => ({
|
||||
s3Service: {
|
||||
@@ -41,55 +40,6 @@ describe('WorkflowService', () => {
|
||||
workflowService.close()
|
||||
})
|
||||
|
||||
it('should process ai_transcription task locally', async () => {
|
||||
vi.mocked(s3Service.getObject).mockResolvedValue({
|
||||
buffer: Buffer.from('fake data'),
|
||||
contentType: 'audio/mpeg',
|
||||
})
|
||||
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'Transcription Team' },
|
||||
})
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'Transcription Project', teamId: team.id },
|
||||
})
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'test.mp3',
|
||||
storageKey: { create: { key: 'test/test.mp3' } },
|
||||
status: 'uploaded',
|
||||
type: 'file',
|
||||
project: { connect: { id: project.id } },
|
||||
},
|
||||
})
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
assetId: asset.id,
|
||||
type: WorkflowTaskType.ai_transcription,
|
||||
status: WorkflowTaskStatus.pending,
|
||||
},
|
||||
})
|
||||
|
||||
expect(task.id).toBeDefined()
|
||||
|
||||
let completedTask = null
|
||||
for (let i = 0; i < 20; i++) {
|
||||
completedTask = await prisma.workflowTask.findUnique({
|
||||
where: { id: task.id },
|
||||
})
|
||||
if (completedTask?.status === WorkflowTaskStatus.completed) {
|
||||
break
|
||||
}
|
||||
if (completedTask?.status === WorkflowTaskStatus.failed) {
|
||||
throw new Error(`Task failed: ${JSON.stringify(completedTask.output)}`)
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 500))
|
||||
}
|
||||
|
||||
expect(completedTask?.status).toBe(WorkflowTaskStatus.completed)
|
||||
}, 15000)
|
||||
|
||||
it('should process ai_embedding task locally', async () => {
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'Embedding Team' },
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
import { ApplicationFailure } from '@temporalio/workflow'
|
||||
import type { WorkflowTask } from '@/generated/prisma/client'
|
||||
import {
|
||||
getActivities,
|
||||
executeActivity,
|
||||
TaskQueueDb,
|
||||
TaskQueueTranscode,
|
||||
sleep,
|
||||
} from '../workflow-utils'
|
||||
|
||||
export async function aiTranscriptionMedia(task: WorkflowTask): Promise<void> {
|
||||
const {
|
||||
updateTaskStatusActivity,
|
||||
getAssetActivity,
|
||||
extractAiMetadataActivity,
|
||||
createCommentActivity,
|
||||
updateCommentActivity,
|
||||
getTranscodeWorkerQueueActivity,
|
||||
downloadMediaToTmpActivity,
|
||||
cleanupTmpDirActivity,
|
||||
} = getActivities()
|
||||
|
||||
let placeholderCommentId: string | undefined
|
||||
let tmpDir: string | undefined
|
||||
let transcodeWorkerQueue: string | undefined
|
||||
|
||||
try {
|
||||
// Update status to processing
|
||||
await executeActivity(TaskQueueDb, updateTaskStatusActivity, {
|
||||
taskId: task.id,
|
||||
status: 'processing',
|
||||
})
|
||||
|
||||
// 0. Create Placeholder Comment
|
||||
const payload = task.payload
|
||||
const placeholder = await executeActivity(TaskQueueDb, createCommentActivity, {
|
||||
assetId: task.assetId,
|
||||
message: '__TRANSCRIPTION__',
|
||||
sessionId: payload?.agent?.sessionId || task.id,
|
||||
agentId: payload?.agent?.agentId || 'default',
|
||||
})
|
||||
placeholderCommentId = placeholder.id
|
||||
|
||||
// 1. Get Asset
|
||||
const asset = await executeActivity(TaskQueueDb, getAssetActivity, task.assetId)
|
||||
const key = asset?.storageKey?.key
|
||||
if (!asset || !key) {
|
||||
throw ApplicationFailure.create({ message: 'Asset not found', nonRetryable: true })
|
||||
}
|
||||
|
||||
// 2. Extract Audio (Requires FFmpeg)
|
||||
transcodeWorkerQueue = await executeActivity(
|
||||
TaskQueueTranscode,
|
||||
getTranscodeWorkerQueueActivity,
|
||||
)
|
||||
|
||||
const download = await executeActivity(transcodeWorkerQueue, downloadMediaToTmpActivity, {
|
||||
assetKey: key,
|
||||
})
|
||||
const { filePath } = download
|
||||
tmpDir = download.tmpDir
|
||||
|
||||
const generatedFiles = await executeActivity(transcodeWorkerQueue, extractAiMetadataActivity, {
|
||||
assetKey: key,
|
||||
filePath,
|
||||
type: 'transcription',
|
||||
isImage: false,
|
||||
})
|
||||
|
||||
if (generatedFiles.length === 0) {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'Failed to extract audio for transcription',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
// Simulate work
|
||||
await sleep(2000)
|
||||
|
||||
// 7. Update Placeholder Comment
|
||||
if (placeholderCommentId) {
|
||||
await executeActivity(TaskQueueDb, updateCommentActivity, {
|
||||
commentId: placeholderCommentId,
|
||||
message: 'Transcription completed successfully.',
|
||||
})
|
||||
}
|
||||
|
||||
// Update status to completed
|
||||
await executeActivity(TaskQueueDb, updateTaskStatusActivity, {
|
||||
taskId: task.id,
|
||||
status: 'completed',
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(`AiTranscriptionMedia failed for task ${task.id}:`, err)
|
||||
|
||||
// Update placeholder comment with error message
|
||||
if (placeholderCommentId) {
|
||||
try {
|
||||
await executeActivity(TaskQueueDb, updateCommentActivity, {
|
||||
commentId: placeholderCommentId,
|
||||
message: `Transcription failed: ${err instanceof Error ? err.message : String(err)}`,
|
||||
})
|
||||
} catch (commentErr) {
|
||||
console.error('Failed to update error comment:', commentErr)
|
||||
}
|
||||
}
|
||||
|
||||
// Update status to failed
|
||||
await executeActivity(TaskQueueDb, updateTaskStatusActivity, {
|
||||
taskId: task.id,
|
||||
status: 'failed',
|
||||
output: { error: err instanceof Error ? err.message : String(err) },
|
||||
})
|
||||
throw err
|
||||
} finally {
|
||||
if (tmpDir && transcodeWorkerQueue) {
|
||||
try {
|
||||
await executeActivity(transcodeWorkerQueue, cleanupTmpDirActivity, { tmpDir })
|
||||
} catch (cleanupErr) {
|
||||
console.error('Failed to cleanup tmp dir:', cleanupErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For Temporal, we often export as a named workflow
|
||||
export const aiTranscriptionWorkflow = aiTranscriptionMedia
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from './ai-transcription'
|
||||
export * from './agent-embedding'
|
||||
export * from './agent-autofill'
|
||||
export * from './agent-chat'
|
||||
|
||||
Reference in New Issue
Block a user