Get transcript summaries of Web videos.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

45 line
1.5 KiB

  1. import { OpenAi } from '@modal-sh/mio-ai';
  2. import { SummarizerEventEmitter, SummarizerEventEmitterImpl } from './summarizer';
  3. import * as YouTube from './video-types/youtube';
  4. const SUPPORTED_VIDEO_TYPES = [
  5. YouTube,
  6. ] as const;
  7. export type CreateTranscriptFetcherParams = (
  8. YouTube.CreateTranscriptFetcherParams
  9. );
  10. export type SummarizerProcessParams = (
  11. YouTube.SummarizerProcessParams
  12. );
  13. export type VideoType = typeof YouTube.VIDEO_TYPE;
  14. export * from './summarizer';
  15. export * from './transcript';
  16. export * as YouTube from './video-types/youtube';
  17. export const createTranscriptFetcher = (params: CreateTranscriptFetcherParams) => {
  18. const { type: videoType } = params;
  19. const theVideoTypeModule = SUPPORTED_VIDEO_TYPES
  20. .find((videoTypeModule) => videoTypeModule.VIDEO_TYPE === videoType);
  21. if (!theVideoTypeModule) {
  22. const validVideoTypes = SUPPORTED_VIDEO_TYPES.map((videoTypeModule) => videoTypeModule.VIDEO_TYPE).join(', ');
  23. throw new TypeError(`Invalid video type: "${videoType}". Valid values are: ${validVideoTypes}`);
  24. }
  25. // shadow the original method for protection
  26. return (...transcriptFetcherParams: Parameters<typeof theVideoTypeModule.getRawTranscript>) => (
  27. theVideoTypeModule.getRawTranscript(...transcriptFetcherParams)
  28. );
  29. };
  30. export const createSummarizer = (params: OpenAi.Configuration): SummarizerEventEmitter => (
  31. new SummarizerEventEmitterImpl(params)
  32. );
  33. export const OPENAI_API_VERSION = OpenAi.ApiVersion.V1 as const;