|
- import { OpenAi } from '@modal-sh/mio-ai';
- import { SummarizerEventEmitter, SummarizerEventEmitterImpl } from './summarizer';
- import * as YouTube from './video-types/youtube';
-
- const SUPPORTED_VIDEO_TYPES = [
- YouTube,
- ] as const;
-
- export type CreateTranscriptFetcherParams = (
- YouTube.CreateTranscriptFetcherParams
- );
-
- export type SummarizerProcessParams = (
- YouTube.SummarizerProcessParams
- );
-
- export type VideoType = typeof YouTube.VIDEO_TYPE;
-
- export * from './summarizer';
- export * from './transcript';
- export * as YouTube from './video-types/youtube';
-
- export const createTranscriptFetcher = (params: CreateTranscriptFetcherParams) => {
- const { type: videoType } = params;
-
- const theVideoTypeModule = SUPPORTED_VIDEO_TYPES
- .find((videoTypeModule) => videoTypeModule.VIDEO_TYPE === videoType);
-
- if (!theVideoTypeModule) {
- const validVideoTypes = SUPPORTED_VIDEO_TYPES.map((videoTypeModule) => videoTypeModule.VIDEO_TYPE).join(', ');
- throw new TypeError(`Invalid video type: "${videoType}". Valid values are: ${validVideoTypes}`);
- }
-
- // shadow the original method for protection
- return (...transcriptFetcherParams: Parameters<typeof theVideoTypeModule.getRawTranscript>) => (
- theVideoTypeModule.getRawTranscript(...transcriptFetcherParams)
- );
- };
-
- export const createSummarizer = (params: OpenAi.Configuration): SummarizerEventEmitter => (
- new SummarizerEventEmitterImpl(params)
- );
-
- export const OPENAI_API_VERSION = OpenAi.ApiVersion.V1 as const;
|