|
- import {
- createSummarizer,
- SummarizerEventEmitter,
- OPENAI_API_VERSION,
- } from '@modal-sh/webvideo-transcript-summary-core';
- import { Readable } from '../../packages/event-emitter-to-readable-stream';
- import * as config from '../../config';
-
- export interface SummaryService {
- createSummaryStream(transcriptText: string): NodeJS.ReadableStream;
- }
-
- export class SummaryServiceImpl implements SummaryService {
- private readonly summarizer: SummarizerEventEmitter;
-
- constructor() {
- // noop
- this.summarizer = createSummarizer({
- apiKey: config.openAi.apiKey,
- organizationId: config.openAi.organizationId,
- apiVersion: OPENAI_API_VERSION,
- });
- }
-
- createSummaryStream(transcriptText: string) {
- const stream = Readable.fromEventEmitter(
- this.summarizer,
- ) as unknown as NodeJS.ReadableStream & { tokenCount: number };
- this.summarizer.summarize(transcriptText);
- return stream;
- }
- }
|