소스 검색

Integrate core's updated events API

Ensure that the summarization is using the correct specs from the Core
module.
master
부모
커밋
6d61b83246
5개의 변경된 파일31개의 추가작업 그리고 22개의 파일을 삭제
  1. +3
    -0
      .env.example
  2. +1
    -0
      .gitignore
  3. +1
    -1
      src/config.ts
  4. +19
    -9
      src/modules/summary/SummaryController.ts
  5. +7
    -12
      src/modules/summary/SummaryService.ts

+ 3
- 0
.env.example 파일 보기

@@ -3,3 +3,6 @@ OPENAI_API_KEY=

# OpenAI organization ID.
OPENAI_ORGANIZATION_ID=

# Directory where the prompts are stored.
OPENAI_PROMPTS_DIR=

+ 1
- 0
.gitignore 파일 보기

@@ -106,3 +106,4 @@ dist

.npmrc
.idea/
/types/

+ 1
- 1
src/config.ts 파일 보기

@@ -3,7 +3,7 @@ export namespace meta {
export const host = process.env.HOST ?? '0.0.0.0';
}

export namespace openai {
export namespace openAi {
export const apiKey = process.env.OPENAI_API_KEY as string;
export const organizationId = process.env.OPENAI_ORGANIZATION_ID;
}

+ 19
- 9
src/modules/summary/SummaryController.ts 파일 보기

@@ -1,7 +1,7 @@
import { CreateSummarizerParams } from '@modal-sh/webvideo-transcript-summary-core';
import { SummaryService, SummaryServiceImpl } from './SummaryService';
import * as config from '../../config';
import { RouteHandlerMethod } from 'fastify';
import {CreateSummarizerParams} from '@modal-sh/webvideo-transcript-summary-core';
import * as config from '../../config';
import { SummaryService, SummaryServiceImpl } from './SummaryService';

export interface SummaryController {
summarizeVideoTranscript: RouteHandlerMethod;
@@ -9,10 +9,7 @@ export interface SummaryController {

export class SummaryControllerImpl implements SummaryController {
constructor(
private readonly summaryService: SummaryService = new SummaryServiceImpl(
config.openai.apiKey,
config.openai.organizationId,
),
private readonly summaryService: SummaryService = new SummaryServiceImpl(),
) {
// noop
}
@@ -20,9 +17,22 @@ export class SummaryControllerImpl implements SummaryController {
readonly summarizeVideoTranscript: RouteHandlerMethod = async (request, reply) => {
const params = request.body as CreateSummarizerParams;
try {
const summaryResult = await this.summaryService.summarizeVideoTranscript(params);
const summaryResult = await this.summaryService.summarizeVideoTranscript({
url: params.url,
type: params.type,
openAiParams: {
apiKey: config.openAi.apiKey,
organizationId: config.openAi.organizationId,
temperature: params.openAiParams?.temperature ?? 0.6,
model: params.openAiParams?.model ?? 'gpt-3.5-turbo',
},
language: params.language ?? 'en',
country: params.country ?? 'US',
});
reply.send(summaryResult);
} catch {
} catch (errRaw) {
const err = errRaw as Error;
request.server.log.error(err);
reply
.code(500)
.send();


+ 7
- 12
src/modules/summary/SummaryService.ts 파일 보기

@@ -15,30 +15,23 @@ export interface SummaryService {
}

export class SummaryServiceImpl implements SummaryService {
constructor(
private readonly openAiApiKey: string,
private readonly openAiOrganizationId?: string,
) {
constructor(private readonly logger = console) {
// noop
}

summarizeVideoTranscript(params: CreateSummarizerParams) {
return new Promise<Partial<SummaryResult>>((resolve, reject) => {
let successEvent = {} as Partial<SummaryResult>;
const successEvent = {} as Partial<SummaryResult>;
let error: Error;
const summarizer = createSummarizer({
type: VideoType.YOUTUBE,
url: params.url,
openaiApiKey: this.openAiApiKey,
openaiOrganizationId: this.openAiOrganizationId,
});
const summarizer = createSummarizer(params);

summarizer.on('process', (data) => {
this.logger.log('process', data);
if (data.phase === 'success') {
switch (data.processType) {
case 'fetch-transcript':
successEvent.rawTranscript = (
JSON.parse(data.content) as { text: string }[]
JSON.parse(data.content as string) as { text: string }[]
)
.map((item) => item.text).join(' ');
break;
@@ -55,10 +48,12 @@ export class SummaryServiceImpl implements SummaryService {
});

summarizer.on('error', (err) => {
this.logger.log('error', err);
error = err;
});

summarizer.on('end', () => {
this.logger.log('end');
if (error) {
reject(error);
return;


불러오는 중...
취소
저장