Skip to content

Commit

Permalink
chore(transcription): use PeerTube UUID helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
lutangar committed May 7, 2024
1 parent 53e126d commit fcaaeca
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
9 changes: 8 additions & 1 deletion packages/node-utils/src/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import short from 'short-uuid'
import short, { SUUID } from 'short-uuid'

const translator = short()

function buildUUID () {
return short.uuid()
}

function buildSUUID (): SUUID {
return short.generate()
}

function uuidToShort (uuid: string) {
if (!uuid) return uuid

Expand All @@ -26,7 +30,10 @@ function isShortUUID (value: string) {

export {
buildUUID,
buildSUUID,
uuidToShort,
shortToUUID,
isShortUUID
}

export type { SUUID }
5 changes: 2 additions & 3 deletions packages/tests/src/transcription/benchmark.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions packages/transcription/src/abstract-transcriber.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -65,6 +64,6 @@ export abstract class AbstractTranscriber {
model,
language,
format = 'vtt',
runId = short.generate()
runId = buildSUUID()
}: TranscribeArgs): Promise<TranscriptFile>
}
4 changes: 2 additions & 2 deletions packages/transcription/src/transcription-run.ts
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -11,7 +11,7 @@ export class Ctranslate2Transcriber extends OpenaiTranscriber {
model = new WhisperBuiltinModel('tiny'),
language,
format = 'vtt',
runId = short.generate()
runId = buildSUUID()
}: WhisperTranscribeArgs): Promise<TranscriptFile> {
this.assertLanguageDetectionAvailable(language)

Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -16,7 +16,7 @@ export class OpenaiTranscriber extends AbstractTranscriber {
model = new WhisperBuiltinModel('tiny'),
language,
format = 'vtt',
runId = short.generate()
runId = buildSUUID()
}: WhisperTranscribeArgs): Promise<TranscriptFile> {
this.assertLanguageDetectionAvailable(language)

Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -14,7 +14,7 @@ export class WhisperTimestampedTranscriber extends OpenaiTranscriber {
model = new WhisperBuiltinModel('tiny'),
language,
format = 'vtt',
runId = short.generate()
runId = buildSUUID()
}: WhisperTranscribeArgs): Promise<TranscriptFile> {
this.assertLanguageDetectionAvailable(language)

Expand Down

0 comments on commit fcaaeca

Please sign in to comment.