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.

33 lines
937 B

  1. import {
  2. createSummarizer,
  3. SummarizerEventEmitter,
  4. OPENAI_API_VERSION,
  5. } from '@modal-sh/webvideo-transcript-summary-core';
  6. import { Readable } from '../../packages/event-emitter-to-readable-stream';
  7. import * as config from '../../config';
  8. export interface SummaryService {
  9. createSummaryStream(transcriptText: string): NodeJS.ReadableStream;
  10. }
  11. export class SummaryServiceImpl implements SummaryService {
  12. private readonly summarizer: SummarizerEventEmitter;
  13. constructor() {
  14. // noop
  15. this.summarizer = createSummarizer({
  16. apiKey: config.openAi.apiKey,
  17. organizationId: config.openAi.organizationId,
  18. apiVersion: OPENAI_API_VERSION,
  19. });
  20. }
  21. createSummaryStream(transcriptText: string) {
  22. const stream = Readable.fromEventEmitter(
  23. this.summarizer,
  24. ) as unknown as NodeJS.ReadableStream & { tokenCount: number };
  25. this.summarizer.summarize(transcriptText);
  26. return stream;
  27. }
  28. }