From fcaaeca374cfcbebd978ff037421508c4ceb37cb Mon Sep 17 00:00:00 2001 From: lutangar Date: Tue, 7 May 2024 15:24:32 +0200 Subject: [PATCH] chore(transcription): use PeerTube UUID helpers --- packages/node-utils/src/uuid.ts | 9 ++++++++- packages/tests/src/transcription/benchmark.spec.ts | 5 ++--- packages/transcription/src/abstract-transcriber.ts | 7 +++---- packages/transcription/src/transcription-run.ts | 4 ++-- .../src/whisper/transcriber/ctranslate2-transcriber.ts | 4 ++-- .../src/whisper/transcriber/openai-transcriber.ts | 4 ++-- .../src/whisper/transcriber/timestamped-transcriber.ts | 4 ++-- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/node-utils/src/uuid.ts b/packages/node-utils/src/uuid.ts index f158ec48780..68110eb0eb2 100644 --- a/packages/node-utils/src/uuid.ts +++ b/packages/node-utils/src/uuid.ts @@ -1,4 +1,4 @@ -import short from 'short-uuid' +import short, { SUUID } from 'short-uuid' const translator = short() @@ -6,6 +6,10 @@ function buildUUID () { return short.uuid() } +function buildSUUID (): SUUID { + return short.generate() +} + function uuidToShort (uuid: string) { if (!uuid) return uuid @@ -26,7 +30,10 @@ function isShortUUID (value: string) { export { buildUUID, + buildSUUID, uuidToShort, shortToUUID, isShortUUID } + +export type { SUUID } diff --git a/packages/tests/src/transcription/benchmark.spec.ts b/packages/tests/src/transcription/benchmark.spec.ts index d47ea832097..8f3978c776b 100644 --- a/packages/tests/src/transcription/benchmark.spec.ts +++ b/packages/tests/src/transcription/benchmark.spec.ts @@ -1,9 +1,8 @@ import { createLogger } from 'winston' -import short, { SUUID } from 'short-uuid' import { performance, PerformanceObserver } from 'node:perf_hooks' // import { CpuInfo, CpuUsage } from 'node:os' import { rm, mkdir } from 'node:fs/promises' -import { buildAbsoluteFixturePath } from '@peertube/peertube-node-utils' +import { buildAbsoluteFixturePath, buildSUUID, SUUID } from '@peertube/peertube-node-utils' import { transcriberFactory, TranscriptFile, @@ -103,7 +102,7 @@ describe('Transcribers benchmark', function () { it(`Run ${transcriberName} transcriber benchmark with ${modelName} model`, async function () { this.timeout(15 * 1000 * 60) // 15 minutes const model = new TranscriptionModel(modelName) - const uuid = short.generate() + const uuid = buildSUUID() const transcriptFile = await transcriber.transcribe({ mediaFilePath, model, diff --git a/packages/transcription/src/abstract-transcriber.ts b/packages/transcription/src/abstract-transcriber.ts index a0de2703b9e..b9a0f66e556 100644 --- a/packages/transcription/src/abstract-transcriber.ts +++ b/packages/transcription/src/abstract-transcriber.ts @@ -1,8 +1,7 @@ import { createLogger, Logger } from 'winston' -import short, { SUUID } from 'short-uuid' import { join } from 'node:path' import { PerformanceObserver } from 'node:perf_hooks' -import { root } from '@peertube/peertube-node-utils' +import { buildSUUID, SUUID, root } from '@peertube/peertube-node-utils' import { TranscriptionEngine } from './transcription-engine.js' import { TranscriptionModel } from './transcription-model.js' import { TranscriptionRun } from './transcription-run.js' @@ -37,7 +36,7 @@ export abstract class AbstractTranscriber { this.performanceObserver = performanceObserver } - createRun (uuid: SUUID = short.generate()) { + createRun (uuid: SUUID = buildSUUID()) { this.run = new TranscriptionRun(this.logger, uuid) } @@ -65,6 +64,6 @@ export abstract class AbstractTranscriber { model, language, format = 'vtt', - runId = short.generate() + runId = buildSUUID() }: TranscribeArgs): Promise } diff --git a/packages/transcription/src/transcription-run.ts b/packages/transcription/src/transcription-run.ts index 6739195cda1..608afbb6ad8 100644 --- a/packages/transcription/src/transcription-run.ts +++ b/packages/transcription/src/transcription-run.ts @@ -1,11 +1,11 @@ -import short, { SUUID } from 'short-uuid' +import { buildSUUID, SUUID } from '@peertube/peertube-node-utils' import { createLogger, Logger } from 'winston' export class TranscriptionRun { uuid: SUUID logger: Logger - constructor (logger = createLogger(), uuid: SUUID = short.generate()) { + constructor (logger = createLogger(), uuid: SUUID = buildSUUID()) { this.uuid = uuid this.logger = logger } diff --git a/packages/transcription/src/whisper/transcriber/ctranslate2-transcriber.ts b/packages/transcription/src/whisper/transcriber/ctranslate2-transcriber.ts index 1eb85602a78..6cb14af97c0 100644 --- a/packages/transcription/src/whisper/transcriber/ctranslate2-transcriber.ts +++ b/packages/transcription/src/whisper/transcriber/ctranslate2-transcriber.ts @@ -1,5 +1,5 @@ import { $ } from 'execa' -import short from 'short-uuid' +import { buildSUUID } from '@peertube/peertube-node-utils' import { lstat } from 'node:fs/promises' import { OpenaiTranscriber, WhisperTranscribeArgs } from './openai-transcriber.js' import { TranscriptFile } from '../../transcript/index.js' @@ -11,7 +11,7 @@ export class Ctranslate2Transcriber extends OpenaiTranscriber { model = new WhisperBuiltinModel('tiny'), language, format = 'vtt', - runId = short.generate() + runId = buildSUUID() }: WhisperTranscribeArgs): Promise { this.assertLanguageDetectionAvailable(language) diff --git a/packages/transcription/src/whisper/transcriber/openai-transcriber.ts b/packages/transcription/src/whisper/transcriber/openai-transcriber.ts index 145f87ab400..9de9d702a26 100644 --- a/packages/transcription/src/whisper/transcriber/openai-transcriber.ts +++ b/packages/transcription/src/whisper/transcriber/openai-transcriber.ts @@ -1,6 +1,6 @@ import { join } from 'path' import { $ } from 'execa' -import short from 'short-uuid' +import { buildSUUID } from '@peertube/peertube-node-utils' import { TranscriptFile, TranscriptFormat } from '../../transcript/index.js' import { AbstractTranscriber, TranscribeArgs } from '../../abstract-transcriber.js' import { WhisperBuiltinModel } from '../whisper-builtin-model.js' @@ -16,7 +16,7 @@ export class OpenaiTranscriber extends AbstractTranscriber { model = new WhisperBuiltinModel('tiny'), language, format = 'vtt', - runId = short.generate() + runId = buildSUUID() }: WhisperTranscribeArgs): Promise { this.assertLanguageDetectionAvailable(language) diff --git a/packages/transcription/src/whisper/transcriber/timestamped-transcriber.ts b/packages/transcription/src/whisper/transcriber/timestamped-transcriber.ts index bb4dc023336..d6d376d7b32 100644 --- a/packages/transcription/src/whisper/transcriber/timestamped-transcriber.ts +++ b/packages/transcription/src/whisper/transcriber/timestamped-transcriber.ts @@ -1,5 +1,5 @@ import { $ } from 'execa' -import short from 'short-uuid' +import { buildSUUID } from '@peertube/peertube-node-utils' import assert from 'node:assert' import { join, parse } from 'node:path' import { existsSync } from 'node:fs' @@ -14,7 +14,7 @@ export class WhisperTimestampedTranscriber extends OpenaiTranscriber { model = new WhisperBuiltinModel('tiny'), language, format = 'vtt', - runId = short.generate() + runId = buildSUUID() }: WhisperTranscribeArgs): Promise { this.assertLanguageDetectionAvailable(language)