|
@@ -1,7 +1,7 @@ |
|
|
import { |
|
|
import { |
|
|
createSummarizer, |
|
|
createSummarizer, |
|
|
CreateSummarizerParams, |
|
|
|
|
|
VideoType, |
|
|
|
|
|
|
|
|
CreateSummarizerParams, SummarizerEventEmitter, |
|
|
|
|
|
SummarizerProcessParams, |
|
|
} from '@modal-sh/webvideo-transcript-summary-core'; |
|
|
} from '@modal-sh/webvideo-transcript-summary-core'; |
|
|
|
|
|
|
|
|
export interface SummaryResult { |
|
|
export interface SummaryResult { |
|
@@ -11,21 +11,32 @@ export interface SummaryResult { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export interface SummaryService { |
|
|
export interface SummaryService { |
|
|
summarizeVideoTranscript(params: CreateSummarizerParams): Promise<Partial<SummaryResult>> |
|
|
|
|
|
|
|
|
initializeSummarizer(params: CreateSummarizerParams): void; |
|
|
|
|
|
summarizeVideoTranscript(processParams: SummarizerProcessParams): Promise<Partial<SummaryResult>>; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export class SummaryServiceImpl implements SummaryService { |
|
|
export class SummaryServiceImpl implements SummaryService { |
|
|
|
|
|
private summarizer?: SummarizerEventEmitter; |
|
|
|
|
|
|
|
|
constructor(private readonly logger = console) { |
|
|
constructor(private readonly logger = console) { |
|
|
// noop |
|
|
// noop |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
summarizeVideoTranscript(params: CreateSummarizerParams) { |
|
|
|
|
|
|
|
|
initializeSummarizer(params: CreateSummarizerParams): void { |
|
|
|
|
|
this.summarizer = createSummarizer(params); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
summarizeVideoTranscript(processParams: SummarizerProcessParams) { |
|
|
return new Promise<Partial<SummaryResult>>((resolve, reject) => { |
|
|
return new Promise<Partial<SummaryResult>>((resolve, reject) => { |
|
|
|
|
|
if (!this.summarizer) { |
|
|
|
|
|
reject(new Error('Summarizer is not initialized')); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const successEvent = {} as Partial<SummaryResult>; |
|
|
const successEvent = {} as Partial<SummaryResult>; |
|
|
let error: Error; |
|
|
let error: Error; |
|
|
const summarizer = createSummarizer(params); |
|
|
|
|
|
|
|
|
|
|
|
summarizer.on('process', (data) => { |
|
|
|
|
|
|
|
|
this.summarizer.on('process', (data) => { |
|
|
this.logger.log('process', data); |
|
|
this.logger.log('process', data); |
|
|
if (data.phase === 'success') { |
|
|
if (data.phase === 'success') { |
|
|
switch (data.processType) { |
|
|
switch (data.processType) { |
|
@@ -47,12 +58,12 @@ export class SummaryServiceImpl implements SummaryService { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
summarizer.on('error', (err) => { |
|
|
|
|
|
|
|
|
this.summarizer.on('error', (err) => { |
|
|
this.logger.log('error', err); |
|
|
this.logger.log('error', err); |
|
|
error = err; |
|
|
error = err; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
summarizer.on('end', () => { |
|
|
|
|
|
|
|
|
this.summarizer.on('end', () => { |
|
|
this.logger.log('end'); |
|
|
this.logger.log('end'); |
|
|
if (error) { |
|
|
if (error) { |
|
|
reject(error); |
|
|
reject(error); |
|
@@ -61,7 +72,7 @@ export class SummaryServiceImpl implements SummaryService { |
|
|
resolve(successEvent); |
|
|
resolve(successEvent); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
summarizer.process(); |
|
|
|
|
|
|
|
|
this.summarizer.process(processParams); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |